author | Olivier Brunel
<jjk@jjacky.com> 2023-01-02 11:27:05 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2023-01-04 15:10:17 UTC |
parent | 2fb48924d3c5aaf7a25b735a55729363bc3c8b54 |
Makefile | +7 | -2 |
main.c | +18 | -21 |
diff --git a/Makefile b/Makefile index 25d1422..be08377 100644 --- a/Makefile +++ b/Makefile @@ -2,13 +2,18 @@ SRCS = main.c md4c.c OBJS = $(SRCS:.c=.o) DEPS = $(SRCS:.c=.d) -CFLAGS = -g -O3 -Wall -I./limb/include +CSS = struct.css common.css light.css dark.css + +#CFLAGS = -g -O3 -Wall -I./limb/include LDFLAGS = -L./limb -llimb -L/lib/skalibs -lskarnet -all: qmdoc +all: qmdoc qmdoc.css qmdoc: $(OBJS) $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $@ +qmdoc.css: $(CSS) + cat $(CSS) > $@ + -include $(DEPS) %.o: %.c Makefile diff --git a/main.c b/main.c index b94596b..90d5601 100644 --- a/main.c +++ b/main.c @@ -33,21 +33,11 @@ enum { CODE_BUFFERED = (CODE_LINES | CODE_HIGHLIGHT), }; -enum { - CSS_STRUCT, - CSS_COMMON, - CSS_LIGHT, - CSS_DARK, - NB_CSS -}; static struct css { const char *file; size_t offset; -} css[NB_CSS] = { - { "struct.css" }, - { "common.css" }, - { "light.css" }, - { "dark.css" } +} css[2] = { + { "qmdoc.css" } }; struct page { @@ -317,17 +307,23 @@ enter_block(MD_BLOCKTYPE type, void *details, void *ctx_) || !raw_str(ctx, "</title>")) return ERR_PARSER_ENTER_BLOCK; if (ctx->options & OPT_INLINE_CSS) { - for (int i = 0; i < NB_CSS; ++i) { - if (!raw_str(ctx, "<style>") - || !raw_str(ctx, ctx->sa.s + ctx->css[i].offset) - || !raw_str(ctx, "</style>")) + for (int i = 0; i < 2; ++i) { + if (ctx->css[i].file && + ( + !raw_str(ctx, "<style>") + || !raw_str(ctx, ctx->sa.s + ctx->css[i].offset) + || !raw_str(ctx, "</style>")) + ) return ERR_PARSER_ENTER_BLOCK; } } else if (!(ctx->options & OPT_NO_CSS)) { - for (int i = 0; i < NB_CSS; ++i) { - if (!raw_str(ctx, "<link rel=\"stylesheet\" href=\"") - || !escape_text(ctx, ctx->css[i].file, strlen(ctx->css[i].file)) - || !raw_str(ctx, "\">")) + for (int i = 0; i < 2; ++i) { + if (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, "\">")) + ) return ERR_PARSER_ENTER_BLOCK; } } @@ -1189,7 +1185,8 @@ main (int argc, char *argv[]) if (!(ctx.options & OPT_NO_CSS)) { outs((ctx.options & OPT_INLINE_CSS) ? "Loading" : "Copying"); outse(" CSS files..."); - for (int i = 0; i < NB_CSS; ++i) { + for (int i = 0; i < 2; ++i) { + if (!css[i].file) continue; if (ctx.options & OPT_INLINE_CSS) { css[i].offset = ctx.sa.len; if (!openreadfileclose(css[i].file, &ctx.sa, 0)