From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 Received: (qmail 6754 invoked from network); 7 Apr 2020 22:56:53 -0000 Received: from bsd.lv (HELO mandoc.bsd.lv) (66.111.2.12) by inbox.vuxu.org with UTF8ESMTPZ; 7 Apr 2020 22:56:53 -0000 Received: from fantadrom.bsd.lv (localhost [127.0.0.1]) by mandoc.bsd.lv (OpenSMTPD) with ESMTP id cff1ee1c for ; Tue, 7 Apr 2020 17:56:46 -0500 (EST) Received: from localhost (mandoc.bsd.lv [local]) by mandoc.bsd.lv (OpenSMTPD) with ESMTPA id b5a4a018 for ; Tue, 7 Apr 2020 17:56:45 -0500 (EST) Date: Tue, 7 Apr 2020 17:56:45 -0500 (EST) X-Mailinglist: mandoc-source Reply-To: source@mandoc.bsd.lv MIME-Version: 1.0 From: schwarze@mandoc.bsd.lv To: source@mandoc.bsd.lv Subject: mandoc: Separate the place to put the permalink (now marked X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Message-ID: <11ff3e9f625727cf@mandoc.bsd.lv> Log Message: ----------- Separate the place to put the 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. Modified Files: -------------- mandoc: html.c read.c tag.c tag.h tree.c Makefile.depend mandoc/regress/mdoc/Cm: tag.out_html mandoc/regress/mdoc/Dv: tag.out_html mandoc/regress/mdoc/Em: tag.out_html mandoc/regress/mdoc/Er: tag.out_html mandoc/regress/mdoc/Ev: tag.out_html mandoc/regress/mdoc/Fl: tag.out_html mandoc/regress/mdoc/Fo: tag.out_html mandoc/regress/mdoc/Ic: tag.out_html mandoc/regress/mdoc/Li: tag.out_html mandoc/regress/mdoc/Ms: tag.out_html mandoc/regress/mdoc/No: tag.out_html mandoc/regress/mdoc/Sy: tag.out_html mandoc/regress/mdoc/Tg: column.in column.out_ascii column.out_markdown warn.out_html Revision Data ------------- Index: tag.out_html =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/No/tag.out_html,v retrieving revision 1.1 retrieving revision 1.2 diff -Lregress/mdoc/No/tag.out_html -Lregress/mdoc/No/tag.out_html -u -p -r1.1 -r1.2 --- regress/mdoc/No/tag.out_html +++ regress/mdoc/No/tag.out_html @@ -1,9 +1,9 @@
-
+
|
text
-
+
text
Index: tag.out_html =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Er/tag.out_html,v retrieving revision 1.1 retrieving revision 1.2 diff -Lregress/mdoc/Er/tag.out_html -Lregress/mdoc/Er/tag.out_html -u -p -r1.1 -r1.2 --- regress/mdoc/Er/tag.out_html +++ regress/mdoc/Er/tag.out_html @@ -7,6 +7,6 @@

-
[]
+
[]
text
Index: tag.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/tag.c,v retrieving revision 1.32 retrieving revision 1.33 diff -Ltag.c -Ltag.c -u -p -r1.32 -r1.33 --- tag.c +++ tag.c @@ -31,6 +31,7 @@ #include "mandoc_aux.h" #include "mandoc_ohash.h" #include "roff.h" +#include "mdoc.h" #include "tag.h" struct tag_entry { @@ -41,6 +42,8 @@ struct tag_entry { char s[]; }; +static void tag_move_id(struct roff_node *); + static struct ohash tag_data; @@ -181,4 +184,95 @@ int 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 = . */ + np = np->parent; + break; + case LIST_diag: + case LIST_hang: + case LIST_inset: + case LIST_ohang: + case LIST_tag: + /* Target the ROFFT_HEAD =
. */ + np = np->parent->head; + break; + default: + /* Target the ROFF_BODY =
  • . */ + break; + } + /* FALLTHROUGH */ + case MDOC_Pp: /* Target the ROFFT_ELEM =

    . */ + 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); } Index: Makefile.depend =================================================================== RCS file: /home/cvs/mandoc/mandoc/Makefile.depend,v retrieving revision 1.46 retrieving revision 1.47 diff -LMakefile.depend -LMakefile.depend -u -p -r1.46 -r1.47 --- Makefile.depend +++ Makefile.depend @@ -33,7 +33,7 @@ eqn_html.o: eqn_html.c config.h mandoc.h eqn_term.o: eqn_term.c config.h eqn.h out.h term.h html.o: html.c config.h mandoc_aux.h mandoc_ohash.h compat_ohash.h mandoc.h roff.h out.h html.h manconf.h main.h lib.o: lib.c config.h roff.h libmdoc.h lib.in -main.o: main.c config.h mandoc_aux.h mandoc.h mandoc_xr.h roff.h mdoc.h man.h mandoc_parse.h term_tag.h main.h manconf.h mansearch.h +main.o: main.c config.h mandoc_aux.h mandoc.h mandoc_xr.h roff.h mdoc.h man.h mandoc_parse.h tag.h term_tag.h main.h manconf.h mansearch.h man.o: man.c config.h mandoc_aux.h mandoc.h roff.h man.h libmandoc.h roff_int.h libman.h man_html.o: man_html.c config.h mandoc_aux.h mandoc.h roff.h man.h out.h html.h main.h man_macro.o: man_macro.c config.h mandoc.h roff.h man.h libmandoc.h roff_int.h libman.h @@ -67,7 +67,7 @@ roff_term.o: roff_term.c mandoc.h roff.h roff_validate.o: roff_validate.c mandoc.h roff.h libmandoc.h roff_int.h soelim.o: soelim.c config.h compat_stringlist.h st.o: st.c config.h mandoc.h roff.h libmdoc.h -tag.o: tag.c config.h mandoc_aux.h mandoc_ohash.h compat_ohash.h roff.h tag.h +tag.o: tag.c config.h mandoc_aux.h mandoc_ohash.h compat_ohash.h roff.h mdoc.h tag.h tbl.o: tbl.c config.h mandoc_aux.h mandoc.h tbl.h libmandoc.h tbl_parse.h tbl_int.h tbl_data.o: tbl_data.c config.h mandoc_aux.h mandoc.h tbl.h libmandoc.h tbl_int.h tbl_html.o: tbl_html.c config.h mandoc.h roff.h tbl.h out.h html.h Index: tree.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/tree.c,v retrieving revision 1.87 retrieving revision 1.88 diff -Ltree.c -Ltree.c -u -p -r1.87 -r1.88 --- tree.c +++ tree.c @@ -207,8 +207,11 @@ print_mdoc(const struct roff_node *n, in 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) Index: html.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/html.c,v retrieving revision 1.265 retrieving revision 1.266 diff -Lhtml.c -Lhtml.c -u -p -r1.265 -r1.266 --- html.c +++ html.c @@ -779,18 +779,20 @@ print_otag_id(struct html *h, enum htmlt { 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) @@ -799,9 +801,11 @@ print_otag_id(struct html *h, enum htmlt 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; } Index: tag.h =================================================================== RCS file: /home/cvs/mandoc/mandoc/tag.h,v retrieving revision 1.12 retrieving revision 1.13 diff -Ltag.h -Ltag.h -u -p -r1.12 -r1.13 --- tag.h +++ tag.h @@ -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); Index: read.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/read.c,v retrieving revision 1.216 retrieving revision 1.217 diff -Lread.c -Lread.c -u -p -r1.216 -r1.217 --- read.c +++ read.c @@ -708,6 +708,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; } Index: tag.out_html =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Cm/tag.out_html,v retrieving revision 1.2 retrieving revision 1.3 diff -Lregress/mdoc/Cm/tag.out_html -Lregress/mdoc/Cm/tag.out_html -u -p -r1.2 -r1.3 --- regress/mdoc/Cm/tag.out_html +++ regress/mdoc/Cm/tag.out_html @@ -1,15 +1,15 @@

    -
    +
    |
    text
    -
    +
    text
    -
    +
    text
    -
    +
    text
    -
    +
    text
    Index: tag.out_html =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Dv/tag.out_html,v retrieving revision 1.1 retrieving revision 1.2 diff -Lregress/mdoc/Dv/tag.out_html -Lregress/mdoc/Dv/tag.out_html -u -p -r1.1 -r1.2 --- regress/mdoc/Dv/tag.out_html +++ regress/mdoc/Dv/tag.out_html @@ -1,9 +1,9 @@
    -
    +
    |
    text
    -
    +
    text
    Index: tag.out_html =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Em/tag.out_html,v retrieving revision 1.2 retrieving revision 1.3 diff -Lregress/mdoc/Em/tag.out_html -Lregress/mdoc/Em/tag.out_html -u -p -r1.2 -r1.3 --- regress/mdoc/Em/tag.out_html +++ regress/mdoc/Em/tag.out_html @@ -1,8 +1,8 @@
    -
    | +
    |
    text
    -
    +
    text
    Index: tag.out_html =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Ev/tag.out_html,v retrieving revision 1.1 retrieving revision 1.2 diff -Lregress/mdoc/Ev/tag.out_html -Lregress/mdoc/Ev/tag.out_html -u -p -r1.1 -r1.2 --- regress/mdoc/Ev/tag.out_html +++ regress/mdoc/Ev/tag.out_html @@ -1,9 +1,9 @@
    -
    +
    |
    text
    -
    +
    text
    Index: tag.out_html =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Fl/tag.out_html,v retrieving revision 1.1 retrieving revision 1.2 diff -Lregress/mdoc/Fl/tag.out_html -Lregress/mdoc/Fl/tag.out_html -u -p -r1.1 -r1.2 --- regress/mdoc/Fl/tag.out_html +++ regress/mdoc/Fl/tag.out_html @@ -1,8 +1,8 @@
    -
    | +
    |
    text
    -
    +
    text
    Index: tag.out_html =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Fo/tag.out_html,v retrieving revision 1.1 retrieving revision 1.2 diff -Lregress/mdoc/Fo/tag.out_html -Lregress/mdoc/Fo/tag.out_html -u -p -r1.1 -r1.2 --- regress/mdoc/Fo/tag.out_html +++ regress/mdoc/Fo/tag.out_html @@ -1,9 +1,8 @@ -

    automatic: - () - and second()

    -

    () +

    automatic: + () and + second()

    +

    () and first()

    -

    explicit: - () - and +

    explicit: + () and (void);

    Index: tag.out_html =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Ic/tag.out_html,v retrieving revision 1.1 retrieving revision 1.2 diff -Lregress/mdoc/Ic/tag.out_html -Lregress/mdoc/Ic/tag.out_html -u -p -r1.1 -r1.2 --- regress/mdoc/Ic/tag.out_html +++ regress/mdoc/Ic/tag.out_html @@ -1,9 +1,9 @@
    -
    +
    |
    text
    -
    +
    text
    Index: tag.out_html =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Li/tag.out_html,v retrieving revision 1.1 retrieving revision 1.2 diff -Lregress/mdoc/Li/tag.out_html -Lregress/mdoc/Li/tag.out_html -u -p -r1.1 -r1.2 --- regress/mdoc/Li/tag.out_html +++ regress/mdoc/Li/tag.out_html @@ -1,9 +1,9 @@
    -
    +
    |
    text
    -
    +
    text
    Index: tag.out_html =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Ms/tag.out_html,v retrieving revision 1.1 retrieving revision 1.2 diff -Lregress/mdoc/Ms/tag.out_html -Lregress/mdoc/Ms/tag.out_html -u -p -r1.1 -r1.2 --- regress/mdoc/Ms/tag.out_html +++ regress/mdoc/Ms/tag.out_html @@ -1,9 +1,9 @@
    -
    +
    |
    text
    -
    +
    text
    Index: tag.out_html =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Sy/tag.out_html,v retrieving revision 1.1 retrieving revision 1.2 diff -Lregress/mdoc/Sy/tag.out_html -Lregress/mdoc/Sy/tag.out_html -u -p -r1.1 -r1.2 --- regress/mdoc/Sy/tag.out_html +++ regress/mdoc/Sy/tag.out_html @@ -1,8 +1,8 @@
    -
    | +
    |
    text
    -
    +
    text
    Index: column.in =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Tg/column.in,v retrieving revision 1.1 retrieving revision 1.2 diff -Lregress/mdoc/Tg/column.in -Lregress/mdoc/Tg/column.in -u -p -r1.1 -r1.2 --- regress/mdoc/Tg/column.in +++ regress/mdoc/Tg/column.in @@ -1,4 +1,4 @@ -.\" $OpenBSD: column.in,v 1.1 2020/04/06 09:55:50 schwarze Exp $ +.\" $OpenBSD: column.in,v 1.2 2020/04/07 22:45:38 schwarze Exp $ .Dd $Mdocdate$ .Dt TG-COLUMN 1 .Os @@ -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 Index: column.out_ascii =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Tg/column.out_ascii,v retrieving revision 1.1 retrieving revision 1.2 diff -Lregress/mdoc/Tg/column.out_ascii -Lregress/mdoc/Tg/column.out_ascii -u -p -r1.1 -r1.2 --- regress/mdoc/Tg/column.out_ascii +++ regress/mdoc/Tg/column.out_ascii @@ -10,4 +10,4 @@ DDEESSCCRRIIPPTTIIOONN 1 2 ENDTEST -OpenBSD April 6, 2020 OpenBSD +OpenBSD April 7, 2020 OpenBSD Index: column.out_markdown =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Tg/column.out_markdown,v retrieving revision 1.1 retrieving revision 1.2 diff -Lregress/mdoc/Tg/column.out_markdown -Lregress/mdoc/Tg/column.out_markdown -u -p -r1.1 -r1.2 --- regress/mdoc/Tg/column.out_markdown +++ regress/mdoc/Tg/column.out_markdown @@ -13,4 +13,4 @@ BEGINTEST ENDTEST -OpenBSD - April 6, 2020 +OpenBSD - April 7, 2020 Index: warn.out_html =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Tg/warn.out_html,v retrieving revision 1.2 retrieving revision 1.3 diff -Lregress/mdoc/Tg/warn.out_html -Lregress/mdoc/Tg/warn.out_html -u -p -r1.2 -r1.3 --- regress/mdoc/Tg/warn.out_html +++ regress/mdoc/Tg/warn.out_html @@ -1,4 +1,4 @@ -

    initial text +

    initial text too many badstart badend whitespace

    -- To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv