aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2020-04-19 16:36:16 +0000
committerIngo Schwarze <schwarze@openbsd.org>2020-04-19 16:36:16 +0000
commit53e82aa8ae9cb194d4b8418e8dd4223a4a5097d3 (patch)
tree574a3520a99a5f38f585bd966a97f48de110c942
parent4ee381e7bf5e05beda919be00d162d31ae86f4b8 (diff)
downloadmandoc-53e82aa8ae9cb194d4b8418e8dd4223a4a5097d3.tar.gz
mandoc-53e82aa8ae9cb194d4b8418e8dd4223a4a5097d3.tar.zst
mandoc-53e82aa8ae9cb194d4b8418e8dd4223a4a5097d3.zip
When .Bd, .D1, or .Dl is tagged, attach the permalink
to the first few letters, similar to what was earlier done for .Pp.
-rw-r--r--regress/mdoc/Bd/Makefile6
-rw-r--r--regress/mdoc/Bd/nested.in15
-rw-r--r--regress/mdoc/Bd/nested.out_ascii5
-rw-r--r--regress/mdoc/Bd/nested.out_html28
-rw-r--r--regress/mdoc/Bd/nested.out_lint4
-rw-r--r--regress/mdoc/Bd/nested.out_markdown14
-rw-r--r--regress/mdoc/Bd/nested.out_tag8
-rw-r--r--regress/mdoc/Bd/paragraph.in10
-rw-r--r--regress/mdoc/Bd/paragraph.out_ascii6
-rw-r--r--regress/mdoc/Bd/paragraph.out_html7
-rw-r--r--regress/mdoc/Bd/paragraph.out_markdown6
-rw-r--r--regress/mdoc/Bd/spacing.out_tag4
-rw-r--r--regress/mdoc/D1/spacing.out_html4
-rw-r--r--regress/mdoc/Dl/Makefile3
-rw-r--r--regress/mdoc/Dl/spacing.in10
-rw-r--r--regress/mdoc/Dl/spacing.out_ascii6
-rw-r--r--regress/mdoc/Dl/spacing.out_html8
-rw-r--r--regress/mdoc/Dl/spacing.out_lint2
-rw-r--r--regress/mdoc/Dl/spacing.out_markdown8
-rw-r--r--regress/mdoc/Dl/spacing.out_tag2
-rw-r--r--regress/mdoc/Pp/arg.out_markdown3
-rw-r--r--regress/mdoc/blank/transp.out_markdown3
-rw-r--r--tag.c65
23 files changed, 154 insertions, 73 deletions
diff --git a/regress/mdoc/Bd/Makefile b/regress/mdoc/Bd/Makefile
index a7319e70..d516f141 100644
--- a/regress/mdoc/Bd/Makefile
+++ b/regress/mdoc/Bd/Makefile
@@ -1,12 +1,12 @@
-# $OpenBSD: Makefile,v 1.23 2020/04/06 09:55:49 schwarze Exp $
+# $OpenBSD: Makefile,v 1.24 2020/04/19 16:26:11 schwarze Exp $
REGRESS_TARGETS = beforeNAME blank centered nested nf paragraph spacing
REGRESS_TARGETS += badargs empty offset-empty offset-neg
REGRESS_TARGETS += break broken unclosed
-TAG_TARGETS = nested paragraph
+TAG_TARGETS = nested paragraph spacing
LINT_TARGETS = beforeNAME blank nested badargs break broken unclosed
-HTML_TARGETS = nf paragraph
+HTML_TARGETS = nested nf paragraph
SKIP_TMAN = beforeNAME centered
diff --git a/regress/mdoc/Bd/nested.in b/regress/mdoc/Bd/nested.in
index 450c1fb4..007a7e94 100644
--- a/regress/mdoc/Bd/nested.in
+++ b/regress/mdoc/Bd/nested.in
@@ -1,21 +1,23 @@
-.\" $OpenBSD: nested.in,v 1.3 2020/04/06 09:55:49 schwarze Exp $
-.Dd $Mdocdate: April 6 2020 $
+.\" $OpenBSD: nested.in,v 1.4 2020/04/19 16:26:11 schwarze Exp $
+.Dd $Mdocdate: April 19 2020 $
.Dt BD-NESTED 1
.Os
.Sh NAME
.Nm Bd-nested
.Nd nested displays and lists
.Sh DESCRIPTION
+BEGINTEST
+.Pp
regular
text
.Tg outer
.Bd -ragged -offset indent
-outer
-text (default indent)
+outer text
+.Pq default indent
.Tg inner
.Bd -ragged -offset indent
-inner
-text (default indent)
+inner text
+.Pq default indent
.Ed
outer
text
@@ -45,3 +47,4 @@ inner text (2n)
.Ed
outer text
.El
+ENDTEST
diff --git a/regress/mdoc/Bd/nested.out_ascii b/regress/mdoc/Bd/nested.out_ascii
index 1d27c178..2381a6bf 100644
--- a/regress/mdoc/Bd/nested.out_ascii
+++ b/regress/mdoc/Bd/nested.out_ascii
@@ -4,6 +4,8 @@ NNAAMMEE
BBdd--nneesstteedd - nested displays and lists
DDEESSCCRRIIPPTTIIOONN
+ BEGINTEST
+
regular text
outer text (default indent)
@@ -25,5 +27,6 @@ DDEESSCCRRIIPPTTIIOONN
inner text (2n)
outer text
+ ENDTEST
-OpenBSD April 6, 2020 OpenBSD
+OpenBSD April 19, 2020 OpenBSD
diff --git a/regress/mdoc/Bd/nested.out_html b/regress/mdoc/Bd/nested.out_html
new file mode 100644
index 00000000..bc71c270
--- /dev/null
+++ b/regress/mdoc/Bd/nested.out_html
@@ -0,0 +1,28 @@
+<p class="Pp">regular text</p>
+<div class="Bd Pp
+ Bd-indent" id="outer"><a class="permalink" href="#outer">outer</a> text
+ (default indent)
+<div class="Bd Pp
+ Bd-indent" id="inner"><a class="permalink" href="#inner">inner</a> text
+ (default indent)</div>
+outer text</div>
+regular text
+<div class="Bd Pp
+ Bd-indent" id="outer_2"><a class="permalink" href="#outer_2">outer</a> text
+ (4n)
+<div class="Bd Pp
+ Bd-indent" id="inner_2"><a class="permalink" href="#inner_2">inner</a> text
+ (2n)</div>
+outer text
+<dl class="Bl-tag">
+ <dt>tag</dt>
+ <dd>text</dd>
+</dl>
+outer text</div>
+regular text
+<dl class="Bl-tag">
+ <dt>tag</dt>
+ <dd>outer text
+ <div class="Bd Pp Bd-indent">inner text (2n)</div>
+ outer text</dd>
+</dl>
diff --git a/regress/mdoc/Bd/nested.out_lint b/regress/mdoc/Bd/nested.out_lint
index 5a6a6966..ca44cdd6 100644
--- a/regress/mdoc/Bd/nested.out_lint
+++ b/regress/mdoc/Bd/nested.out_lint
@@ -1,2 +1,2 @@
-mandoc: nested.in:16:2: WARNING: nested displays are not portable: Bd in Bd
-mandoc: nested.in:29:2: WARNING: nested displays are not portable: Bd in Bd
+mandoc: nested.in:18:2: WARNING: nested displays are not portable: Bd in Bd
+mandoc: nested.in:31:2: WARNING: nested displays are not portable: Bd in Bd
diff --git a/regress/mdoc/Bd/nested.out_markdown b/regress/mdoc/Bd/nested.out_markdown
index e647a0df..aef7e4b0 100644
--- a/regress/mdoc/Bd/nested.out_markdown
+++ b/regress/mdoc/Bd/nested.out_markdown
@@ -6,14 +6,16 @@ BD-NESTED(1) - General Commands Manual
# DESCRIPTION
+BEGINTEST
+
regular
text
-> outer
-> text (default indent)
+> outer text
+> (default indent)
-> > inner
-> > text (default indent)
+> > inner text
+> > (default indent)
> outer
> text
@@ -43,4 +45,6 @@ tag
> outer text
-OpenBSD - April 6, 2020
+ENDTEST
+
+OpenBSD - April 19, 2020
diff --git a/regress/mdoc/Bd/nested.out_tag b/regress/mdoc/Bd/nested.out_tag
index 7b9c2012..c02287f7 100644
--- a/regress/mdoc/Bd/nested.out_tag
+++ b/regress/mdoc/Bd/nested.out_tag
@@ -1,6 +1,6 @@
NAME 3
DESCRIPTION 6
-outer 9
-inner 11
-outer 15
-inner 17
+outer 11
+inner 13
+outer 17
+inner 19
diff --git a/regress/mdoc/Bd/paragraph.in b/regress/mdoc/Bd/paragraph.in
index 8e53d0e7..2b58406e 100644
--- a/regress/mdoc/Bd/paragraph.in
+++ b/regress/mdoc/Bd/paragraph.in
@@ -1,5 +1,5 @@
-.\" $OpenBSD: paragraph.in,v 1.2 2020/04/06 09:55:49 schwarze Exp $
-.Dd $Mdocdate: April 6 2020 $
+.\" $OpenBSD: paragraph.in,v 1.3 2020/04/19 16:26:11 schwarze Exp $
+.Dd $Mdocdate: April 19 2020 $
.Dt BD-PARAGRAPH 1
.Os
.Sh NAME
@@ -28,12 +28,12 @@ to normal
another
paragraph
.Tg unfilled
-.Bd -unfilled
-unfilled
+.Bd -literal
+unfilled literal
display
.Tg upara
.Pp
-unfilled
+unfilled literal
paragraph
.Ed
again back
diff --git a/regress/mdoc/Bd/paragraph.out_ascii b/regress/mdoc/Bd/paragraph.out_ascii
index bf122ce0..be9583d8 100644
--- a/regress/mdoc/Bd/paragraph.out_ascii
+++ b/regress/mdoc/Bd/paragraph.out_ascii
@@ -15,13 +15,13 @@ DDEESSCCRRIIPPTTIIOONN
another paragraph
- unfilled
+ unfilled literal
display
- unfilled
+ unfilled literal
paragraph
again back to normal
ENDTEST
end of file
-OpenBSD April 6, 2020 OpenBSD
+OpenBSD April 19, 2020 OpenBSD
diff --git a/regress/mdoc/Bd/paragraph.out_html b/regress/mdoc/Bd/paragraph.out_html
index 07a02769..cc3491c9 100644
--- a/regress/mdoc/Bd/paragraph.out_html
+++ b/regress/mdoc/Bd/paragraph.out_html
@@ -1,6 +1,7 @@
<p class="Pp" id="npara"><a class="permalink" href="#npara">normal</a>
paragraph</p>
-<div class="Bd Pp" id="filled">filled display
+<div class="Bd Pp" id="filled"><a class="permalink" href="#filled">filled</a>
+ display
<p class="Pp" id="fpara"><a class="permalink" href="#fpara">paragraph</a> in
display</p>
</div>
@@ -8,10 +9,10 @@ back to normal
<p class="Pp">another paragraph</p>
<div class="Bd Pp" id="unfilled">
<pre>
-unfilled
+<a class="permalink" href="#unfilled">unfilled</a> literal
display
<mark id="upara"></mark>
-<a class="permalink" href="#upara">unfilled</a>
+<a class="permalink" href="#upara">unfilled</a> literal
paragraph
</pre>
</div>
diff --git a/regress/mdoc/Bd/paragraph.out_markdown b/regress/mdoc/Bd/paragraph.out_markdown
index 6e569b5d..af74b7b4 100644
--- a/regress/mdoc/Bd/paragraph.out_markdown
+++ b/regress/mdoc/Bd/paragraph.out_markdown
@@ -25,10 +25,10 @@ to normal
another
paragraph
- unfilled
+ unfilled literal
display
- unfilled
+ unfilled literal
paragraph
again back
@@ -36,4 +36,4 @@ to normal
ENDTEST
end of file
-OpenBSD - April 6, 2020
+OpenBSD - April 19, 2020
diff --git a/regress/mdoc/Bd/spacing.out_tag b/regress/mdoc/Bd/spacing.out_tag
new file mode 100644
index 00000000..b986cab0
--- /dev/null
+++ b/regress/mdoc/Bd/spacing.out_tag
@@ -0,0 +1,4 @@
+NAME 3
+DESCRIPTION 6
+EXAMPLES 14
+word 15
diff --git a/regress/mdoc/D1/spacing.out_html b/regress/mdoc/D1/spacing.out_html
index 3a9affc9..726a9be5 100644
--- a/regress/mdoc/D1/spacing.out_html
+++ b/regress/mdoc/D1/spacing.out_html
@@ -1,7 +1,7 @@
<p class="Pp">preceding paragraph</p>
<div class="Bd
- Bd-indent" id="display"><a class="permalink" href="#display">spacing in and
- around one-line displays</a></div>
+ Bd-indent" id="display"><a class="permalink" href="#display">spacing</a> in
+ and around one-line displays</div>
empty display:
<div class="Bd Bd-indent"></div>
following text
diff --git a/regress/mdoc/Dl/Makefile b/regress/mdoc/Dl/Makefile
index 51605be0..33a7b034 100644
--- a/regress/mdoc/Dl/Makefile
+++ b/regress/mdoc/Dl/Makefile
@@ -1,7 +1,8 @@
-# $OpenBSD: Makefile,v 1.5 2020/04/06 09:55:49 schwarze Exp $
+# $OpenBSD: Makefile,v 1.6 2020/04/19 16:26:11 schwarze Exp $
REGRESS_TARGETS = spacing
TAG_TARGETS = spacing
LINT_TARGETS = spacing
+HTML_TARGETS = spacing
.include <bsd.regress.mk>
diff --git a/regress/mdoc/Dl/spacing.in b/regress/mdoc/Dl/spacing.in
index 96d77ac7..70ce62d0 100644
--- a/regress/mdoc/Dl/spacing.in
+++ b/regress/mdoc/Dl/spacing.in
@@ -1,14 +1,20 @@
-.\" $OpenBSD: spacing.in,v 1.5 2020/04/06 09:55:49 schwarze Exp $
-.Dd $Mdocdate: April 6 2020 $
+.\" $OpenBSD: spacing.in,v 1.6 2020/04/19 16:26:11 schwarze Exp $
+.Dd $Mdocdate: April 19 2020 $
.Dt DL-SPACING 1
.Os
.Sh NAME
.Nm Dl-spacing
.Nd spacing in and around one-line literal displays
.Sh DESCRIPTION
+BEGINTEST
+.Pp
preceding text
.Tg display
.Dl spacing in and around one-line literal displays
empty display:
.Dl
following text
+.br
+ENDTEST
+.br
+end of file
diff --git a/regress/mdoc/Dl/spacing.out_ascii b/regress/mdoc/Dl/spacing.out_ascii
index c96eca32..9d7f07fd 100644
--- a/regress/mdoc/Dl/spacing.out_ascii
+++ b/regress/mdoc/Dl/spacing.out_ascii
@@ -4,9 +4,13 @@ NNAAMMEE
DDll--ssppaacciinngg - spacing in and around one-line literal displays
DDEESSCCRRIIPPTTIIOONN
+ BEGINTEST
+
preceding text
spacing in and around one-line literal displays
empty display:
following text
+ ENDTEST
+ end of file
-OpenBSD April 6, 2020 OpenBSD
+OpenBSD April 19, 2020 OpenBSD
diff --git a/regress/mdoc/Dl/spacing.out_html b/regress/mdoc/Dl/spacing.out_html
new file mode 100644
index 00000000..122f4f69
--- /dev/null
+++ b/regress/mdoc/Dl/spacing.out_html
@@ -0,0 +1,8 @@
+<p class="Pp">preceding text</p>
+<div class="Bd
+ Bd-indent" id="display"><code class="Li"><a class="permalink" href="#display">spacing</a>
+ in and around one-line literal displays</code></div>
+empty display:
+<div class="Bd Bd-indent"><code class="Li"></code></div>
+following text
+<br/>
diff --git a/regress/mdoc/Dl/spacing.out_lint b/regress/mdoc/Dl/spacing.out_lint
index a31f329f..ff047dc6 100644
--- a/regress/mdoc/Dl/spacing.out_lint
+++ b/regress/mdoc/Dl/spacing.out_lint
@@ -1 +1 @@
-mandoc: spacing.in:13:2: WARNING: empty block: Dl
+mandoc: spacing.in:15:2: WARNING: empty block: Dl
diff --git a/regress/mdoc/Dl/spacing.out_markdown b/regress/mdoc/Dl/spacing.out_markdown
index 27dab22c..4a6d9302 100644
--- a/regress/mdoc/Dl/spacing.out_markdown
+++ b/regress/mdoc/Dl/spacing.out_markdown
@@ -6,12 +6,16 @@ DL-SPACING(1) - General Commands Manual
# DESCRIPTION
+BEGINTEST
+
preceding text
spacing in and around one-line literal displays
empty display:
-following text
+following text
+ENDTEST
+end of file
-OpenBSD - April 6, 2020
+OpenBSD - April 19, 2020
diff --git a/regress/mdoc/Dl/spacing.out_tag b/regress/mdoc/Dl/spacing.out_tag
index b036279d..73ab507a 100644
--- a/regress/mdoc/Dl/spacing.out_tag
+++ b/regress/mdoc/Dl/spacing.out_tag
@@ -1,3 +1,3 @@
NAME 3
DESCRIPTION 6
-display 8
+display 10
diff --git a/regress/mdoc/Pp/arg.out_markdown b/regress/mdoc/Pp/arg.out_markdown
index a793f5a1..b0d0744e 100644
--- a/regress/mdoc/Pp/arg.out_markdown
+++ b/regress/mdoc/Pp/arg.out_markdown
@@ -15,8 +15,7 @@ line 3
line 4
-final
-text
+final text
ENDTEST
diff --git a/regress/mdoc/blank/transp.out_markdown b/regress/mdoc/blank/transp.out_markdown
index 6c317e46..9c8ac825 100644
--- a/regress/mdoc/blank/transp.out_markdown
+++ b/regress/mdoc/blank/transp.out_markdown
@@ -23,8 +23,7 @@ Pp sp 2v:
sp Pp:
-Double
-sp:
+Double sp:
br blank:
diff --git a/tag.c b/tag.c
index 105f19e1..fcaad99f 100644
--- a/tag.c
+++ b/tag.c
@@ -1,4 +1,4 @@
-/* $Id: tag.c,v 1.35 2020/04/18 20:40:10 schwarze Exp $ */
+/* $Id: tag.c,v 1.36 2020/04/19 16:36:16 schwarze Exp $ */
/*
* Copyright (c) 2015,2016,2018,2019,2020 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -43,6 +43,8 @@ struct tag_entry {
char s[];
};
+static void tag_move_href(struct roff_man *,
+ struct roff_node *, const char *);
static void tag_move_id(struct roff_node *);
static struct ohash tag_data;
@@ -254,6 +256,39 @@ tag_move_id(struct roff_node *n)
}
/*
+ * When a paragraph is tagged and starts with text,
+ * move the permalink to the first few words.
+ */
+static void
+tag_move_href(struct roff_man *man, struct roff_node *n, const char *tag)
+{
+ char *cp;
+
+ if (n == NULL || n->type != ROFFT_TEXT ||
+ *n->string == '\0' || *n->string == ' ')
+ return;
+
+ cp = n->string;
+ while (cp != NULL && cp - n->string < 5)
+ cp = strchr(cp + 1, ' ');
+
+ /* If the first text node is longer, split it. */
+
+ if (cp != NULL && cp[1] != '\0') {
+ man->last = n;
+ man->next = ROFF_NEXT_SIBLING;
+ roff_word_alloc(man, n->line,
+ n->pos + (cp - n->string), cp + 1);
+ man->last->flags = n->flags & ~NODE_LINE;
+ *cp = '\0';
+ }
+
+ assert(n->tag == NULL);
+ n->tag = mandoc_strdup(tag);
+ n->flags |= NODE_HREF;
+}
+
+/*
* 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.
@@ -261,34 +296,16 @@ tag_move_id(struct roff_node *n)
void
tag_postprocess(struct roff_man *man, struct roff_node *n)
{
- struct roff_node *nn;
- char *cp;
-
if (n->flags & NODE_ID) {
switch (n->tok) {
case MDOC_Pp:
- nn = n->next;
- if (nn == NULL || nn->type != ROFFT_TEXT ||
- *nn->string == '\0' || *nn->string == ' ')
- break;
- /* Use the first few letters for the permalink. */
- cp = nn->string;
- while (cp != NULL && cp - nn->string < 5)
- cp = strchr(cp + 1, ' ');
- if (cp != NULL && cp[1] != '\0') {
- /* Split a longer text node. */
- man->last = nn;
- man->next = ROFF_NEXT_SIBLING;
- roff_word_alloc(man, nn->line,
- nn->pos + (cp - nn->string), cp + 1);
- man->last->flags = nn->flags;
- *cp = '\0';
- }
- assert(nn->tag == NULL);
- nn->tag = mandoc_strdup(n->tag);
- nn->flags |= NODE_HREF;
+ tag_move_href(man, n->next, n->tag);
break;
case MDOC_Bd:
+ case MDOC_D1:
+ case MDOC_Dl:
+ tag_move_href(man, n->child, n->tag);
+ break;
case MDOC_Bl:
/* XXX No permalink for now. */
break;