summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2020-04-07 22:45:39 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2020-04-07 22:45:39 +0000
commit059b974c9931ac26e6ff9ef58dd61b4b6e0c8068 (patch)
treed0e32b633f6b2163f51942e1eca25586449154bd
parent48286e5e06d9ffc523470a78ff72a598838c8693 (diff)
Separate the place to put the <a href> permalink (now marked
with NODE_HREF) from the target element of the link (still marked with NODE_ID). In many cases, use this to move the target to the beginning of the paragraph, such that readers don't get dropped into the middle of a sentence.
-rw-r--r--regress/usr.bin/mandoc/mdoc/Cm/tag.out_html10
-rw-r--r--regress/usr.bin/mandoc/mdoc/Dv/tag.out_html4
-rw-r--r--regress/usr.bin/mandoc/mdoc/Em/tag.out_html4
-rw-r--r--regress/usr.bin/mandoc/mdoc/Er/tag.out_html2
-rw-r--r--regress/usr.bin/mandoc/mdoc/Ev/tag.out_html4
-rw-r--r--regress/usr.bin/mandoc/mdoc/Fl/tag.out_html4
-rw-r--r--regress/usr.bin/mandoc/mdoc/Fo/tag.out_html13
-rw-r--r--regress/usr.bin/mandoc/mdoc/Ic/tag.out_html4
-rw-r--r--regress/usr.bin/mandoc/mdoc/Li/tag.out_html4
-rw-r--r--regress/usr.bin/mandoc/mdoc/Ms/tag.out_html4
-rw-r--r--regress/usr.bin/mandoc/mdoc/No/tag.out_html4
-rw-r--r--regress/usr.bin/mandoc/mdoc/Sy/tag.out_html4
-rw-r--r--regress/usr.bin/mandoc/mdoc/Tg/column.in7
-rw-r--r--regress/usr.bin/mandoc/mdoc/Tg/column.out_ascii2
-rw-r--r--regress/usr.bin/mandoc/mdoc/Tg/column.out_markdown2
-rw-r--r--regress/usr.bin/mandoc/mdoc/Tg/warn.out_html2
-rw-r--r--usr.bin/mandoc/html.c18
-rw-r--r--usr.bin/mandoc/read.c3
-rw-r--r--usr.bin/mandoc/tag.c96
-rw-r--r--usr.bin/mandoc/tag.h3
-rw-r--r--usr.bin/mandoc/tree.c7
21 files changed, 152 insertions, 49 deletions
diff --git a/regress/usr.bin/mandoc/mdoc/Cm/tag.out_html b/regress/usr.bin/mandoc/mdoc/Cm/tag.out_html
index 134f21c4533..5141f52a81d 100644
--- a/regress/usr.bin/mandoc/mdoc/Cm/tag.out_html
+++ b/regress/usr.bin/mandoc/mdoc/Cm/tag.out_html
@@ -1,15 +1,15 @@
<dl class="Bl-tag">
- <dt><a class="permalink" href="#one"><code class="Cm" id="one">one</code></a>
+ <dt id="one"><a class="permalink" href="#one"><code class="Cm">one</code></a>
|
<a class="permalink" href="#two"><code class="Cm" id="two">two</code></a></dt>
<dd>text</dd>
- <dt><a class="permalink" href="#three"><code class="Cm" id="three">three</code></a></dt>
+ <dt id="three"><a class="permalink" href="#three"><code class="Cm">three</code></a></dt>
<dd>text</dd>
- <dt><a class="permalink" href="#hyphen"><code class="Cm" id="hyphen">-hyphen</code></a></dt>
+ <dt id="hyphen"><a class="permalink" href="#hyphen"><code class="Cm">-hyphen</code></a></dt>
<dd>text</dd>
- <dt><a class="permalink" href="#minus"><code class="Cm" id="minus">-minus-sign</code></a></dt>
+ <dt id="minus"><a class="permalink" href="#minus"><code class="Cm">-minus-sign</code></a></dt>
<dd>text</dd>
- <dt><a class="permalink" href="#backslash"><code class="Cm" id="backslash">\backslash</code></a></dt>
+ <dt id="backslash"><a class="permalink" href="#backslash"><code class="Cm">\backslash</code></a></dt>
<dd>text</dd>
</dl>
<a class="permalink" href="#four"><code class="Cm" id="four">four</code></a>
diff --git a/regress/usr.bin/mandoc/mdoc/Dv/tag.out_html b/regress/usr.bin/mandoc/mdoc/Dv/tag.out_html
index cee78340802..4f04e0b7ef0 100644
--- a/regress/usr.bin/mandoc/mdoc/Dv/tag.out_html
+++ b/regress/usr.bin/mandoc/mdoc/Dv/tag.out_html
@@ -1,9 +1,9 @@
<dl class="Bl-tag">
- <dt><a class="permalink" href="#one"><code class="Dv" id="one">one</code></a>
+ <dt id="one"><a class="permalink" href="#one"><code class="Dv">one</code></a>
|
<a class="permalink" href="#two"><code class="Dv" id="two">two</code></a></dt>
<dd>text</dd>
- <dt><a class="permalink" href="#three"><code class="Dv" id="three">three</code></a></dt>
+ <dt id="three"><a class="permalink" href="#three"><code class="Dv">three</code></a></dt>
<dd>text</dd>
</dl>
<a class="permalink" href="#four"><code class="Dv" id="four">four</code></a>
diff --git a/regress/usr.bin/mandoc/mdoc/Em/tag.out_html b/regress/usr.bin/mandoc/mdoc/Em/tag.out_html
index 225343eebd0..f5c47121d37 100644
--- a/regress/usr.bin/mandoc/mdoc/Em/tag.out_html
+++ b/regress/usr.bin/mandoc/mdoc/Em/tag.out_html
@@ -1,8 +1,8 @@
<dl class="Bl-tag">
- <dt><a class="permalink" href="#one"><i class="Em" id="one">one</i></a> |
+ <dt id="one"><a class="permalink" href="#one"><i class="Em">one</i></a> |
<a class="permalink" href="#two"><i class="Em" id="two">two</i></a></dt>
<dd>text</dd>
- <dt><a class="permalink" href="#three-with-hyphens"><i class="Em" id="three-with-hyphens">three-with-hyphens</i></a></dt>
+ <dt id="three-with-hyphens"><a class="permalink" href="#three-with-hyphens"><i class="Em">three-with-hyphens</i></a></dt>
<dd>text</dd>
</dl>
<a class="permalink" href="#four"><i class="Em" id="four">four</i></a>
diff --git a/regress/usr.bin/mandoc/mdoc/Er/tag.out_html b/regress/usr.bin/mandoc/mdoc/Er/tag.out_html
index a2c2978f2dc..80daa28b798 100644
--- a/regress/usr.bin/mandoc/mdoc/Er/tag.out_html
+++ b/regress/usr.bin/mandoc/mdoc/Er/tag.out_html
@@ -7,6 +7,6 @@
<section class="Sh">
<h1 class="Sh" id="ERRORS"><a class="permalink" href="#ERRORS">ERRORS</a></h1>
<dl class="Bl-tag">
- <dt>[<a class="permalink" href="#ENOENT"><code class="Er" id="ENOENT">ENOENT</code></a>]</dt>
+ <dt id="ENOENT">[<a class="permalink" href="#ENOENT"><code class="Er">ENOENT</code></a>]</dt>
<dd>text</dd>
</dl>
diff --git a/regress/usr.bin/mandoc/mdoc/Ev/tag.out_html b/regress/usr.bin/mandoc/mdoc/Ev/tag.out_html
index 1e1c92b9a2f..ccc5beb0840 100644
--- a/regress/usr.bin/mandoc/mdoc/Ev/tag.out_html
+++ b/regress/usr.bin/mandoc/mdoc/Ev/tag.out_html
@@ -1,9 +1,9 @@
<dl class="Bl-tag">
- <dt><a class="permalink" href="#one"><code class="Ev" id="one">one</code></a>
+ <dt id="one"><a class="permalink" href="#one"><code class="Ev">one</code></a>
|
<a class="permalink" href="#two"><code class="Ev" id="two">two</code></a></dt>
<dd>text</dd>
- <dt><a class="permalink" href="#three"><code class="Ev" id="three">three</code></a></dt>
+ <dt id="three"><a class="permalink" href="#three"><code class="Ev">three</code></a></dt>
<dd>text</dd>
</dl>
<a class="permalink" href="#four"><code class="Ev" id="four">four</code></a>
diff --git a/regress/usr.bin/mandoc/mdoc/Fl/tag.out_html b/regress/usr.bin/mandoc/mdoc/Fl/tag.out_html
index f67a30c04d8..c101124fe65 100644
--- a/regress/usr.bin/mandoc/mdoc/Fl/tag.out_html
+++ b/regress/usr.bin/mandoc/mdoc/Fl/tag.out_html
@@ -1,8 +1,8 @@
<dl class="Bl-tag">
- <dt><a class="permalink" href="#a"><code class="Fl" id="a">-a</code></a> |
+ <dt id="a"><a class="permalink" href="#a"><code class="Fl">-a</code></a> |
<a class="permalink" href="#b"><code class="Fl" id="b">-b</code></a></dt>
<dd>text</dd>
- <dt><a class="permalink" href="#c"><code class="Fl" id="c">-c</code></a></dt>
+ <dt id="c"><a class="permalink" href="#c"><code class="Fl">-c</code></a></dt>
<dd>text</dd>
</dl>
<a class="permalink" href="#d"><code class="Fl" id="d">-d</code></a>
diff --git a/regress/usr.bin/mandoc/mdoc/Fo/tag.out_html b/regress/usr.bin/mandoc/mdoc/Fo/tag.out_html
index b350861482e..018ff92e0f2 100644
--- a/regress/usr.bin/mandoc/mdoc/Fo/tag.out_html
+++ b/regress/usr.bin/mandoc/mdoc/Fo/tag.out_html
@@ -1,9 +1,8 @@
-<p class="Pp">automatic:
- <a class="permalink" href="#first"><code class="Fn" id="first">first</code></a>()
- and <code class="Fn">second</code>()</p>
-<p class="Pp"><a class="permalink" href="#second"><code class="Fn" id="second">second</code></a>()
+<p class="Pp" id="first">automatic:
+ <a class="permalink" href="#first"><code class="Fn">first</code></a>() and
+ <code class="Fn">second</code>()</p>
+<p class="Pp" id="second"><a class="permalink" href="#second"><code class="Fn">second</code></a>()
and <code class="Fn">first</code>()</p>
-<p class="Pp">explicit:
- <a class="permalink" href="#e3"><code class="Fn" id="e3">third</code></a>()
- and
+<p class="Pp" id="e3">explicit:
+ <a class="permalink" href="#e3"><code class="Fn">third</code></a>() and
<a class="permalink" href="#e4"><code class="Fn" id="e4">fourth</code></a>(<var class="Fa">void</var>);</p>
diff --git a/regress/usr.bin/mandoc/mdoc/Ic/tag.out_html b/regress/usr.bin/mandoc/mdoc/Ic/tag.out_html
index ad3cc1efc52..7148cc883ad 100644
--- a/regress/usr.bin/mandoc/mdoc/Ic/tag.out_html
+++ b/regress/usr.bin/mandoc/mdoc/Ic/tag.out_html
@@ -1,9 +1,9 @@
<dl class="Bl-tag">
- <dt><a class="permalink" href="#one"><code class="Ic" id="one">one</code></a>
+ <dt id="one"><a class="permalink" href="#one"><code class="Ic">one</code></a>
|
<a class="permalink" href="#two"><code class="Ic" id="two">two</code></a></dt>
<dd>text</dd>
- <dt><a class="permalink" href="#three"><code class="Ic" id="three">three</code></a></dt>
+ <dt id="three"><a class="permalink" href="#three"><code class="Ic">three</code></a></dt>
<dd>text</dd>
</dl>
<a class="permalink" href="#four"><code class="Ic" id="four">four</code></a>
diff --git a/regress/usr.bin/mandoc/mdoc/Li/tag.out_html b/regress/usr.bin/mandoc/mdoc/Li/tag.out_html
index 3730caa6a52..d1b71573482 100644
--- a/regress/usr.bin/mandoc/mdoc/Li/tag.out_html
+++ b/regress/usr.bin/mandoc/mdoc/Li/tag.out_html
@@ -1,9 +1,9 @@
<dl class="Bl-tag">
- <dt><a class="permalink" href="#one"><code class="Li" id="one">one</code></a>
+ <dt id="one"><a class="permalink" href="#one"><code class="Li">one</code></a>
|
<a class="permalink" href="#two"><code class="Li" id="two">two</code></a></dt>
<dd>text</dd>
- <dt><a class="permalink" href="#three"><code class="Li" id="three">three</code></a></dt>
+ <dt id="three"><a class="permalink" href="#three"><code class="Li">three</code></a></dt>
<dd>text</dd>
</dl>
<a class="permalink" href="#four"><code class="Li" id="four">four</code></a>
diff --git a/regress/usr.bin/mandoc/mdoc/Ms/tag.out_html b/regress/usr.bin/mandoc/mdoc/Ms/tag.out_html
index 0f24b2acc7d..9ae0292b5ad 100644
--- a/regress/usr.bin/mandoc/mdoc/Ms/tag.out_html
+++ b/regress/usr.bin/mandoc/mdoc/Ms/tag.out_html
@@ -1,9 +1,9 @@
<dl class="Bl-tag">
- <dt><a class="permalink" href="#one"><span class="Ms" id="one">one</span></a>
+ <dt id="one"><a class="permalink" href="#one"><span class="Ms">one</span></a>
|
<a class="permalink" href="#two"><span class="Ms" id="two">two</span></a></dt>
<dd>text</dd>
- <dt><a class="permalink" href="#three"><span class="Ms" id="three">three</span></a></dt>
+ <dt id="three"><a class="permalink" href="#three"><span class="Ms">three</span></a></dt>
<dd>text</dd>
</dl>
<a class="permalink" href="#four"><span class="Ms" id="four">four</span></a>
diff --git a/regress/usr.bin/mandoc/mdoc/No/tag.out_html b/regress/usr.bin/mandoc/mdoc/No/tag.out_html
index 32696917362..97109cee472 100644
--- a/regress/usr.bin/mandoc/mdoc/No/tag.out_html
+++ b/regress/usr.bin/mandoc/mdoc/No/tag.out_html
@@ -1,9 +1,9 @@
<dl class="Bl-tag">
- <dt><a class="permalink" href="#one"><span class="No" id="one">one</span></a>
+ <dt id="one"><a class="permalink" href="#one"><span class="No">one</span></a>
|
<a class="permalink" href="#two"><span class="No" id="two">two</span></a></dt>
<dd>text</dd>
- <dt><a class="permalink" href="#three"><span class="No" id="three">three</span></a></dt>
+ <dt id="three"><a class="permalink" href="#three"><span class="No">three</span></a></dt>
<dd>text</dd>
</dl>
<a class="permalink" href="#four"><span class="No" id="four">four</span></a>
diff --git a/regress/usr.bin/mandoc/mdoc/Sy/tag.out_html b/regress/usr.bin/mandoc/mdoc/Sy/tag.out_html
index 69276a1883b..cca78319209 100644
--- a/regress/usr.bin/mandoc/mdoc/Sy/tag.out_html
+++ b/regress/usr.bin/mandoc/mdoc/Sy/tag.out_html
@@ -1,8 +1,8 @@
<dl class="Bl-tag">
- <dt><a class="permalink" href="#one"><b class="Sy" id="one">one</b></a> |
+ <dt id="one"><a class="permalink" href="#one"><b class="Sy">one</b></a> |
<a class="permalink" href="#two"><b class="Sy" id="two">two</b></a></dt>
<dd>text</dd>
- <dt><a class="permalink" href="#three"><b class="Sy" id="three">three</b></a></dt>
+ <dt id="three"><a class="permalink" href="#three"><b class="Sy">three</b></a></dt>
<dd>text</dd>
</dl>
<a class="permalink" href="#four"><b class="Sy" id="four">four</b></a>
diff --git a/regress/usr.bin/mandoc/mdoc/Tg/column.in b/regress/usr.bin/mandoc/mdoc/Tg/column.in
index 50b0d1f0ba1..d717283b78d 100644
--- a/regress/usr.bin/mandoc/mdoc/Tg/column.in
+++ b/regress/usr.bin/mandoc/mdoc/Tg/column.in
@@ -1,5 +1,5 @@
-.\" $OpenBSD: column.in,v 1.1 2020/04/06 09:55:50 schwarze Exp $
-.Dd $Mdocdate: April 6 2020 $
+.\" $OpenBSD: column.in,v 1.2 2020/04/07 22:45:38 schwarze Exp $
+.Dd $Mdocdate: April 7 2020 $
.Dt TG-COLUMN 1
.Os
.Sh NAME
@@ -9,8 +9,9 @@
BEGINTEST
.Tg list
.Bl -column one two
+.It one Ta
.Tg row1
-.It one Ta two
+two
.Tg row2
.It 1 2
.El
diff --git a/regress/usr.bin/mandoc/mdoc/Tg/column.out_ascii b/regress/usr.bin/mandoc/mdoc/Tg/column.out_ascii
index 3051005bb1c..60391cff44f 100644
--- a/regress/usr.bin/mandoc/mdoc/Tg/column.out_ascii
+++ b/regress/usr.bin/mandoc/mdoc/Tg/column.out_ascii
@@ -10,4 +10,4 @@ DDEESSCCRRIIPPTTIIOONN
1 2
ENDTEST
-OpenBSD April 6, 2020 OpenBSD
+OpenBSD April 7, 2020 OpenBSD
diff --git a/regress/usr.bin/mandoc/mdoc/Tg/column.out_markdown b/regress/usr.bin/mandoc/mdoc/Tg/column.out_markdown
index a6820fd0644..2042eb99a43 100644
--- a/regress/usr.bin/mandoc/mdoc/Tg/column.out_markdown
+++ b/regress/usr.bin/mandoc/mdoc/Tg/column.out_markdown
@@ -13,4 +13,4 @@ BEGINTEST
ENDTEST
-OpenBSD - April 6, 2020
+OpenBSD - April 7, 2020
diff --git a/regress/usr.bin/mandoc/mdoc/Tg/warn.out_html b/regress/usr.bin/mandoc/mdoc/Tg/warn.out_html
index fdc333b6577..a7f925740d0 100644
--- a/regress/usr.bin/mandoc/mdoc/Tg/warn.out_html
+++ b/regress/usr.bin/mandoc/mdoc/Tg/warn.out_html
@@ -1,4 +1,4 @@
-<p class="Pp"><mark id="start-tag"></mark>initial text
+<p class="Pp" id="start-tag">initial text
<a class="permalink" href="#macro"><code class="Ic" id="macro">macro</code></a>
too many badstart badend whitespace <mark id="sub"></mark></p>
<section class="Ss">
diff --git a/usr.bin/mandoc/html.c b/usr.bin/mandoc/html.c
index e15c680b296..773b7429c43 100644
--- a/usr.bin/mandoc/html.c
+++ b/usr.bin/mandoc/html.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: html.c,v 1.136 2020/04/06 09:55:49 schwarze Exp $ */
+/* $OpenBSD: html.c,v 1.137 2020/04/07 22:45:37 schwarze Exp $ */
/*
* Copyright (c) 2011-2015, 2017-2020 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -777,18 +777,20 @@ print_otag_id(struct html *h, enum htmltag elemtype, const char *cattr,
{
struct roff_node *nch;
struct tag *ret, *t;
- const char *id;
+ char *id, *href;
ret = NULL;
- id = NULL;
+ id = href = NULL;
if (n->flags & NODE_ID)
id = html_make_id(n, 1);
- if (id != NULL && htmltags[elemtype].flags & HTML_INPHRASE)
- ret = print_otag(h, TAG_A, "chR", "permalink", id);
+ if (n->flags & NODE_HREF)
+ href = id == NULL ? html_make_id(n, 0) : id;
+ if (href != NULL && htmltags[elemtype].flags & HTML_INPHRASE)
+ ret = print_otag(h, TAG_A, "chR", "permalink", href);
t = print_otag(h, elemtype, "ci", cattr, id);
if (ret == NULL) {
ret = t;
- if (id != NULL && (nch = n->child) != NULL) {
+ if (href != NULL && (nch = n->child) != NULL) {
/* man(7) is safe, it tags phrasing content only. */
if (n->tok > MDOC_MAX ||
htmltags[elemtype].flags & HTML_TOPHRASE)
@@ -797,9 +799,11 @@ print_otag_id(struct html *h, enum htmltag elemtype, const char *cattr,
while (nch != NULL && nch->type == ROFFT_TEXT)
nch = nch->next;
if (nch == NULL)
- print_otag(h, TAG_A, "chR", "permalink", id);
+ print_otag(h, TAG_A, "chR", "permalink", href);
}
}
+ if (id == NULL)
+ free(href);
return ret;
}
diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c
index 2fcabf8bb46..613a17d8062 100644
--- a/usr.bin/mandoc/read.c
+++ b/usr.bin/mandoc/read.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: read.c,v 1.187 2020/03/13 16:14:14 schwarze Exp $ */
+/* $OpenBSD: read.c,v 1.188 2020/04/07 22:45:37 schwarze Exp $ */
/*
* Copyright (c) 2010-2019 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -706,6 +706,7 @@ mparse_result(struct mparse *curp)
mdoc_validate(curp->man);
else
man_validate(curp->man);
+ tag_postprocess(curp->man->meta.first);
}
return &curp->man->meta;
}
diff --git a/usr.bin/mandoc/tag.c b/usr.bin/mandoc/tag.c
index 7de2616118c..1e37541c07b 100644
--- a/usr.bin/mandoc/tag.c
+++ b/usr.bin/mandoc/tag.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tag.c,v 1.32 2020/04/03 10:29:01 schwarze Exp $ */
+/* $OpenBSD: tag.c,v 1.33 2020/04/07 22:45:37 schwarze Exp $ */
/*
* Copyright (c) 2015,2016,2018,2019,2020 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -29,6 +29,7 @@
#include "mandoc_aux.h"
#include "mandoc_ohash.h"
#include "roff.h"
+#include "mdoc.h"
#include "tag.h"
struct tag_entry {
@@ -39,6 +40,8 @@ struct tag_entry {
char s[];
};
+static void tag_move_id(struct roff_node *);
+
static struct ohash tag_data;
@@ -180,3 +183,94 @@ tag_exists(const char *tag)
{
return ohash_find(&tag_data, ohash_qlookup(&tag_data, tag)) != NULL;
}
+
+/*
+ * For in-line elements, move the link target
+ * to the enclosing paragraph when appropriate.
+ */
+static void
+tag_move_id(struct roff_node *n)
+{
+ struct roff_node *np;
+
+ np = n;
+ for (;;) {
+ if (np->prev != NULL)
+ np = np->prev;
+ else if ((np = np->parent) == NULL)
+ return;
+ switch (np->tok) {
+ case MDOC_It:
+ switch (np->parent->parent->norm->Bl.type) {
+ case LIST_column:
+ /* Target the ROFFT_BLOCK = <tr>. */
+ np = np->parent;
+ break;
+ case LIST_diag:
+ case LIST_hang:
+ case LIST_inset:
+ case LIST_ohang:
+ case LIST_tag:
+ /* Target the ROFFT_HEAD = <dt>. */
+ np = np->parent->head;
+ break;
+ default:
+ /* Target the ROFF_BODY = <li>. */
+ break;
+ }
+ /* FALLTHROUGH */
+ case MDOC_Pp: /* Target the ROFFT_ELEM = <p>. */
+ if (np->string == NULL) {
+ np->string = mandoc_strdup(n->string == NULL ?
+ n->child->string : n->string);
+ np->flags |= NODE_ID;
+ n->flags &= ~NODE_ID;
+ }
+ return;
+ case MDOC_Sh:
+ case MDOC_Ss:
+ case MDOC_Bd:
+ case MDOC_Bl:
+ case MDOC_D1:
+ case MDOC_Dl:
+ case MDOC_Rs:
+ /* Do not move past major blocks. */
+ return;
+ default:
+ /*
+ * Move past in-line content and partial
+ * blocks, for example .It Xo or .It Bq Er.
+ */
+ break;
+ }
+ }
+}
+
+/*
+ * When all tags have been set, decide where to put
+ * the associated permalinks, and maybe move some tags
+ * to the beginning of the respective paragraphs.
+ */
+void
+tag_postprocess(struct roff_node *n)
+{
+ if (n->flags & NODE_ID) {
+ switch (n->tok) {
+ case MDOC_Bd:
+ case MDOC_Bl:
+ case MDOC_Pp:
+ /* XXX No permalink for now. */
+ break;
+ default:
+ if (n->type == ROFFT_ELEM || n->tok == MDOC_Fo)
+ tag_move_id(n);
+ if (n->tok != MDOC_Tg)
+ n->flags |= NODE_HREF;
+ else if ((n->flags & NODE_ID) == 0)
+ n->flags |= NODE_NOPRT;
+ break;
+ }
+ }
+ for (n = n->child; n != NULL; n = n->next)
+ tag_postprocess(n);
+}
diff --git a/usr.bin/mandoc/tag.h b/usr.bin/mandoc/tag.h
index a74f433a8c5..9bbcd6a71f1 100644
--- a/usr.bin/mandoc/tag.h
+++ b/usr.bin/mandoc/tag.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tag.h,v 1.12 2020/04/02 22:10:27 schwarze Exp $ */
+/* $OpenBSD: tag.h,v 1.13 2020/04/07 22:45:37 schwarze Exp $ */
/*
* Copyright (c) 2015, 2018, 2019, 2020 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -31,4 +31,5 @@
void tag_alloc(void);
int tag_exists(const char *);
void tag_put(const char *, int, struct roff_node *);
+void tag_postprocess(struct roff_node *);
void tag_free(void);
diff --git a/usr.bin/mandoc/tree.c b/usr.bin/mandoc/tree.c
index 5d82f866056..8b3013d6461 100644
--- a/usr.bin/mandoc/tree.c
+++ b/usr.bin/mandoc/tree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tree.c,v 1.54 2020/03/13 00:31:05 schwarze Exp $ */
+/* $OpenBSD: tree.c,v 1.55 2020/04/07 22:45:37 schwarze Exp $ */
/*
* Copyright (c) 2013-2015, 2017-2020 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -205,8 +205,11 @@ print_mdoc(const struct roff_node *n, int indent)
if (n->string != NULL)
printf("=%s", n->string);
}
- if (n->flags & NODE_HREF)
+ if (n->flags & NODE_HREF) {
printf(" HREF");
+ if (n->string != NULL && (n->flags & NODE_ID) == 0)
+ printf("=%s", n->string);
+ }
if (n->flags & NODE_BROKEN)
printf(" BROKEN");
if (n->flags & NODE_NOFILL)