From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from scc-mailout-kit-02.scc.kit.edu (scc-mailout-kit-02.scc.kit.edu [129.13.231.82]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTP id 4ae680ff for ; Sun, 12 Mar 2017 14:39:45 -0500 (EST) Received: from asta-nat.asta.uni-karlsruhe.de ([172.22.63.82] helo=hekate.usta.de) by scc-mailout-kit-02.scc.kit.edu with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (envelope-from ) id 1cn9LD-0000UL-NN; Sun, 12 Mar 2017 20:39:45 +0100 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.77) (envelope-from ) id 1cn9LB-0003I2-6d; Sun, 12 Mar 2017 20:39:41 +0100 Received: from athene.usta.de ([172.24.96.10]) by donnerwolke.usta.de with esmtp (Exim 4.84_2) (envelope-from ) id 1cn9LB-0000gL-0j; Sun, 12 Mar 2017 20:39:41 +0100 Received: from localhost (athene.usta.de [local]) by athene.usta.de (OpenSMTPD) with ESMTPA id f157c950; Sun, 12 Mar 2017 20:39:41 +0100 (CET) Date: Sun, 12 Mar 2017 20:39:40 +0100 From: Ingo Schwarze To: Thomas Guettler , discuss@mdocml.bsd.lv Subject: Re: Links into HTML page would be great Message-ID: <20170312193940.GA91520@athene.usta.de> References: <8ffc686a-f898-4952-ae6f-3b8881469f17@thomas-guettler.de> <20170312180832.GE69791@athene.usta.de> X-Mailinglist: mdocml-discuss Reply-To: discuss@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170312180832.GE69791@athene.usta.de> User-Agent: Mutt/1.6.2 (2016-07-01) 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