summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2018-04-13 16:27:15 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2018-04-13 16:27:15 +0000
commitfccebb05c34a76a5a7a79b282a4fba0d61dcc5af (patch)
tree2db44514a31cd76222c62a39f2d53acb485f0891
parent6bc2fa0a4326f457a7716f57a66f082d22bb418c (diff)
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--usr.bin/mandoc/html.c30
-rw-r--r--usr.bin/mandoc/html.h5
-rw-r--r--usr.bin/mandoc/man_html.c35
-rw-r--r--usr.bin/mandoc/mdoc_html.c33
4 files changed, 72 insertions, 31 deletions
diff --git a/usr.bin/mandoc/html.c b/usr.bin/mandoc/html.c
index 0075de3de0b..feb9f8a8f4d 100644
--- a/usr.bin/mandoc/html.c
+++ b/usr.bin/mandoc/html.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: html.c,v 1.90 2017/09/06 16:24:11 schwarze Exp $ */
+/* $OpenBSD: html.c,v 1.91 2018/04/13 16:27:14 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
@@ -769,6 +769,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/usr.bin/mandoc/html.h b/usr.bin/mandoc/html.h
index 234ab44c60a..b3a8b796461 100644
--- a/usr.bin/mandoc/html.h
+++ b/usr.bin/mandoc/html.h
@@ -1,7 +1,7 @@
-/* $OpenBSD: html.h,v 1.49 2017/07/08 14:51:01 schwarze Exp $ */
+/* $OpenBSD: html.h,v 1.50 2018/04/13 16:27:14 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/usr.bin/mandoc/man_html.c b/usr.bin/mandoc/man_html.c
index 0897b0889c2..4cf1d4235e5 100644
--- a/usr.bin/mandoc/man_html.c
+++ b/usr.bin/mandoc/man_html.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: man_html.c,v 1.99 2018/04/11 17:10:35 schwarze Exp $ */
+/* $OpenBSD: man_html.c,v 1.100 2018/04/13 16:27:14 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
@@ -46,7 +46,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);
@@ -66,8 +67,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 */
@@ -136,30 +139,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;
@@ -368,7 +375,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;
@@ -396,7 +403,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/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c
index cf71eb198f8..cbee6c8edf3 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.170 2018/04/11 17:10:35 schwarze Exp $ */
+/* $OpenBSD: mdoc_html.c,v 1.171 2018/04/13 16:27:14 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -48,14 +48,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);
@@ -282,30 +285,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;
@@ -427,7 +434,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;
@@ -444,7 +451,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;