diff options
Diffstat (limited to 'usr.bin/mandoc')
-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 |
9 files changed, 72 insertions, 24 deletions
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" |