Welcome to little lamb

Code » qmdoc » commit c724f41

Add -t/--title for overall title

author Olivier Brunel
2022-12-27 19:19:50 UTC
committer Olivier Brunel
2022-12-27 20:49:34 UTC
parent f6f196c49ed9c6b6c48dcd67f6fa9cc206c469a4

Add -t/--title for overall title

That is, this title is featured on the left (above TOC) on every page.

main.c +13 -3

diff --git a/main.c b/main.c
index 7020258..72ead33 100644
--- a/main.c
+++ b/main.c
@@ -72,6 +72,7 @@ struct ctx {
     struct page *pages;
     int nb_pages;
     int cur_page;
+    const char *title;
     struct {
         int flags;
         int from;
@@ -280,8 +281,10 @@ enter_block(MD_BLOCKTYPE type, void *details, void *ctx_)
                         return ERR_PARSER_ENTER_BLOCK;
                     }
                 }
-                if (!raw_str(ctx, "</head><body><header><nav><ul>"))
-                        return ERR_PARSER_ENTER_BLOCK;
+                if (!raw_str(ctx, "</head><body><header><section><h1>")
+                        || !escape_text(ctx, ctx->title, strlen(ctx->title))
+                        || !raw_str(ctx, "</h1></section><nav><ul>"))
+                    return ERR_PARSER_ENTER_BLOCK;
 
                 for (int i = 0; i < ctx->nb_pages; ++i) {
                     if (!raw_str(ctx, "<li><a href=\"")
@@ -908,6 +911,7 @@ help(void)
          " -d, --destdir DIR            Write files into DIR\n"
          " -h, --help                   Show this help screen and exit\n"
          " -I, --inline-css             Use inline CSS instead of external files\n"
+         " -t, --title TITLE            Set TITLE as general (across all pages) title\n"
         );
 }
 
@@ -926,6 +930,7 @@ main (int argc, char *argv[])
 
     int options = 0;
     char *destdir = ".";
+    const char *title = "Documentation";
 
     int c;
     struct option opts[] = {
@@ -933,9 +938,10 @@ main (int argc, char *argv[])
         { "destdir",        required_argument,  NULL,   'd' },
         { "help",           no_argument,        NULL,   'h' },
         { "inline-css",     no_argument,        NULL,   'I' },
+        { "title",          required_argument,  NULL,   't' },
         { NULL,             0,                  NULL,    0  },
     };
-    while ((c = getopt_long(argc, argv, "Cd:hI", opts, NULL)) != -1) switch (c) {
+    while ((c = getopt_long(argc, argv, "Cd:hIt:", opts, NULL)) != -1) switch (c) {
         case 'C':
             options |= OPT_NO_CSS;
             break;
@@ -947,6 +953,9 @@ main (int argc, char *argv[])
         case 'I':
             options |= OPT_INLINE_CSS;
             break;
+        case 't':
+            title = optarg;
+            break;
         case '?':
             usage(1);
     }
@@ -965,6 +974,7 @@ main (int argc, char *argv[])
         .css = css,
         .pages = pages,
         .nb_pages = sizeof(pages) / sizeof(*pages),
+        .title = title,
         .buf.sa = STRALLOC_ZERO,
     };