Welcome to little lamb

Code » qmdoc » commit 35bc567

Add an extra CSS file, no-toc.css, when --no-toc

author Olivier Brunel
2023-01-02 13:17:23 UTC
committer Olivier Brunel
2023-01-04 15:10:17 UTC
parent 235a1a65c5b54336badd90ac4057ef9f9c9544d2

Add an extra CSS file, no-toc.css, when --no-toc

When using --no-toc the content of the page remains offset to the left,
as if the TOC was there, which is probably not wasn't wanted.
So, we just add a tiny CSS that will take care of that.

main.c +6 -1
no-toc.css +4 -0

diff --git a/main.c b/main.c
index aa23cec..dd0cf8e 100644
--- a/main.c
+++ b/main.c
@@ -37,13 +37,16 @@ enum {
 enum {
     CSS_QMDOC,
     CSS_CUSTOM,
+    CSS_NO_TOC,
     NB_CSS
 };
 static struct css {
     const char *file;
     size_t offset;
 } css[NB_CSS] = {
-    { "qmdoc.css" }
+    { "qmdoc.css" },
+    { NULL },
+    { "no-toc.css" }
 };
 
 struct page {
@@ -1176,6 +1179,8 @@ main (int argc, char *argv[])
     int fddest = open(destdir, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
     if (fddest < 0) strerr_diefu3sys(-ERR_IO, "open '", destdir, "'");
 
+    if (!(ctx.options & OPT_NO_TOC)) css[CSS_NO_TOC].file = NULL;
+
     struct page pages[argc - optind];
     ctx.pages = pages;
     ctx.nb_pages = sizeof(pages) / sizeof(*pages);
diff --git a/no-toc.css b/no-toc.css
new file mode 100644
index 0000000..aa391df
--- /dev/null
+++ b/no-toc.css
@@ -0,0 +1,4 @@
+main > section {
+    position: inherit;
+    margin-left: inherit;
+}