author | Olivier Brunel
<jjk@jjacky.com> 2023-01-02 11:31:05 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2023-01-04 15:10:17 UTC |
parent | 748e0ceab26f7b4b89dfb09e4f99ac164391d2a9 |
main.c | +15 | -9 |
diff --git a/main.c b/main.c index 90d5601..ef3e7ea 100644 --- a/main.c +++ b/main.c @@ -312,18 +312,19 @@ enter_block(MD_BLOCKTYPE type, void *details, void *ctx_) ( !raw_str(ctx, "<style>") || !raw_str(ctx, ctx->sa.s + ctx->css[i].offset) - || !raw_str(ctx, "</style>")) - ) + || !raw_str(ctx, "</style>") + )) return ERR_PARSER_ENTER_BLOCK; } - } else if (!(ctx->options & OPT_NO_CSS)) { + } else { for (int i = 0; i < 2; ++i) { - if (ctx->css[i].file && + if ((i == 1 || !(ctx->options & OPT_NO_CSS)) + && ctx->css[i].file && ( !raw_str(ctx, "<link rel=\"stylesheet\" href=\"") || !escape_text(ctx, ctx->css[i].file, strlen(ctx->css[i].file)) - || !raw_str(ctx, "\">")) - ) + || !raw_str(ctx, "\">") + )) return ERR_PARSER_ENTER_BLOCK; } } @@ -1054,7 +1055,8 @@ static void help(void) { outh(" -a, --author AUTHOR Set AUTHOR as author (in meta in footer)\n" - " -C, --no-css Do not use CSS\n" + " -C, --no-css Do not use CSS (still process --css if any)\n" + " -c, --css FILE Add FILE as additional CSS\n" " -d, --destdir DIR Write files into DIR\n" " -F, --footer FILE Insert FILE as common footer\n" " -H, --header FILE Insert FILE as common header\n" @@ -1097,6 +1099,7 @@ main (int argc, char *argv[]) struct option opts[] = { { "author", required_argument, NULL, 'a' }, { "no-css", no_argument, NULL, 'C' }, + { "css", required_argument, NULL, 'c' }, { "destdir", required_argument, NULL, 'd' }, { "footer", required_argument, NULL, 'F' }, { "header", required_argument, NULL, 'H' }, @@ -1107,13 +1110,16 @@ main (int argc, char *argv[]) { "title", required_argument, NULL, 't' }, { NULL, 0, NULL, 0 }, }; - while ((c = getopt_long(argc, argv, "a:Cd:F:H:hIl:ot:", opts, NULL)) != -1) switch (c) { + while ((c = getopt_long(argc, argv, "a:Cc:d:F:H:hIl:ot:", opts, NULL)) != -1) switch (c) { case 'a': ctx.doc.author = optarg; break; case 'C': ctx.options |= OPT_NO_CSS; break; + case 'c': + ctx.css[1].file = optarg; + break; case 'd': destdir = optarg; break; @@ -1182,7 +1188,7 @@ main (int argc, char *argv[]) } } - if (!(ctx.options & OPT_NO_CSS)) { + if (!(ctx.options & OPT_NO_CSS) || ctx.css[1].file) { outs((ctx.options & OPT_INLINE_CSS) ? "Loading" : "Copying"); outse(" CSS files..."); for (int i = 0; i < 2; ++i) {