discuss@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: Thomas Guettler <guettliml@thomas-guettler.de>, discuss@mdocml.bsd.lv
Subject: Re: Links into HTML page would be great
Date: Sun, 12 Mar 2017 20:39:40 +0100	[thread overview]
Message-ID: <20170312193940.GA91520@athene.usta.de> (raw)
In-Reply-To: <20170312180832.GE69791@athene.usta.de>

Hi,

Ingo Schwarze wrote on Sun, Mar 12, 2017 at 07:08:32PM +0100:
> Thomas Guettler wrote on Tue, Feb 28, 2017 at 03:33:00PM +0100:

>> it would be great if you could create a link which points to this:
>> http://man.openbsd.org/OpenBSD-current/man5/ssh_config.5#ServerAliveInterval

> You have a point.
 
>> I have no clue how nroff works. I guess it is not easy to implement.

> You may be wrong, it is likely not difficult.

It turns out to be even easier than i anticipated.

Here is a proof-of-concept patch that i just installed on man.openbsd.org.
For now, it only does .Cm, merely because that's what Thomas used as
his example, and also because it is one of the macros where this is
useful.

If people speak up here who like that, or if i come to the
conclusion that i like it myself (which seems likely),
i will probably add support for some more macros, probably
.Ev .Fl .Ic .Ms .Dv .Li .No .Er .Sy .Em ,
do some polishing (for example making sure the tag contains no
invalid characters), then commit it in a few days.

The two macros .Fn and .Fd are slightly more tricky and may need
a bit of deliberation, but are probably feasible, too.

At first, i was a bit worried because what exactly such a tagging
facility will tag may not be completely stable over time.  But then
it occurred to me that really isn't a big deal.  I mean, even if
some external deep links sometimes go dead due to algorithmic changes,
we are not worse off than right now.  Even if those links are never
updated, they still point to the right page, only to the beginning
of it.

Yours,
  Ingo


Index: mdoc_html.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/mdoc_html.c,v
retrieving revision 1.148
diff -u -p -r1.148 mdoc_html.c
--- mdoc_html.c	3 Mar 2017 13:55:06 -0000	1.148
+++ mdoc_html.c	12 Mar 2017 19:23:54 -0000
@@ -46,6 +46,7 @@ struct	htmlmdoc {
 	void		(*post)(MDOC_ARGS);
 };
 
+static	const char	 *cond_id(const struct roff_node *);
 static	char		 *make_id(const struct roff_node *);
 static	void		  print_mdoc_head(MDOC_ARGS);
 static	void		  print_mdoc_node(MDOC_ARGS);
@@ -496,6 +497,22 @@ make_id(const struct roff_node *n)
 	return buf;
 }
 
+static const char *
+cond_id(const struct roff_node *n)
+{
+	if (n->child != NULL &&
+	    n->child->type == ROFFT_TEXT &&
+	    (n->prev == NULL ||
+	     (n->prev->type == ROFFT_TEXT &&
+	      strcmp(n->prev->string, "|") == 0)) &&
+	    (n->parent->tok == MDOC_It ||
+	     (n->parent->tok == MDOC_Xo &&
+	      n->parent->parent->prev == NULL &&
+	      n->parent->parent->parent->tok == MDOC_It)))
+		return n->child->string;
+	return NULL;
+}
+
 static int
 mdoc_sh_pre(MDOC_ARGS)
 {
@@ -549,7 +566,7 @@ mdoc_fl_pre(MDOC_ARGS)
 static int
 mdoc_cm_pre(MDOC_ARGS)
 {
-	print_otag(h, TAG_B, "c", "Cm");
+	print_otag(h, TAG_B, "ci", "Cm", cond_id(n));
 	return 1;
 }
 
--
 To unsubscribe send an email to discuss+unsubscribe@mdocml.bsd.lv

  reply	other threads:[~2017-03-12 19:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-28 14:33 Thomas Güttler
2017-03-12 18:08 ` Ingo Schwarze
2017-03-12 19:39   ` Ingo Schwarze [this message]
2017-03-13  9:42     ` Thomas Güttler
2017-03-13  9:56       ` Jan Stary
2017-03-14  1:49         ` Ingo Schwarze
2017-03-14  9:39         ` Jan Stary
2017-03-14 17:17           ` Ingo Schwarze
2017-03-13  9:59       ` Thomas Güttler
2017-03-13 15:32         ` Ingo Schwarze
2017-03-13 21:35       ` Ingo Schwarze

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170312193940.GA91520@athene.usta.de \
    --to=schwarze@usta.de \
    --cc=discuss@mdocml.bsd.lv \
    --cc=guettliml@thomas-guettler.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).