Welcome to little lamb

Code » qmdoc » commit a52a180

Add -l/--lang to set language in <html>

author Olivier Brunel
2022-12-29 19:40:17 UTC
committer Olivier Brunel
2022-12-29 19:40:17 UTC
parent cbed7e2d62a95bed6731b07f4d0e539c42805bea

Add -l/--lang to set language in <html>

main.c +12 -2

diff --git a/main.c b/main.c
index e014a06..dcb0a06 100644
--- a/main.c
+++ b/main.c
@@ -74,6 +74,7 @@ struct ctx {
     struct {
         const char *title;
         const char *author;
+        const char *lang;
         int flags;
     } doc;
     struct {
@@ -299,7 +300,9 @@ enter_block(MD_BLOCKTYPE type, void *details, void *ctx_)
 #define str_title(i)    ctx->sa.s + ctx->pages[i].titleoff
 #define str_file(i)    ctx->sa.s + ctx->pages[i].fileoff
                 size_t authlen = strlen(ctx->doc.author);
-                if (!raw_str(ctx, "<!DOCTYPE html>\n<html><head>")
+                if (!raw_str(ctx, "<!DOCTYPE html>\n<html lang=\"")
+                        || !escape_text(ctx, ctx->doc.lang, strlen(ctx->doc.lang))
+                        || !raw_str(ctx, "\"><head>")
                         || !raw_str(ctx, metas)
                         || (authlen && (!raw_str(ctx, "<meta name=\"author\" content=\"")
                                         || !escape_text(ctx, ctx->doc.author, authlen)
@@ -1004,6 +1007,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"
+         " -l, --lang LNG               Set LNG as language attribute\n"
          " -t, --title TITLE            Set TITLE as general (across all pages) title\n"
         );
 }
@@ -1025,6 +1029,7 @@ main (int argc, char *argv[])
     char *destdir = ".";
     const char *title = "Documentation";
     const char *author = "";
+    const char *lang = "en";
 
     int c;
     struct option opts[] = {
@@ -1033,10 +1038,11 @@ main (int argc, char *argv[])
         { "destdir",        required_argument,  NULL,   'd' },
         { "help",           no_argument,        NULL,   'h' },
         { "inline-css",     no_argument,        NULL,   'I' },
+        { "lang",           no_argument,        NULL,   'l' },
         { "title",          required_argument,  NULL,   't' },
         { NULL,             0,                  NULL,    0  },
     };
-    while ((c = getopt_long(argc, argv, "a:Cd:hIt:", opts, NULL)) != -1) switch (c) {
+    while ((c = getopt_long(argc, argv, "a:Cd:hIl:t:", opts, NULL)) != -1) switch (c) {
         case 'a':
             author = optarg;
             break;
@@ -1051,6 +1057,9 @@ main (int argc, char *argv[])
         case 'I':
             options |= OPT_INLINE_CSS;
             break;
+        case 'l':
+            lang = optarg;
+            break;
         case 't':
             title = optarg;
             break;
@@ -1074,6 +1083,7 @@ main (int argc, char *argv[])
         .nb_pages = sizeof(pages) / sizeof(*pages),
         .doc.title = title,
         .doc.author = author,
+        .doc.lang = lang,
         .buf.sa = STRALLOC_ZERO,
     };