From 9c50b3f3dd65454028a85113ebc01c5f1f8dabf5 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sat, 4 Apr 2020 20:33:33 +0000 Subject: automatically tag .SH and .SS in man(7) terminal output in the same way as it was done for .Sh and .Ss in mdoc(7) --- man_html.c | 1 - man_validate.c | 25 ++++++++++++++++++++++++- regress/man/IP/empty.out_tag | 2 ++ regress/man/IP/tag.out_tag | 2 ++ regress/man/SH/Makefile | 3 ++- regress/man/SH/paragraph.out_tag | 4 ++++ regress/man/SS/Makefile | 3 ++- regress/man/SS/paragraph.out_tag | 4 ++++ regress/man/TP/tag.out_tag | 2 ++ 9 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 regress/man/SH/paragraph.out_tag create mode 100644 regress/man/SS/paragraph.out_tag diff --git a/man_html.c b/man_html.c index 0a0a5faa..21a76517 100644 --- a/man_html.c +++ b/man_html.c @@ -327,7 +327,6 @@ man_SH_pre(MAN_ARGS) print_otag(h, TAG_SECTION, "c", class); break; case ROFFT_HEAD: - n->flags |= NODE_ID; print_otag_id(h, tag, class, n); break; case ROFFT_BODY: diff --git a/man_validate.c b/man_validate.c index 4e10fb55..aedd8b82 100644 --- a/man_validate.c +++ b/man_validate.c @@ -311,9 +311,32 @@ static void post_SH(CHKARGS) { struct roff_node *nc; + char *cp, *tag; - if (n->type != ROFFT_BODY || (nc = n->child) == NULL) + nc = n->child; + switch (n->type) { + case ROFFT_HEAD: + tag = NULL; + deroff(&tag, n); + if (tag != NULL) { + for (cp = tag; *cp != '\0'; cp++) + if (*cp == ' ') + *cp = '_'; + if (nc != NULL && nc->type == ROFFT_TEXT && + strcmp(nc->string, tag) == 0) + tag_put(NULL, TAG_WEAK, n); + else + tag_put(tag, TAG_FALLBACK, n); + free(tag); + } + return; + case ROFFT_BODY: + if (nc != NULL) + break; return; + default: + return; + } if (nc->tok == MAN_PP && nc->body->child != NULL) { while (nc->body->last != NULL) { diff --git a/regress/man/IP/empty.out_tag b/regress/man/IP/empty.out_tag index f35f1120..081683cf 100644 --- a/regress/man/IP/empty.out_tag +++ b/regress/man/IP/empty.out_tag @@ -1,3 +1,5 @@ +NAME 5 +DESCRIPTION 8 tag1 15 tag2 17 tag 21 diff --git a/regress/man/IP/tag.out_tag b/regress/man/IP/tag.out_tag index 5be038db..13ec09ac 100644 --- a/regress/man/IP/tag.out_tag +++ b/regress/man/IP/tag.out_tag @@ -1,2 +1,4 @@ +NAME 5 +DESCRIPTION 8 strong 13 weak 15 diff --git a/regress/man/SH/Makefile b/regress/man/SH/Makefile index f42a85b2..049680bc 100644 --- a/regress/man/SH/Makefile +++ b/regress/man/SH/Makefile @@ -1,8 +1,9 @@ -# $OpenBSD: Makefile,v 1.7 2020/02/27 01:25:58 schwarze Exp $ +# $OpenBSD: Makefile,v 1.8 2020/04/04 20:23:07 schwarze Exp $ REGRESS_TARGETS = broken broken_eline empty_before longarg noarg paragraph vert LINT_TARGETS = broken broken_eline empty_before noarg HTML_TARGETS = paragraph +TAG_TARGETS = paragraph # groff-1.22.3 defects: # - .SH without args just before EOF causes two additional blank lines. diff --git a/regress/man/SH/paragraph.out_tag b/regress/man/SH/paragraph.out_tag new file mode 100644 index 00000000..18a73f7c --- /dev/null +++ b/regress/man/SH/paragraph.out_tag @@ -0,0 +1,4 @@ +NAME 5 +SYNOPSIS 8 +DESCRIPTION 11 +EXAMPLES 16 diff --git a/regress/man/SS/Makefile b/regress/man/SS/Makefile index edbe4c2c..3a894af2 100644 --- a/regress/man/SS/Makefile +++ b/regress/man/SS/Makefile @@ -1,8 +1,9 @@ -# $OpenBSD: Makefile,v 1.5 2020/02/27 01:25:58 schwarze Exp $ +# $OpenBSD: Makefile,v 1.6 2020/04/04 20:23:07 schwarze Exp $ REGRESS_TARGETS = broken broken_eline longarg noarg paragraph vert LINT_TARGETS = broken broken_eline noarg HTML_TARGETS = paragraph +TAG_TARGETS = paragraph # groff-1.22.3 defects: # - .SS without args just before EOF causes two additional blank lines. diff --git a/regress/man/SS/paragraph.out_tag b/regress/man/SS/paragraph.out_tag new file mode 100644 index 00000000..15451212 --- /dev/null +++ b/regress/man/SS/paragraph.out_tag @@ -0,0 +1,4 @@ +NAME 5 +DESCRIPTION 8 +First_subsection 11 +Second_subsection 16 diff --git a/regress/man/TP/tag.out_tag b/regress/man/TP/tag.out_tag index 88f6cff8..14230d89 100644 --- a/regress/man/TP/tag.out_tag +++ b/regress/man/TP/tag.out_tag @@ -1,3 +1,5 @@ +NAME 5 +DESCRIPTION 8 plain 13 strong 19 weak 21 -- cgit