author | Olivier Brunel
<jjk@jjacky.com> 2023-01-14 16:34:30 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2023-01-14 16:34:30 UTC |
parent | f500874a449a890183b0d959db6e30e8a781fe5d |
doc/qmdoc.1.md | +22 | -4 |
src/main.c | +18 | -5 |
diff --git a/doc/qmdoc.1.md b/doc/qmdoc.1.md index 42a6713..fead0bc 100644 --- a/doc/qmdoc.1.md +++ b/doc/qmdoc.1.md @@ -58,16 +58,23 @@ featured inside a meta tag as well as in the footer of generated pages. : *-F* `FILE`, *--footer* `FILE` :: Insert `FILE` as footer on every generated page. `FILE` is expected to -:: contain valid HTML code, and will be inserted right before a page's `</body>` -:: tag. +:: contain valid HTML code, and will be inserted as-is on top of the page's +:: content. + +:: ! HINT: +:: ! You can have the content of `FILE` inserted right at the opening of the +:: ! `body` tag by using `--wide-include` : *-H* `FILE`, *--header* `FILE` :: Insert `FILE` as header on every generated page. `FILE` is expected to -:: contain valid HTML code, and will be inserted right after a page's `<body>` -:: tag. +:: contain valid HTML code, and will be inserted as-is on bottom of the page's +:: content. +:: ! HINT: +:: ! You can have the content of `FILE` inserted right before the closing of the +:: ! `body` tag by using `--wide-include` : *-h*, *--help* @@ -153,6 +160,17 @@ table of contents for the entire generated documentation. :: generated pages. +: *-W*, *--wide-include* + +:: When using `--header` and/or `--footer` the content of the specified file is +:: included within the page's `<section>`, thus appearing on top/bottom of the +:: page's content (i.e. on the right side, "after"/next to the Table of +:: Contents). + +:: When using `--wide-include` it will be inserted right after the opening of +:: the `<body>` for the header, right before its closing for the footer. + + : *-X*, *--no-index* :: Disable index mode. See [[INDEX MODE]] for more information. diff --git a/src/main.c b/src/main.c index b1a2371..716f347 100644 --- a/src/main.c +++ b/src/main.c @@ -29,6 +29,7 @@ enum { OPT_BUTTONS = (1 << 4), OPT_NO_INDEX = (1 << 5), OPT_INDEX = (1 << 6), + OPT_WIDE_INC = (1 << 7), }; enum { @@ -388,7 +389,8 @@ enter_block(MD_BLOCKTYPE type, void *details, void *ctx_) } } if (!raw_str(ctx, "</head><body>") - || (ctx->doc.oheader && !raw_str(ctx, ctx->sa.s + ctx->doc.oheader)) + || (ctx->doc.oheader && (ctx->options & OPT_WIDE_INC) + && !raw_str(ctx, ctx->sa.s + ctx->doc.oheader)) || !raw_str(ctx, "<main>")) return ERR_PARSER_ENTER_BLOCK; @@ -453,7 +455,9 @@ enter_block(MD_BLOCKTYPE type, void *details, void *ctx_) return ERR_PARSER_ENTER_BLOCK; } - if (!raw_str(ctx, "<section>")) + if (!raw_str(ctx, "<section>") + || (ctx->doc.oheader && !(ctx->options & OPT_WIDE_INC) + && !raw_str(ctx, ctx->sa.s + ctx->doc.oheader))) return ERR_PARSER_ENTER_BLOCK; if (p->nameoff) { @@ -712,8 +716,12 @@ leave_block(MD_BLOCKTYPE type, void *details, void *ctx_) || !escape_text(ctx, ctx->doc.author, strlen(ctx->doc.author)) || !raw_str(ctx, "<br>" "<span class=\"generated\">Generated with qmdoc</span>" - "</footer></section></main>") - || (ctx->doc.ofooter && !raw_str(ctx, ctx->sa.s + ctx->doc.ofooter)) + "</footer>") + || (ctx->doc.ofooter && !(ctx->options & OPT_WIDE_INC) + && !raw_str(ctx, ctx->sa.s + ctx->doc.ofooter)) + || !raw_str(ctx, "</section></main>") + || (ctx->doc.ofooter && (ctx->options & OPT_WIDE_INC) + && !raw_str(ctx, ctx->sa.s + ctx->doc.ofooter)) || !raw_str(ctx, "</body></html>")) return ERR_PARSER_LEAVE_BLOCK; break; @@ -1416,6 +1424,7 @@ help(void) " -s, --subtitle TEXT Set TEXT as general subtitle\n" " -T, --no-toc Don't write a TOC on each page. Implies --no-index\n" " -t, --title TITLE Set TITLE as general (across all pages) title\n" + " -W, --wide-include Include header/footer right within <body>\n" " -X, --no-index Disable index mode\n" ); } @@ -1466,10 +1475,11 @@ main (int argc, char *argv[]) { "subtitle", required_argument, NULL, 's' }, { "no-toc", no_argument, NULL, 'T' }, { "title", required_argument, NULL, 't' }, + { "wide-includes", no_argument, NULL, 'W' }, { "no-index", no_argument, NULL, 'X' }, { NULL, 0, NULL, 0 }, }; - while ((c = getopt_long(argc, argv, "a:bCc:d:F:H:hIil:M:os:Tt:X", opts, NULL)) != -1) switch (c) { + while ((c = getopt_long(argc, argv, "a:bCc:d:F:H:hIil:M:os:Tt:WX", opts, NULL)) != -1) switch (c) { case 'a': ctx.doc.author = optarg; break; @@ -1517,6 +1527,9 @@ main (int argc, char *argv[]) case 't': ctx.doc.title = optarg; break; + case 'W': + ctx.options |= OPT_WIDE_INC; + break; case 'X': ctx.options |= OPT_NO_INDEX; break;