aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2018-04-13 16:28:07 +0000
committerIngo Schwarze <schwarze@openbsd.org>2018-04-13 16:28:07 +0000
commit0c8f9a78c144e759fc8ce4b1b92b1787474385bd (patch)
tree5bd9b378850a798e0f4ab3c4b335909e576d80b0
parent0fde2fa390d9a4194f8a09e5c0f5d921d8755109 (diff)
downloadmandoc-0c8f9a78c144e759fc8ce4b1b92b1787474385bd.tar.gz
mandoc-0c8f9a78c144e759fc8ce4b1b92b1787474385bd.tar.zst
mandoc-0c8f9a78c144e759fc8ce4b1b92b1787474385bd.zip
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 <wiz at NetBSD>
-rw-r--r--html.c30
-rw-r--r--html.h5
-rw-r--r--man_html.c35
-rw-r--r--mandoc_html.320
-rw-r--r--mdoc_html.c33
5 files changed, 89 insertions, 34 deletions
diff --git a/html.c b/html.c
index 65f7eea4..68ec1f14 100644
--- a/html.c
+++ b/html.c
@@ -1,7 +1,7 @@
-/* $Id: html.c,v 1.220 2017/09/06 16:24:25 schwarze Exp $ */
+/* $Id: html.c,v 1.221 2018/04/13 16:28:07 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2011-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2011-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -771,6 +771,32 @@ print_gen_decls(struct html *h)
}
void
+print_gen_comment(struct html *h, struct roff_node *n)
+{
+ int wantblank;
+
+ print_word(h, "<!-- This is an automatically generated file."
+ " Do not edit.");
+ h->indent = 1;
+ wantblank = 0;
+ while (n != NULL && n->type == ROFFT_COMMENT) {
+ if (strstr(n->string, "-->") == 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
print_text(struct html *h, const char *word)
{
if (h->col && (h->flags & HTML_NOSPACE) == 0) {
diff --git a/html.h b/html.h
index c727eacf..d128a76c 100644
--- a/html.h
+++ b/html.h
@@ -1,7 +1,7 @@
-/* $Id: html.h,v 1.87 2017/07/08 14:51:04 schwarze Exp $ */
+/* $Id: html.h,v 1.88 2018/04/13 16:28:07 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
*
* 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 *, ...);
diff --git a/man_html.c b/man_html.c
index efcb87ee..f7942ddd 100644
--- a/man_html.c
+++ b/man_html.c
@@ -1,7 +1,7 @@
-/* $Id: man_html.c,v 1.146 2018/04/11 17:11:13 schwarze Exp $ */
+/* $Id: man_html.c,v 1.147 2018/04/13 16:28:07 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
*
* 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 struct roff_node *n)
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, struct roffsu *su)
}
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;
diff --git a/mandoc_html.3 b/mandoc_html.3
index ba25e0ad..5e7bf607 100644
--- a/mandoc_html.3
+++ b/mandoc_html.3
@@ -1,6 +1,6 @@
-.\" $Id: mandoc_html.3,v 1.10 2017/07/15 17:57:51 schwarze Exp $
+.\" $Id: mandoc_html.3,v 1.11 2018/04/13 16:28:07 schwarze Exp $
.\"
-.\" Copyright (c) 2014, 2017 Ingo Schwarze <schwarze@openbsd.org>
+.\" Copyright (c) 2014, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: July 15 2017 $
+.Dd $Mdocdate: April 13 2018 $
.Dt MANDOC_HTML 3
.Os
.Sh NAME
@@ -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
@@ -109,6 +111,18 @@ and
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
prints the opening
.Aq Ic META
diff --git a/mdoc_html.c b/mdoc_html.c
index 3a047007..6d26f808 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_html.c,v 1.295 2018/04/11 17:11:13 schwarze Exp $ */
+/* $Id: mdoc_html.c,v 1.296 2018/04/13 16:28:07 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 struct roff_node *n)
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;