From f383f7b17706b2186a0194c0227f7b6c80542b3c Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Wed, 5 Oct 2011 21:35:17 +0000 Subject: Add the -Ofragment option to -T[]x]html. This accomodates for embedding manual output in existing HTML or XHTML documents, e.g., when invoking mandoc from an SSI or CGI. --- example.style.css | 8 +++++--- html.c | 10 +++++++--- html.h | 10 ++++++---- man_html.c | 35 +++++++++++++++++------------------ mandoc.1 | 10 ++++++++-- mdoc_html.c | 33 +++++++++++++++++---------------- 6 files changed, 60 insertions(+), 46 deletions(-) diff --git a/example.style.css b/example.style.css index 9131ff20..7bd13fc1 100644 --- a/example.style.css +++ b/example.style.css @@ -1,4 +1,4 @@ -/* $Id: example.style.css,v 1.46 2011/08/26 09:03:17 kristaps Exp $ */ +/* $Id: example.style.css,v 1.47 2011/10/05 21:35:17 kristaps Exp $ */ /* * This is an example style-sheet provided for mandoc(1) and the -Thtml @@ -9,8 +9,10 @@ * See mdoc(7) and man(7) for macro explanations. */ -html { min-width: 580px; width: 580px; } -body { font-family: monospace; } +div.mandoc { min-width: 78ex; + width: 78ex; + font-family: monospace; } /* This is the outer node of all mandoc -T[x]html documents. */ + h1 { margin-bottom: 0ex; font-size: inherit; margin-left: -4ex; } /* Section header (Sh, SH). */ h2 { margin-bottom: 0ex; font-size: inherit; margin-left: -2ex; } /* Sub-section header (Ss, SS). */ table { width: 100%; margin-top: 0ex; margin-bottom: 0ex; } /* All tables. */ diff --git a/html.c b/html.c index 6ee11b5e..326df035 100644 --- a/html.c +++ b/html.c @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.149 2011/07/07 14:34:11 kristaps Exp $ */ +/* $Id: html.c,v 1.150 2011/10/05 21:35:17 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze @@ -118,13 +118,14 @@ static void * ml_alloc(char *outopts, enum htmltype type) { struct html *h; - const char *toks[4]; + const char *toks[5]; char *v; toks[0] = "style"; toks[1] = "man"; toks[2] = "includes"; - toks[3] = NULL; + toks[3] = "fragment"; + toks[4] = NULL; h = mandoc_calloc(1, sizeof(struct html)); @@ -143,6 +144,9 @@ ml_alloc(char *outopts, enum htmltype type) case (2): h->base_includes = v; break; + case (3): + h->oflags |= HTML_FRAGMENT; + break; default: break; } diff --git a/html.h b/html.h index d504c80c..60960702 100644 --- a/html.h +++ b/html.h @@ -1,4 +1,4 @@ -/* $Id: html.h,v 1.46 2011/09/18 14:14:15 schwarze Exp $ */ +/* $Id: html.h,v 1.47 2011/10/05 21:35:17 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * @@ -104,7 +104,7 @@ struct htmlpair { #define PAIR_STYLE_INIT(p, h) PAIR_INIT(p, ATTR_STYLE, (h)->buf) #define PAIR_SUMMARY_INIT(p, v) PAIR_INIT(p, ATTR_SUMMARY, v) -enum htmltype { +enum htmltype { HTML_HTML_4_01_STRICT, HTML_XHTML_1_0_STRICT }; @@ -125,11 +125,13 @@ struct html { char *base_includes; /* base for include href */ char *style; /* style-sheet URI */ char buf[BUFSIZ]; /* see bufcat and friends */ - size_t buflen; + size_t buflen; struct tag *metaf; /* current open font scope */ enum htmlfont metal; /* last used font */ enum htmlfont metac; /* current font mode */ - enum htmltype type; + enum htmltype type; /* output media type */ + int oflags; /* output options */ +#define HTML_FRAGMENT (1 << 0) /* don't emit HTML/HEAD/BODY */ }; void print_gen_decls(struct html *); diff --git a/man_html.c b/man_html.c index db6b1f90..e2873402 100644 --- a/man_html.c +++ b/man_html.c @@ -1,4 +1,4 @@ -/* $Id: man_html.c,v 1.81 2011/08/18 09:16:01 kristaps Exp $ */ +/* $Id: man_html.c,v 1.82 2011/10/05 21:35:17 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * @@ -141,33 +141,32 @@ print_bvspace(struct html *h, const struct man_node *n) void html_man(void *arg, const struct man *m) { - struct html *h; - struct tag *t; struct mhtml mh; - h = (struct html *)arg; - - print_gen_decls(h); - memset(&mh, 0, sizeof(struct mhtml)); - - t = print_otag(h, TAG_HTML, 0, NULL); - print_man(man_meta(m), man_node(m), &mh, h); - print_tagq(h, t); - - printf("\n"); + print_man(man_meta(m), man_node(m), &mh, (struct html *)arg); + putchar('\n'); } static void print_man(MAN_ARGS) { - struct tag *t; + struct tag *t, *tt; + struct htmlpair tag; - t = print_otag(h, TAG_HEAD, 0, NULL); - print_man_head(m, n, mh, h); - print_tagq(h, t); + PAIR_CLASS_INIT(&tag, "mandoc"); + + if ( ! (HTML_FRAGMENT & h->oflags)) { + print_gen_decls(h); + t = print_otag(h, TAG_HTML, 0, NULL); + tt = print_otag(h, TAG_HEAD, 0, NULL); + print_man_head(m, n, mh, h); + print_tagq(h, tt); + print_otag(h, TAG_BODY, 0, NULL); + print_otag(h, TAG_DIV, 1, &tag); + } else + t = print_otag(h, TAG_DIV, 1, &tag); - t = print_otag(h, TAG_BODY, 0, NULL); print_man_nodelist(m, n, mh, h); print_tagq(h, t); } diff --git a/mandoc.1 b/mandoc.1 index 2f748283..b629e833 100644 --- a/mandoc.1 +++ b/mandoc.1 @@ -1,4 +1,4 @@ -.\" $Id: mandoc.1,v 1.93 2011/09/26 20:47:23 schwarze Exp $ +.\" $Id: mandoc.1,v 1.94 2011/10/05 21:35:17 kristaps Exp $ .\" .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons .\" @@ -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: September 26 2011 $ +.Dd $Mdocdate: October 5 2011 $ .Dt MANDOC 1 .Os .Sh NAME @@ -259,6 +259,12 @@ The following .Fl O arguments are accepted: .Bl -tag -width Ds +.It Cm fragment +Do not emit doctype, html, and body elements. +The +.Cm style +argument shall be unused. +This is useful when embedding manual content within existing documents. .It Cm includes Ns = Ns Ar fmt The string .Ar fmt , diff --git a/mdoc_html.c b/mdoc_html.c index b1652f0d..bf176391 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.178 2011/08/26 09:03:17 kristaps Exp $ */ +/* $Id: mdoc_html.c,v 1.179 2011/10/05 21:35:17 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * @@ -262,17 +262,9 @@ static const char * const lists[LIST_MAX] = { void html_mdoc(void *arg, const struct mdoc *m) { - struct html *h; - struct tag *t; - - h = (struct html *)arg; - - print_gen_decls(h); - t = print_otag(h, TAG_HTML, 0, NULL); - print_mdoc(mdoc_meta(m), mdoc_node(m), h); - print_tagq(h, t); - printf("\n"); + print_mdoc(mdoc_meta(m), mdoc_node(m), (struct html *)arg); + putchar('\n'); } @@ -360,13 +352,22 @@ a2offs(const char *p, struct roffsu *su) static void print_mdoc(MDOC_ARGS) { - struct tag *t; + struct tag *t, *tt; + struct htmlpair tag; - t = print_otag(h, TAG_HEAD, 0, NULL); - print_mdoc_head(m, n, h); - print_tagq(h, t); + PAIR_CLASS_INIT(&tag, "mandoc"); + + if ( ! (HTML_FRAGMENT & h->oflags)) { + print_gen_decls(h); + t = print_otag(h, TAG_HTML, 0, NULL); + tt = print_otag(h, TAG_HEAD, 0, NULL); + print_mdoc_head(m, n, h); + print_tagq(h, tt); + print_otag(h, TAG_BODY, 0, NULL); + print_otag(h, TAG_DIV, 1, &tag); + } else + t = print_otag(h, TAG_DIV, 1, &tag); - t = print_otag(h, TAG_BODY, 0, NULL); print_mdoc_nodelist(m, n, h); print_tagq(h, t); } -- cgit v1.2.3-56-ge451