diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2020-04-18 20:28:47 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2020-04-18 20:28:47 +0000 |
commit | adc0e7e7748edd333b4d5812fc65a5a80b390c3b (patch) | |
tree | ff4a4c428773b930cc227400d251e1415f1e24be | |
parent | bcc61c2472f57078a62b7714dcd78706d334efd5 (diff) |
When a .Tg is attached to a paragraph, attach the permalink
to the first word, or the first few words if they are short.
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Bd/paragraph.out_html | 8 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Pp/Makefile | 3 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Pp/arg.in | 8 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Pp/arg.out_ascii | 6 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Pp/arg.out_html | 6 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Pp/arg.out_lint | 6 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Pp/arg.out_markdown | 9 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Pp/arg.out_tag | 4 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/blank/transp.out_markdown | 3 | ||||
-rw-r--r-- | usr.bin/mandoc/html.c | 25 | ||||
-rw-r--r-- | usr.bin/mandoc/html.h | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/man_validate.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_html.c | 11 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_validate.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/read.c | 8 | ||||
-rw-r--r-- | usr.bin/mandoc/tag.c | 33 | ||||
-rw-r--r-- | usr.bin/mandoc/tag.h | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/term_tag.c | 3 |
18 files changed, 110 insertions, 39 deletions
diff --git a/regress/usr.bin/mandoc/mdoc/Bd/paragraph.out_html b/regress/usr.bin/mandoc/mdoc/Bd/paragraph.out_html index f537335e0c7..07a0276995f 100644 --- a/regress/usr.bin/mandoc/mdoc/Bd/paragraph.out_html +++ b/regress/usr.bin/mandoc/mdoc/Bd/paragraph.out_html @@ -1,6 +1,8 @@ -<p class="Pp" id="npara">normal paragraph</p> +<p class="Pp" id="npara"><a class="permalink" href="#npara">normal</a> + paragraph</p> <div class="Bd Pp" id="filled">filled display -<p class="Pp" id="fpara">paragraph in display</p> +<p class="Pp" id="fpara"><a class="permalink" href="#fpara">paragraph</a> in + display</p> </div> back to normal <p class="Pp">another paragraph</p> @@ -9,7 +11,7 @@ back to normal unfilled display <mark id="upara"></mark> -unfilled +<a class="permalink" href="#upara">unfilled</a> paragraph </pre> </div> diff --git a/regress/usr.bin/mandoc/mdoc/Pp/Makefile b/regress/usr.bin/mandoc/mdoc/Pp/Makefile index 03d32774e3d..d13a1f3e190 100644 --- a/regress/usr.bin/mandoc/mdoc/Pp/Makefile +++ b/regress/usr.bin/mandoc/mdoc/Pp/Makefile @@ -1,7 +1,8 @@ -# $OpenBSD: Makefile,v 1.7 2020/04/06 09:55:50 schwarze Exp $ +# $OpenBSD: Makefile,v 1.8 2020/04/18 20:28:46 schwarze Exp $ REGRESS_TARGETS = arg TAG_TARGETS = arg LINT_TARGETS = arg +HTML_TARGETS = arg .include <bsd.regress.mk> diff --git a/regress/usr.bin/mandoc/mdoc/Pp/arg.in b/regress/usr.bin/mandoc/mdoc/Pp/arg.in index 1e62c80c377..542cb759f3a 100644 --- a/regress/usr.bin/mandoc/mdoc/Pp/arg.in +++ b/regress/usr.bin/mandoc/mdoc/Pp/arg.in @@ -1,11 +1,13 @@ -.\" $OpenBSD: arg.in,v 1.5 2020/04/06 09:55:50 schwarze Exp $ -.Dd $Mdocdate: April 6 2020 $ +.\" $OpenBSD: arg.in,v 1.6 2020/04/18 20:28:46 schwarze Exp $ +.Dd $Mdocdate: April 18 2020 $ .Dt PP-ARG 1 .Os .Sh NAME .Nm Pp-arg .Nd paragraph macro with arguments .Sh DESCRIPTION +BEGINTEST +.Pp line 1 .Tg first .Pp drop this @@ -17,3 +19,5 @@ line 4 .Tg last .Pp final text +.Pp +ENDTEST diff --git a/regress/usr.bin/mandoc/mdoc/Pp/arg.out_ascii b/regress/usr.bin/mandoc/mdoc/Pp/arg.out_ascii index 70eebb4d991..86ebee94aad 100644 --- a/regress/usr.bin/mandoc/mdoc/Pp/arg.out_ascii +++ b/regress/usr.bin/mandoc/mdoc/Pp/arg.out_ascii @@ -4,6 +4,8 @@ NNAAMMEE PPpp--aarrgg - paragraph macro with arguments DDEESSCCRRIIPPTTIIOONN + BEGINTEST + line 1 line 2 @@ -13,4 +15,6 @@ DDEESSCCRRIIPPTTIIOONN final text -OpenBSD April 6, 2020 OpenBSD + ENDTEST + +OpenBSD April 18, 2020 OpenBSD diff --git a/regress/usr.bin/mandoc/mdoc/Pp/arg.out_html b/regress/usr.bin/mandoc/mdoc/Pp/arg.out_html new file mode 100644 index 00000000000..c601661c4ac --- /dev/null +++ b/regress/usr.bin/mandoc/mdoc/Pp/arg.out_html @@ -0,0 +1,6 @@ +<p class="Pp">line 1</p> +<p class="Pp" id="first"><a class="permalink" href="#first">line 2</a> + <br/> + line 3</p> +<p class="Pp">line 4</p> +<p class="Pp" id="last"><a class="permalink" href="#last">final</a> text</p> diff --git a/regress/usr.bin/mandoc/mdoc/Pp/arg.out_lint b/regress/usr.bin/mandoc/mdoc/Pp/arg.out_lint index 40d77064c32..79cf10cb316 100644 --- a/regress/usr.bin/mandoc/mdoc/Pp/arg.out_lint +++ b/regress/usr.bin/mandoc/mdoc/Pp/arg.out_lint @@ -1,3 +1,3 @@ -mandoc: arg.in:13:5: ERROR: skipping all arguments: br drop this -mandoc: arg.in:15:8: ERROR: skipping excess arguments: sp ... drop this -mandoc: arg.in:11:2: ERROR: skipping all arguments: Pp drop +mandoc: arg.in:15:5: ERROR: skipping all arguments: br drop this +mandoc: arg.in:17:8: ERROR: skipping excess arguments: sp ... drop this +mandoc: arg.in:13:2: ERROR: skipping all arguments: Pp drop diff --git a/regress/usr.bin/mandoc/mdoc/Pp/arg.out_markdown b/regress/usr.bin/mandoc/mdoc/Pp/arg.out_markdown index 0b06ac9ea60..a793f5a1254 100644 --- a/regress/usr.bin/mandoc/mdoc/Pp/arg.out_markdown +++ b/regress/usr.bin/mandoc/mdoc/Pp/arg.out_markdown @@ -6,6 +6,8 @@ PP-ARG(1) - General Commands Manual # DESCRIPTION +BEGINTEST + line 1 line 2 @@ -13,6 +15,9 @@ line 3 line 4 -final text +final +text + +ENDTEST -OpenBSD - April 6, 2020 +OpenBSD - April 18, 2020 diff --git a/regress/usr.bin/mandoc/mdoc/Pp/arg.out_tag b/regress/usr.bin/mandoc/mdoc/Pp/arg.out_tag index 443b1be2c9b..c58db3688f9 100644 --- a/regress/usr.bin/mandoc/mdoc/Pp/arg.out_tag +++ b/regress/usr.bin/mandoc/mdoc/Pp/arg.out_tag @@ -1,4 +1,4 @@ NAME 3 DESCRIPTION 6 -first 9 -last 14 +first 11 +last 16 diff --git a/regress/usr.bin/mandoc/mdoc/blank/transp.out_markdown b/regress/usr.bin/mandoc/mdoc/blank/transp.out_markdown index 9c8ac8258fa..6c317e46632 100644 --- a/regress/usr.bin/mandoc/mdoc/blank/transp.out_markdown +++ b/regress/usr.bin/mandoc/mdoc/blank/transp.out_markdown @@ -23,7 +23,8 @@ Pp sp 2v: sp Pp: -Double sp: +Double +sp: br blank: diff --git a/usr.bin/mandoc/html.c b/usr.bin/mandoc/html.c index 16cc53193a4..90e182ece18 100644 --- a/usr.bin/mandoc/html.c +++ b/usr.bin/mandoc/html.c @@ -1,4 +1,4 @@ -/* $OpenBSD: html.c,v 1.138 2020/04/08 11:54:14 schwarze Exp $ */ +/* $OpenBSD: html.c,v 1.139 2020/04/18 20:28:46 schwarze Exp $ */ /* * Copyright (c) 2011-2015, 2017-2020 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> @@ -876,6 +876,15 @@ print_gen_comment(struct html *h, struct roff_node *n) void print_text(struct html *h, const char *word) { + print_tagged_text(h, word, NULL); +} + +void +print_tagged_text(struct html *h, const char *word, struct roff_node *n) +{ + struct tag *t; + char *href; + /* * Always wrap text in a paragraph unless already contained in * some flow container; never put it directly into a section. @@ -896,13 +905,20 @@ print_text(struct html *h, const char *word) } /* - * Print the text, optionally surrounded by HTML whitespace, - * optionally manually switching fonts before and after. + * Optionally switch fonts, optionally write a permalink, then + * print the text, optionally surrounded by HTML whitespace. */ assert(h->metaf == NULL); print_metaf(h); print_indent(h); + + if (n != NULL && (href = html_make_id(n, 0)) != NULL) { + t = print_otag(h, TAG_A, "chR", "permalink", href); + free(href); + } else + t = NULL; + if ( ! print_encode(h, word, NULL, 0)) { if ( ! (h->flags & HTML_NONOSPACE)) h->flags &= ~HTML_NOSPACE; @@ -913,7 +929,8 @@ print_text(struct html *h, const char *word) if (h->metaf != NULL) { print_tagq(h, h->metaf); h->metaf = NULL; - } + } else if (t != NULL) + print_tagq(h, t); h->flags &= ~HTML_IGNDELIM; } diff --git a/usr.bin/mandoc/html.h b/usr.bin/mandoc/html.h index 7bd55d48af5..dcce339fe8c 100644 --- a/usr.bin/mandoc/html.h +++ b/usr.bin/mandoc/html.h @@ -1,4 +1,4 @@ -/* $OpenBSD: html.h,v 1.69 2020/03/13 00:31:04 schwarze Exp $ */ +/* $OpenBSD: html.h,v 1.70 2020/04/18 20:28:46 schwarze Exp $ */ /* * Copyright (c) 2017, 2018, 2019, 2020 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> @@ -127,6 +127,8 @@ struct tag *print_otag_id(struct html *, enum htmltag, const char *, struct roff_node *); void print_tagq(struct html *, const struct tag *); void print_stagq(struct html *, const struct tag *); +void print_tagged_text(struct html *, const char *, + struct roff_node *); void print_text(struct html *, const char *); void print_tblclose(struct html *); void print_tbl(struct html *, const struct tbl_span *); diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c index 0b28fe4a173..023a81e0efd 100644 --- a/usr.bin/mandoc/man_validate.c +++ b/usr.bin/mandoc/man_validate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_validate.c,v 1.122 2020/04/04 20:23:07 schwarze Exp $ */ +/* $OpenBSD: man_validate.c,v 1.123 2020/04/18 20:28:46 schwarze Exp $ */ /* * Copyright (c) 2010, 2012-2020 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> @@ -32,11 +32,11 @@ #include "mandoc_aux.h" #include "mandoc.h" #include "roff.h" -#include "tag.h" #include "man.h" #include "libmandoc.h" #include "roff_int.h" #include "libman.h" +#include "tag.h" #define CHKARGS struct roff_man *man, struct roff_node *n diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c index d55cb75d0ca..4a277cbc72a 100644 --- a/usr.bin/mandoc/mdoc_html.c +++ b/usr.bin/mandoc/mdoc_html.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_html.c,v 1.213 2020/04/06 09:55:49 schwarze Exp $ */ +/* $OpenBSD: mdoc_html.c,v 1.214 2020/04/18 20:28:46 schwarze Exp $ */ /* * Copyright (c) 2014-2020 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> @@ -375,10 +375,13 @@ print_mdoc_node(MDOC_ARGS) } t = h->tag; t->refcnt++; - if (NODE_DELIMC & n->flags) + if (n->flags & NODE_DELIMC) h->flags |= HTML_NOSPACE; - print_text(h, n->string); - if (NODE_DELIMO & n->flags) + if (n->flags & NODE_HREF) + print_tagged_text(h, n->string, n); + else + print_text(h, n->string); + if (n->flags & NODE_DELIMO) h->flags |= HTML_NOSPACE; break; case ROFFT_EQN: diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index f42751c5d67..c986931639e 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_validate.c,v 1.299 2020/04/08 11:54:14 schwarze Exp $ */ +/* $OpenBSD: mdoc_validate.c,v 1.300 2020/04/18 20:28:46 schwarze Exp $ */ /* * Copyright (c) 2010-2020 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> @@ -35,11 +35,11 @@ #include "mandoc.h" #include "mandoc_xr.h" #include "roff.h" -#include "tag.h" #include "mdoc.h" #include "libmandoc.h" #include "roff_int.h" #include "libmdoc.h" +#include "tag.h" /* FIXME: .Bl -diag can't have non-text children in HEAD. */ diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index 613a17d8062..e344489abf3 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,6 +1,6 @@ -/* $OpenBSD: read.c,v 1.188 2020/04/07 22:45:37 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.189 2020/04/18 20:28:46 schwarze Exp $ */ /* - * Copyright (c) 2010-2019 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2010-2020 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012 Joerg Sonnenberger <joerg@netbsd.org> * @@ -40,12 +40,12 @@ #include "mandoc_aux.h" #include "mandoc.h" #include "roff.h" -#include "tag.h" #include "mdoc.h" #include "man.h" #include "mandoc_parse.h" #include "libmandoc.h" #include "roff_int.h" +#include "tag.h" #define REPARSE_LIMIT 1000 @@ -706,7 +706,7 @@ mparse_result(struct mparse *curp) mdoc_validate(curp->man); else man_validate(curp->man); - tag_postprocess(curp->man->meta.first); + tag_postprocess(curp->man, curp->man->meta.first); } return &curp->man->meta; } diff --git a/usr.bin/mandoc/tag.c b/usr.bin/mandoc/tag.c index 97d2dc71806..3bd48941388 100644 --- a/usr.bin/mandoc/tag.c +++ b/usr.bin/mandoc/tag.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tag.c,v 1.34 2020/04/08 11:54:14 schwarze Exp $ */ +/* $OpenBSD: tag.c,v 1.35 2020/04/18 20:28:46 schwarze Exp $ */ /* * Copyright (c) 2015,2016,2018,2019,2020 Ingo Schwarze <schwarze@openbsd.org> * @@ -30,6 +30,7 @@ #include "mandoc_ohash.h" #include "roff.h" #include "mdoc.h" +#include "roff_int.h" #include "tag.h" struct tag_entry { @@ -256,13 +257,37 @@ tag_move_id(struct roff_node *n) * to the beginning of the respective paragraphs. */ void -tag_postprocess(struct roff_node *n) +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; + break; case MDOC_Bd: case MDOC_Bl: - case MDOC_Pp: /* XXX No permalink for now. */ break; default: @@ -279,5 +304,5 @@ tag_postprocess(struct roff_node *n) } } for (n = n->child; n != NULL; n = n->next) - tag_postprocess(n); + tag_postprocess(man, n); } diff --git a/usr.bin/mandoc/tag.h b/usr.bin/mandoc/tag.h index 9bbcd6a71f1..7fa7504643b 100644 --- a/usr.bin/mandoc/tag.h +++ b/usr.bin/mandoc/tag.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tag.h,v 1.13 2020/04/07 22:45:37 schwarze Exp $ */ +/* $OpenBSD: tag.h,v 1.14 2020/04/18 20:28:46 schwarze Exp $ */ /* * Copyright (c) 2015, 2018, 2019, 2020 Ingo Schwarze <schwarze@openbsd.org> * @@ -31,5 +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_postprocess(struct roff_man *, struct roff_node *); void tag_free(void); diff --git a/usr.bin/mandoc/term_tag.c b/usr.bin/mandoc/term_tag.c index 4b05816046a..1c67dcc1703 100644 --- a/usr.bin/mandoc/term_tag.c +++ b/usr.bin/mandoc/term_tag.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term_tag.c,v 1.3 2020/04/08 11:54:14 schwarze Exp $ */ +/* $OpenBSD: term_tag.c,v 1.4 2020/04/18 20:28:46 schwarze Exp $ */ /* * Copyright (c) 2015,2016,2018,2019,2020 Ingo Schwarze <schwarze@openbsd.org> * @@ -29,6 +29,7 @@ #include "mandoc.h" #include "roff.h" +#include "roff_int.h" #include "tag.h" #include "term_tag.h" |