From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-2.sys.kth.se (smtp-2.sys.kth.se [130.237.32.160]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id p93AGsFR001925 for ; Mon, 3 Oct 2011 06:16:55 -0400 (EDT) Received: from mailscan-1.sys.kth.se (mailscan-1.sys.kth.se [130.237.32.91]) by smtp-2.sys.kth.se (Postfix) with ESMTP id ECAAB10400D for ; Mon, 3 Oct 2011 12:16:48 +0200 (CEST) X-Virus-Scanned: by amavisd-new at kth.se Received: from smtp-2.sys.kth.se ([130.237.32.160]) by mailscan-1.sys.kth.se (mailscan-1.sys.kth.se [130.237.32.91]) (amavisd-new, port 10024) with LMTP id eIROx30TUUPF for ; Mon, 3 Oct 2011 12:16:44 +0200 (CEST) X-KTH-Auth: kristaps [193.10.49.5] X-KTH-mail-from: kristaps@bsd.lv X-KTH-rcpt-to: tech@mdocml.bsd.lv Received: from [172.16.18.84] (unknown [193.10.49.5]) by smtp-2.sys.kth.se (Postfix) with ESMTP id D463114FB74 for ; Mon, 3 Oct 2011 12:16:43 +0200 (CEST) Message-ID: <4E898B8B.4030404@bsd.lv> Date: Mon, 03 Oct 2011 12:16:43 +0200 From: Kristaps Dzonsons User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.20) Gecko/20110820 Icedove/3.1.12 X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 To: tech@mdocml.bsd.lv Subject: HTML fragment mode. Content-Type: multipart/mixed; boundary="------------000605060402000606040303" This is a multi-part message in MIME format. --------------000605060402000606040303 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, Enclosed is a small patch that, with -Ofragmnet, has -T[x]html only emit the CONTENT of an HTML file, not the file stuff itself (DOCTYPE, HTML, HEAD, BODY). It also makes a new top-level node,
, so that it's easier to embed mandoc -Thtml output in other pages. Thus, consider this SSI pseudo-code: blahblah This would be useful for mandoc.cgi, for example, because it wouldn't have to bundle all the extra HTML crap (headers, footers, etc.) nor would it need to use templates, worry about hardcoded CSS paths, etc. Clean! Thoughts? Kristaps --------------000605060402000606040303 Content-Type: text/plain; name="patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch.txt" Index: example.style.css =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/example.style.css,v retrieving revision 1.46 diff -u -r1.46 example.style.css --- example.style.css 26 Aug 2011 09:03:17 -0000 1.46 +++ example.style.css 3 Oct 2011 10:14:25 -0000 @@ -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. */ Index: html.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/html.c,v retrieving revision 1.149 diff -u -r1.149 html.c --- html.c 7 Jul 2011 14:34:11 -0000 1.149 +++ html.c 3 Oct 2011 10:14:25 -0000 @@ -118,13 +118,14 @@ 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)); @@ -142,6 +143,9 @@ break; case (2): h->base_includes = v; + break; + case (3): + h->oflags |= HTML_FRAGMENT; break; default: break; Index: html.h =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/html.h,v retrieving revision 1.46 diff -u -r1.46 html.h --- html.h 18 Sep 2011 14:14:15 -0000 1.46 +++ html.h 3 Oct 2011 10:14:25 -0000 @@ -104,7 +104,7 @@ #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 @@ 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; +#define HTML_FRAGMENT (1 << 0) /* don't emit HTML/HEAD/BODY */ }; void print_gen_decls(struct html *); Index: man_html.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_html.c,v retrieving revision 1.81 diff -u -r1.81 man_html.c --- man_html.c 18 Aug 2011 09:16:01 -0000 1.81 +++ man_html.c 3 Oct 2011 10:14:26 -0000 @@ -141,33 +141,32 @@ 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; + + PAIR_CLASS_INIT(&tag, "mandoc"); - t = print_otag(h, TAG_HEAD, 0, NULL); - print_man_head(m, n, mh, h); - print_tagq(h, t); + 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); } Index: mandoc.1 =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.1,v retrieving revision 1.93 diff -u -r1.93 mandoc.1 --- mandoc.1 26 Sep 2011 20:47:23 -0000 1.93 +++ mandoc.1 3 Oct 2011 10:14:26 -0000 @@ -259,6 +259,11 @@ .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. .It Cm includes Ns = Ns Ar fmt The string .Ar fmt , Index: mdoc_html.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_html.c,v retrieving revision 1.178 diff -u -r1.178 mdoc_html.c --- mdoc_html.c 26 Aug 2011 09:03:17 -0000 1.178 +++ mdoc_html.c 3 Oct 2011 10:14:26 -0000 @@ -262,17 +262,9 @@ 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 @@ static void print_mdoc(MDOC_ARGS) { - struct tag *t; + struct tag *t, *tt; + struct htmlpair tag; + + PAIR_CLASS_INIT(&tag, "mandoc"); - t = print_otag(h, TAG_HEAD, 0, NULL); - print_mdoc_head(m, n, h); - print_tagq(h, t); + 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); } --------------000605060402000606040303-- -- To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv