From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id 86611113 for ; Fri, 13 Apr 2018 11:28:38 -0500 (EST) Date: Fri, 13 Apr 2018 11:28:38 -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: preserve comments before .Dd and .TH (typically Copyright and X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Message-Id: <84f5779447be75e3@fantadrom.bsd.lv> Log Message: ----------- preserve comments before .Dd and .TH (typically Copyright and license) in full HTML output, but not with -Ofragment, e.g. in man.cgi(8); suggested by Thomas Klausner Modified Files: -------------- mandoc: html.c html.h man_html.c mandoc_html.3 mdoc_html.c Revision Data ------------- Index: man_html.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/man_html.c,v retrieving revision 1.146 retrieving revision 1.147 diff -Lman_html.c -Lman_html.c -u -p -r1.146 -r1.147 --- man_html.c +++ man_html.c @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons - * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze + * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -48,7 +48,8 @@ struct htmlman { static void print_bvspace(struct html *, const struct roff_node *); -static void print_man_head(MAN_ARGS); +static void print_man_head(const struct roff_meta *, + struct html *); static void print_man_nodelist(MAN_ARGS); static void print_man_node(MAN_ARGS); static int fillmode(struct html *, int); @@ -68,8 +69,10 @@ static int man_UR_pre(MAN_ARGS); static int man_alt_pre(MAN_ARGS); static int man_ign_pre(MAN_ARGS); static int man_in_pre(MAN_ARGS); -static void man_root_post(MAN_ARGS); -static void man_root_pre(MAN_ARGS); +static void man_root_post(const struct roff_meta *, + struct html *); +static void man_root_pre(const struct roff_meta *, + struct html *); static const struct htmlman __mans[MAN_MAX - MAN_TH] = { { NULL, NULL }, /* TH */ @@ -138,30 +141,34 @@ print_bvspace(struct html *h, const stru void html_man(void *arg, const struct roff_man *man) { - struct html *h; - struct tag *t; + struct html *h; + struct roff_node *n; + struct tag *t; h = (struct html *)arg; + n = man->first->child; if ((h->oflags & HTML_FRAGMENT) == 0) { print_gen_decls(h); print_otag(h, TAG_HTML, ""); + if (n->type == ROFFT_COMMENT) + print_gen_comment(h, n); t = print_otag(h, TAG_HEAD, ""); - print_man_head(&man->meta, man->first, h); + print_man_head(&man->meta, h); print_tagq(h, t); print_otag(h, TAG_BODY, ""); } - man_root_pre(&man->meta, man->first, h); + man_root_pre(&man->meta, h); t = print_otag(h, TAG_DIV, "c", "manual-text"); - print_man_nodelist(&man->meta, man->first->child, h); + print_man_nodelist(&man->meta, n, h); print_tagq(h, t); - man_root_post(&man->meta, man->first, h); + man_root_post(&man->meta, h); print_tagq(h, NULL); } static void -print_man_head(MAN_ARGS) +print_man_head(const struct roff_meta *man, struct html *h) { char *cp; @@ -370,7 +377,7 @@ a2width(const struct roff_node *n, struc } static void -man_root_pre(MAN_ARGS) +man_root_pre(const struct roff_meta *man, struct html *h) { struct tag *t, *tt; char *title; @@ -398,7 +405,7 @@ man_root_pre(MAN_ARGS) } static void -man_root_post(MAN_ARGS) +man_root_post(const struct roff_meta *man, struct html *h) { struct tag *t, *tt; Index: html.h =================================================================== RCS file: /home/cvs/mandoc/mandoc/html.h,v retrieving revision 1.87 retrieving revision 1.88 diff -Lhtml.h -Lhtml.h -u -p -r1.87 -r1.88 --- html.h +++ html.h @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons - * Copyright (c) 2017 Ingo Schwarze + * Copyright (c) 2017, 2018 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -119,6 +119,7 @@ struct eqn_box; void roff_html_pre(struct html *, const struct roff_node *); +void print_gen_comment(struct html *, struct roff_node *); void print_gen_decls(struct html *); void print_gen_head(struct html *); struct tag *print_otag(struct html *, enum htmltag, const char *, ...); Index: mdoc_html.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/mdoc_html.c,v retrieving revision 1.295 retrieving revision 1.296 diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.295 -r1.296 --- mdoc_html.c +++ mdoc_html.c @@ -50,14 +50,17 @@ struct htmlmdoc { }; static char *cond_id(const struct roff_node *); -static void print_mdoc_head(MDOC_ARGS); +static void print_mdoc_head(const struct roff_meta *, + struct html *); static void print_mdoc_node(MDOC_ARGS); static void print_mdoc_nodelist(MDOC_ARGS); static void synopsis_pre(struct html *, const struct roff_node *); -static void mdoc_root_post(MDOC_ARGS); -static int mdoc_root_pre(MDOC_ARGS); +static void mdoc_root_post(const struct roff_meta *, + struct html *); +static int mdoc_root_pre(const struct roff_meta *, + struct html *); static void mdoc__x_post(MDOC_ARGS); static int mdoc__x_pre(MDOC_ARGS); @@ -284,30 +287,34 @@ synopsis_pre(struct html *h, const struc void html_mdoc(void *arg, const struct roff_man *mdoc) { - struct html *h; - struct tag *t; + struct html *h; + struct roff_node *n; + struct tag *t; h = (struct html *)arg; + n = mdoc->first->child; if ((h->oflags & HTML_FRAGMENT) == 0) { print_gen_decls(h); print_otag(h, TAG_HTML, ""); + if (n->type == ROFFT_COMMENT) + print_gen_comment(h, n); t = print_otag(h, TAG_HEAD, ""); - print_mdoc_head(&mdoc->meta, mdoc->first->child, h); + print_mdoc_head(&mdoc->meta, h); print_tagq(h, t); print_otag(h, TAG_BODY, ""); } - mdoc_root_pre(&mdoc->meta, mdoc->first->child, h); + mdoc_root_pre(&mdoc->meta, h); t = print_otag(h, TAG_DIV, "c", "manual-text"); - print_mdoc_nodelist(&mdoc->meta, mdoc->first->child, h); + print_mdoc_nodelist(&mdoc->meta, n, h); print_tagq(h, t); - mdoc_root_post(&mdoc->meta, mdoc->first->child, h); + mdoc_root_post(&mdoc->meta, h); print_tagq(h, NULL); } static void -print_mdoc_head(MDOC_ARGS) +print_mdoc_head(const struct roff_meta *meta, struct html *h) { char *cp; @@ -429,7 +436,7 @@ print_mdoc_node(MDOC_ARGS) } static void -mdoc_root_post(MDOC_ARGS) +mdoc_root_post(const struct roff_meta *meta, struct html *h) { struct tag *t, *tt; @@ -446,7 +453,7 @@ mdoc_root_post(MDOC_ARGS) } static int -mdoc_root_pre(MDOC_ARGS) +mdoc_root_pre(const struct roff_meta *meta, struct html *h) { struct tag *t, *tt; char *volume, *title; Index: html.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/html.c,v retrieving revision 1.220 retrieving revision 1.221 diff -Lhtml.c -Lhtml.c -u -p -r1.220 -r1.221 --- html.c +++ html.c @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons - * Copyright (c) 2011-2015, 2017 Ingo Schwarze + * Copyright (c) 2011-2015, 2017, 2018 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -768,6 +768,32 @@ print_gen_decls(struct html *h) { print_word(h, ""); print_endline(h); +} + +void +print_gen_comment(struct html *h, struct roff_node *n) +{ + int wantblank; + + print_word(h, "") == NULL && + (wantblank || *n->string != '\0')) { + print_endline(h); + print_indent(h); + print_word(h, n->string); + wantblank = *n->string != '\0'; + } + n = n->next; + } + if (wantblank) + print_endline(h); + print_word(h, " -->"); + print_endline(h); + h->indent = 0; } void Index: mandoc_html.3 =================================================================== RCS file: /home/cvs/mandoc/mandoc/mandoc_html.3,v retrieving revision 1.10 retrieving revision 1.11 diff -Lmandoc_html.3 -Lmandoc_html.3 -u -p -r1.10 -r1.11 --- mandoc_html.3 +++ mandoc_html.3 @@ -1,6 +1,6 @@ .\" $Id$ .\" -.\" Copyright (c) 2014, 2017 Ingo Schwarze +.\" Copyright (c) 2014, 2017, 2018 Ingo Schwarze .\" .\" Permission to use, copy, modify, and distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above @@ -25,6 +25,8 @@ .Ft void .Fn print_gen_decls "struct html *h" .Ft void +.Fn print_gen_comment "struct html *h" "struct roff_node *n" +.Ft void .Fn print_gen_head "struct html *h" .Ft struct tag * .Fo print_otag @@ -107,6 +109,18 @@ prints the opening and .Aq Pf \&! Ic DOCTYPE declarations required for the current document type. +.Pp +The function +.Fn print_gen_comment +prints the leading comments, usually containing a Copyright notice +and license, as an HTML comment. +It is intended to be called right after opening the +.Aq Ic HTML +element. +Pass the first +.Dv ROFFT_COMMENT +node in +.Fa n . .Pp The function .Fn print_gen_head -- To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv