]> git.cameronkatri.com Git - mandoc.git/commitdiff
Just like we are already doing it in HTML output, automatically tag
authorIngo Schwarze <schwarze@openbsd.org>
Wed, 1 Apr 2020 20:21:08 +0000 (20:21 +0000)
committerIngo Schwarze <schwarze@openbsd.org>
Wed, 1 Apr 2020 20:21:08 +0000 (20:21 +0000)
section and subsection headers in terminal output, too.  Even though
admittedly, commands like "/SEE" and "/   Subsec" work, too, there
is no downside, and besides, with the recent improvements in the
tagging framework, implementation cost is negligible.

22 files changed:
mdoc_html.c
mdoc_validate.c
regress/mdoc/Cm/tag.out_tag
regress/mdoc/Dv/tag.out_tag
regress/mdoc/Em/tag.out_tag
regress/mdoc/Er/tag.out_tag
regress/mdoc/Ev/tag.out_tag
regress/mdoc/Fl/tag.out_tag
regress/mdoc/Fo/tag.out_tag
regress/mdoc/Ic/tag.out_tag
regress/mdoc/Li/tag.out_tag
regress/mdoc/Ms/tag.out_tag
regress/mdoc/No/tag.out_tag
regress/mdoc/Sh/Makefile
regress/mdoc/Sh/tag.in
regress/mdoc/Sh/tag.out_ascii
regress/mdoc/Sh/tag.out_html
regress/mdoc/Sh/tag.out_lint [new file with mode: 0644]
regress/mdoc/Sh/tag.out_markdown
regress/mdoc/Sh/tag.out_tag [new file with mode: 0644]
regress/mdoc/Sy/tag.out_tag
regress/mdoc/Tg/warn.out_tag

index 8ae8703f7b486e536fd46d3a0594b3af4fdce775..fbfa19a086e706983332e31a2a173349fae0abe2 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mdoc_html.c,v 1.336 2020/03/13 15:32:28 schwarze Exp $ */
+/* $Id: mdoc_html.c,v 1.337 2020/04/01 20:21:08 schwarze Exp $ */
 /*
  * Copyright (c) 2014-2020 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -569,7 +569,6 @@ mdoc_sh_pre(MDOC_ARGS)
                print_otag(h, TAG_SECTION, "c", "Sh");
                break;
        case ROFFT_HEAD:
-               n->flags |= NODE_ID;
                print_otag_id(h, TAG_H1, "Sh", n);
                break;
        case ROFFT_BODY:
@@ -591,7 +590,6 @@ mdoc_ss_pre(MDOC_ARGS)
                print_otag(h, TAG_SECTION, "c", "Ss");
                break;
        case ROFFT_HEAD:
-               n->flags |= NODE_ID;
                print_otag_id(h, TAG_H2, "Ss", n);
                break;
        case ROFFT_BODY:
index bae3d6b8c3e5b6ddbdfa85485c9ba9925d69a0b7..ad096588f1d1a67c3614c2c18230ca67c1b9539b 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.380 2020/03/13 15:32:28 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.381 2020/04/01 20:21:08 schwarze Exp $ */
 /*
  * Copyright (c) 2010-2020 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -96,7 +96,6 @@ static        void     post_fn(POST_ARGS);
 static void     post_fname(POST_ARGS);
 static void     post_fo(POST_ARGS);
 static void     post_hyph(POST_ARGS);
-static void     post_ignpar(POST_ARGS);
 static void     post_it(POST_ARGS);
 static void     post_lb(POST_ARGS);
 static void     post_nd(POST_ARGS);
@@ -109,6 +108,7 @@ static      void     post_prevpar(POST_ARGS);
 static void     post_root(POST_ARGS);
 static void     post_rs(POST_ARGS);
 static void     post_rv(POST_ARGS);
+static void     post_section(POST_ARGS);
 static void     post_sh(POST_ARGS);
 static void     post_sh_head(POST_ARGS);
 static void     post_sh_name(POST_ARGS);
@@ -129,7 +129,7 @@ static      const v_post mdoc_valids[MDOC_MAX - MDOC_Dd] = {
        post_dt,        /* Dt */
        post_os,        /* Os */
        post_sh,        /* Sh */
-       post_ignpar,    /* Ss */
+       post_section,   /* Ss */
        post_par,       /* Pp */
        post_display,   /* D1 */
        post_display,   /* Dl */
@@ -2202,7 +2202,7 @@ post_sx(POST_ARGS)
 static void
 post_sh(POST_ARGS)
 {
-       post_ignpar(mdoc);
+       post_section(mdoc);
 
        switch (mdoc->last->type) {
        case ROFFT_HEAD:
@@ -2535,15 +2535,31 @@ post_xr(POST_ARGS)
 }
 
 static void
-post_ignpar(POST_ARGS)
+post_section(POST_ARGS)
 {
-       struct roff_node *np;
+       struct roff_node *n, *nch;
+       char             *cp, *tag;
 
-       switch (mdoc->last->type) {
+       n = mdoc->last;
+       switch (n->type) {
        case ROFFT_BLOCK:
                post_prevpar(mdoc);
                return;
        case ROFFT_HEAD:
+               tag = NULL;
+               deroff(&tag, n);
+               if (tag != NULL) {
+                       for (cp = tag; *cp != '\0'; cp++)
+                               if (*cp == ' ')
+                                       *cp = '_';
+                       if ((nch = n->child) != NULL &&
+                           nch->type == ROFFT_TEXT &&
+                           strcmp(nch->string, tag) == 0)
+                               tag_put(NULL, TAG_WEAK, n);
+                       else
+                               tag_put(tag, TAG_FALLBACK, n);
+                       free(tag);
+               }
                post_delim(mdoc);
                post_hyph(mdoc);
                return;
@@ -2552,23 +2568,21 @@ post_ignpar(POST_ARGS)
        default:
                return;
        }
-
-       if ((np = mdoc->last->child) != NULL)
-               if (np->tok == MDOC_Pp ||
-                   np->tok == ROFF_br || np->tok == ROFF_sp) {
-                       mandoc_msg(MANDOCERR_PAR_SKIP, np->line, np->pos,
-                           "%s after %s", roff_name[np->tok],
-                           roff_name[mdoc->last->tok]);
-                       roff_node_delete(mdoc, np);
-               }
-
-       if ((np = mdoc->last->last) != NULL)
-               if (np->tok == MDOC_Pp || np->tok == ROFF_br) {
-                       mandoc_msg(MANDOCERR_PAR_SKIP, np->line, np->pos,
-                           "%s at the end of %s", roff_name[np->tok],
-                           roff_name[mdoc->last->tok]);
-                       roff_node_delete(mdoc, np);
-               }
+       if ((nch = n->child) != NULL &&
+           (nch->tok == MDOC_Pp || nch->tok == ROFF_br ||
+            nch->tok == ROFF_sp)) {
+               mandoc_msg(MANDOCERR_PAR_SKIP, nch->line, nch->pos,
+                   "%s after %s", roff_name[nch->tok],
+                   roff_name[n->tok]);
+               roff_node_delete(mdoc, nch);
+       }
+       if ((nch = n->last) != NULL &&
+           (nch->tok == MDOC_Pp || nch->tok == ROFF_br)) {
+               mandoc_msg(MANDOCERR_PAR_SKIP, nch->line, nch->pos,
+                   "%s at the end of %s", roff_name[nch->tok],
+                   roff_name[n->tok]);
+               roff_node_delete(mdoc, nch);
+       }
 }
 
 static void
index 0b97edbcf0f37d1eaa2886be9a0345ec13ddaaa7..3a3a6b138f6cd78ce538312def1e4df4b7069100 100644 (file)
@@ -1,3 +1,5 @@
+NAME 3
+DESCRIPTION 6
 one 9
 two 9
 three 12
index 94f0cfb2c0df086be9ac8aa70ec81b6c39503a59..848d769fae7b9d51edc425065b71ba6b4c05d2c3 100644 (file)
@@ -1,3 +1,5 @@
+NAME 3
+DESCRIPTION 6
 one 9
 two 9
 three 12
index c2fbaf59646890c25d5435c2260c520f711f6557..dd032f4f1f0c74d834d9147363df3cdb359ab798 100644 (file)
@@ -1,3 +1,5 @@
+NAME 3
+DESCRIPTION 6
 one 9
 two 9
 three 12
index b00a67187e0d87232bf85861ee5043f3098ed65a..c074e6cdadfcdb8f76768230cf4296e01d8d9ba9 100644 (file)
@@ -1,2 +1,5 @@
+NAME 3
+DESCRIPTION 6
 two 10
+ERRORS 12
 ENOENT 13
index 94f0cfb2c0df086be9ac8aa70ec81b6c39503a59..848d769fae7b9d51edc425065b71ba6b4c05d2c3 100644 (file)
@@ -1,3 +1,5 @@
+NAME 3
+DESCRIPTION 6
 one 9
 two 9
 three 12
index 89a94151c0de2690df45a5eb66fd90f1bd4df6e7..a3710cac4a184f26637beb6fe86b29805c68195c 100644 (file)
@@ -1,3 +1,5 @@
+NAME 3
+DESCRIPTION 6
 a 9
 b 9
 c 12
index 2387023c8f42128d2581e36399f200bf26c62ca9..901861d18d4506de3fdafdfe4dc393f8b8e4986b 100644 (file)
@@ -1,3 +1,5 @@
+NAME 3
+DESCRIPTION 6
 first 9
 second 11
 e3 13
index 94f0cfb2c0df086be9ac8aa70ec81b6c39503a59..848d769fae7b9d51edc425065b71ba6b4c05d2c3 100644 (file)
@@ -1,3 +1,5 @@
+NAME 3
+DESCRIPTION 6
 one 9
 two 9
 three 12
index 94f0cfb2c0df086be9ac8aa70ec81b6c39503a59..848d769fae7b9d51edc425065b71ba6b4c05d2c3 100644 (file)
@@ -1,3 +1,5 @@
+NAME 3
+DESCRIPTION 6
 one 9
 two 9
 three 12
index 94f0cfb2c0df086be9ac8aa70ec81b6c39503a59..848d769fae7b9d51edc425065b71ba6b4c05d2c3 100644 (file)
@@ -1,3 +1,5 @@
+NAME 3
+DESCRIPTION 6
 one 9
 two 9
 three 12
index 94f0cfb2c0df086be9ac8aa70ec81b6c39503a59..848d769fae7b9d51edc425065b71ba6b4c05d2c3 100644 (file)
@@ -1,3 +1,5 @@
+NAME 3
+DESCRIPTION 6
 one 9
 two 9
 three 12
index 4b37bb2abe04d1106877ed3b7129594d5bdbfead..ea21e5025fdecf1a2909be100b9468f76ae422f9 100644 (file)
@@ -1,11 +1,12 @@
-# $OpenBSD: Makefile,v 1.13 2020/02/27 21:38:27 schwarze Exp $
+# $OpenBSD: Makefile,v 1.14 2020/04/01 20:10:18 schwarze Exp $
 
 REGRESS_TARGETS         = badNAME before empty emptyNAME first nohead order
 REGRESS_TARGETS        += orderNAME paragraph parbefore parborder punctNAME
 REGRESS_TARGETS        += subbefore tag transp
 LINT_TARGETS    = badNAME before empty emptyNAME first nohead order
-LINT_TARGETS   += orderNAME parbefore parborder punctNAME subbefore
+LINT_TARGETS   += orderNAME parbefore parborder punctNAME subbefore tag
 HTML_TARGETS    = paragraph tag
+TAG_TARGETS     = tag
 
 # groff-1.22.3 defects:
 # - .Pp before .Sh NAME causes a blank line before the header line
index 0e0e5fef16e1c6492bce61941a60fa3702a0deda..da8a884a200a0e2357926d7408f2bfbd2e5bd9aa 100644 (file)
@@ -1,5 +1,5 @@
-.\" $OpenBSD: tag.in,v 1.1 2020/02/27 21:38:27 schwarze Exp $
-.Dd $Mdocdate: February 27 2020 $
+.\" $OpenBSD: tag.in,v 1.2 2020/04/01 20:10:18 schwarze Exp $
+.Dd $Mdocdate: April 1 2020 $
 .Dt SH-TAG 1
 .Os
 .Sh NAME
@@ -11,11 +11,17 @@ Text in the description.
 BEGINTEST
 .Pp
 Text in the subsection.
+.Sh DESCRIPTION
+Text in duplicate description section.
 .Tg examples
 .Sh EXAMPLES
 Text introducing examples.
 .Tg example
 .Ss Subsection
 Example text.
+.Sh "\&         WEIRD SECTION   "
+Text in weird section.
+.Sh \ \&
+Text in section with empty header.
 .Pp
 ENDTEST
index df0ab050a1e6395c8b90684daec224c22e947442..309cb5597bf0a5ada4d4a713ed5a03f4adfab3c3 100644 (file)
@@ -11,12 +11,21 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
 
      Text in the subsection.
 
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+     Text in duplicate description section.
+
 E\bEX\bXA\bAM\bMP\bPL\bLE\bES\bS
      Text introducing examples.
 
    S\bSu\bub\bbs\bse\bec\bct\bti\bio\bon\bn
      Example text.
 
+      W\bWE\bEI\bIR\bRD\bD S\bSE\bEC\bCT\bTI\bIO\bON\bN
+     Text in weird section.
+
+
+     Text in section with empty header.
+
      ENDTEST
 
-OpenBSD                        February 27, 2020                       OpenBSD
+OpenBSD                          April 1, 2020                         OpenBSD
index 9722aa8c3c50a934222377a8e381673e018daebe..49c45fdb18e541511acba57688457e2716476bde 100644 (file)
@@ -2,8 +2,22 @@
 </section>
 </section>
 <section class="Sh">
+<h1 class="Sh" id="DESCRIPTION_2"><a class="permalink" href="#DESCRIPTION_2">DESCRIPTION</a></h1>
+<p class="Pp">Text in duplicate description section.</p>
+</section>
+<section class="Sh">
 <h1 class="Sh" id="examples"><a class="permalink" href="#examples">EXAMPLES</a></h1>
 <p class="Pp">Text introducing examples.</p>
 <section class="Ss">
 <h2 class="Ss" id="example"><a class="permalink" href="#example">Subsection</a></h2>
 <p class="Pp">Example text.</p>
+</section>
+</section>
+<section class="Sh">
+<h1 class="Sh" id="WEIRD_SECTION"><a class="permalink" href="#WEIRD_SECTION">  
+  WEIRD SECTION         </a></h1>
+<p class="Pp">Text in weird section.</p>
+</section>
+<section class="Sh">
+<h1 class="Sh">&#x00A0;</h1>
+<p class="Pp">Text in section with empty header.</p>
diff --git a/regress/mdoc/Sh/tag.out_lint b/regress/mdoc/Sh/tag.out_lint
new file mode 100644 (file)
index 0000000..cfb1dfa
--- /dev/null
@@ -0,0 +1,3 @@
+mandoc: tag.in:14:2: WARNING: duplicate section title: Sh DESCRIPTION
+mandoc: tag.in:22:7: WARNING: tab in filled text
+mandoc: tag.in:22:22: WARNING: tab in filled text
index 2813f8f0d2868d26adfa4f930d654172545d9c9c..75a1e58e437f2ef7695acd3dcf63a70555e6dc42 100644 (file)
@@ -14,6 +14,10 @@ BEGINTEST
 
 Text in the subsection.
 
+# DESCRIPTION
+
+Text in duplicate description section.
+
 # EXAMPLES
 
 Text introducing examples.
@@ -22,6 +26,14 @@ Text introducing examples.
 
 Example text.
 
+#       WEIRD SECTION   
+
+Text in weird section.
+
+# &#160;
+
+Text in section with empty header.
+
 ENDTEST
 
-OpenBSD - February 27, 2020
+OpenBSD - April 1, 2020
diff --git a/regress/mdoc/Sh/tag.out_tag b/regress/mdoc/Sh/tag.out_tag
new file mode 100644 (file)
index 0000000..04b1188
--- /dev/null
@@ -0,0 +1,7 @@
+NAME 3
+DESCRIPTION 6
+Subsection 9
+DESCRIPTION 14
+examples 17
+example 20
+WEIRD_SECTION 23
index c2fbaf59646890c25d5435c2260c520f711f6557..dd032f4f1f0c74d834d9147363df3cdb359ab798 100644 (file)
@@ -1,3 +1,5 @@
+NAME 3
+DESCRIPTION 6
 one 9
 two 9
 three 12
index e1fc141c34649a9d4f9e66c2f2da7a3f1fff24a3..6426c3b57e30d8abc11c09907a5dfcfef2b34578 100644 (file)
@@ -1,3 +1,5 @@
+NAME 3
+DESCRIPTION 6
 start 9
 macro 9
 sub 9