Welcome to little lamb

Code » qmdoc » commit 6e1e02b

Add -s/--subtitle

author Olivier Brunel
2023-01-04 13:40:54 UTC
committer Olivier Brunel
2023-01-04 15:10:17 UTC
parent f538cd5b67969a31cd1a57adb0865e8f760b2e85

Add -s/--subtitle

main.c +15 -2

diff --git a/main.c b/main.c
index 3ce65a4..abf1355 100644
--- a/main.c
+++ b/main.c
@@ -79,6 +79,7 @@ struct ctx {
     int cur_page;
     struct {
         const char *title;
+        const char *subtitle;
         const char *author;
         const char *lang;
         size_t oheader;
@@ -352,7 +353,13 @@ enter_block(MD_BLOCKTYPE type, void *details, void *ctx_)
                 if (!(ctx->options & OPT_NO_TOC)) {
                     if (!raw_str(ctx, "<header><section><h1>")
                         || !escape_text(ctx, ctx->doc.title, strlen(ctx->doc.title))
-                        || !raw_str(ctx, "</h1></section><nav><ul>"))
+                        || !raw_str(ctx, "</h1>")
+                        || (ctx->doc.subtitle && (!raw_str(ctx, "<h2>")
+                                                  || !escape_text(ctx,
+                                                                  ctx->doc.subtitle,
+                                                                  strlen(ctx->doc.subtitle)))
+                            )
+                        || !raw_str(ctx, "</section><nav><ul>"))
                         return ERR_PARSER_ENTER_BLOCK;
 
                     for (int i = 0; i < ctx->nb_pages; ++i) {
@@ -1180,6 +1187,7 @@ help(void)
          " -i, --index                  Force index mode\n"
          " -l, --lang LNG               Set LNG as language attribute\n"
          " -o, --overwrite              Overwrite destination files if already exist\n"
+         " -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"
          " -X, --no-index               Disable index mode\n"
@@ -1208,6 +1216,7 @@ main (int argc, char *argv[])
         .sa_out = STRALLOC_ZERO,
         .css = css,
         .doc.title = "Documentation",
+        .doc.subtitle = NULL,
         .doc.author = "",
         .doc.lang = "en",
         .buf.sa = STRALLOC_ZERO,
@@ -1227,12 +1236,13 @@ main (int argc, char *argv[])
         { "index",          no_argument,        NULL,   'i' },
         { "lang",           no_argument,        NULL,   'l' },
         { "overwrite",      no_argument,        NULL,   'o' },
+        { "subtitle",       required_argument,  NULL,   's' },
         { "no-toc",         no_argument,        NULL,   'T' },
         { "title",          required_argument,  NULL,   't' },
         { "no-index",       no_argument,        NULL,   'X' },
         { NULL,             0,                  NULL,    0  },
     };
-    while ((c = getopt_long(argc, argv, "a:bCc:d:F:H:hIil:oTt:X", opts, NULL)) != -1) switch (c) {
+    while ((c = getopt_long(argc, argv, "a:bCc:d:F:H:hIil:os:Tt:X", opts, NULL)) != -1) switch (c) {
         case 'a':
             ctx.doc.author = optarg;
             break;
@@ -1268,6 +1278,9 @@ main (int argc, char *argv[])
         case 'o':
             ctx.options |= OPT_OVERWRITE;
             break;
+        case 's':
+            ctx.doc.subtitle = optarg;
+            break;
         case 'T':
             ctx.options |= OPT_NO_TOC | OPT_NO_INDEX;
             break;