From 38c044546783fd645a03d19bfa871035df45507c Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Thu, 27 Feb 2020 21:43:44 +0000 Subject: Fully support explicit tagging of .Sh and .Ss. This fixes the offset of two lines in terminal output and this improves HTML output by putting the id= attribute and element into the respective

or

element rather than writing an additional element. To that end, introduce node flags NODE_ID (to make the node a link target, for example by writing an HTML id= attribute or by calling tag_put()) and NODE_HREF (to make the node a link source, used only in HTML output, used only to write an

+

Text introducing examples.

+
+

+

Example text.

diff --git a/regress/mdoc/Sh/tag.out_markdown b/regress/mdoc/Sh/tag.out_markdown new file mode 100644 index 00000000..2813f8f0 --- /dev/null +++ b/regress/mdoc/Sh/tag.out_markdown @@ -0,0 +1,27 @@ +SH-TAG(1) - General Commands Manual + +# NAME + +**Sh-tag** - tagging section headers + +# DESCRIPTION + +Text in the description. + +## Subsection + +BEGINTEST + +Text in the subsection. + +# EXAMPLES + +Text introducing examples. + +## Subsection + +Example text. + +ENDTEST + +OpenBSD - February 27, 2020 diff --git a/roff.c b/roff.c index 55172fad..d1f364d4 100644 --- a/roff.c +++ b/roff.c @@ -1173,7 +1173,7 @@ deroff(char **dest, const struct roff_node *n) char *cp; size_t sz; - if (n->type != ROFFT_TEXT) { + if (n->string == NULL) { for (n = n->child; n != NULL; n = n->next) deroff(dest, n); return; diff --git a/roff.h b/roff.h index f9aa35de..37d90b4e 100644 --- a/roff.h +++ b/roff.h @@ -522,6 +522,8 @@ struct roff_node { #define NODE_NOFILL (1 << 8) /* Fill mode switched off. */ #define NODE_NOSRC (1 << 9) /* Generated node, not in input file. */ #define NODE_NOPRT (1 << 10) /* Shall not print anything. */ +#define NODE_ID (1 << 11) /* Target for deep linking. */ +#define NODE_HREF (1 << 12) /* Link to another place in this page. */ int prev_font; /* Before entering this node. */ int aux; /* Decoded node data, type-dependent. */ enum roff_tok tok; /* Request or macro ID. */ diff --git a/tree.c b/tree.c index 1a6d4dd7..5352b868 100644 --- a/tree.c +++ b/tree.c @@ -199,6 +199,13 @@ print_mdoc(const struct roff_node *n, int indent) putchar(')'); if (n->flags & NODE_EOS) putchar('.'); + if (n->flags & NODE_ID) { + printf(" ID"); + if (n->string != NULL) + printf("=%s", n->string); + } + if (n->flags & NODE_HREF) + printf(" HREF"); if (n->flags & NODE_BROKEN) printf(" BROKEN"); if (n->flags & NODE_NOFILL) -- cgit