Skip to content

Commit 8dfbea2

Browse files
committed
feat: custom stylesheets
fix #1081
1 parent 0a1cbad commit 8dfbea2

File tree

279 files changed

+22410
-15615
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

279 files changed

+22410
-15615
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@ jobs:
10271027
root="$(pwd)/demos/$project/$variant"
10281028
src="$root/adoc"
10291029
dst="$root/adoc-asciidoc"
1030+
stylesheet="$(pwd)/share/mrdocs/addons/generator/common/layouts/style.css"
10301031
10311032
# Create the top-level output dir
10321033
mkdir -p "$dst"
@@ -1037,7 +1038,7 @@ jobs:
10371038
rel="${f#"$src/"}" # path relative to $src
10381039
outdir="$dst/$(dirname "$rel")" # mirror subdir inside $dst
10391040
mkdir -p "$outdir"
1040-
asciidoctor -D "$outdir" "$f"
1041+
asciidoctor -a stylesheet="${stylesheet}" -D "$outdir" "$f"
10411042
done
10421043
done
10431044
fi

docs/modules/ROOT/pages/generators.adoc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,34 @@ The layout template can include other partial templates to render the symbol dat
111111

112112
The Document Object Model (DOM) for each symbol includes all information about the symbol.One advantage of custom templates over post-processing XML files is the ability to access symbols as a graph.If symbol `A` refers to symbol `B`, some properties of symbol `B` are likely to be required in the documentation of `A`.All templates and generators can access a reference to `B` by searching the symbol tree or simply by accessing the elements `A` refers to.All references to other symbols are resolved in the templates.
113113

114+
== Stylesheet Options
115+
116+
The HTML and AsciiDoc generators ship a bundled stylesheet that is inlined by default. You can replace or layer styles with the following options (available in config files and on the CLI):
117+
118+
- `stylesheets`: ordered list of stylesheet paths or URLs. If empty, the bundled CSS is used. Remote URLs require `linkcss: true`.
119+
- `no-default-styles`: skip the bundled CSS entirely.
120+
- `linkcss`: emit `<link>` tags instead of inline `<style>` blocks. Local styles are copied by default; remote URLs are only linked.
121+
- `copycss`: when linking, copy bundled and local styles into the output tree (default `true`). Set to `false` to skip copying.
122+
- `stylesdir`: directory (relative to the output root) used for linked styles, e.g. `css` results in `css/custom.css`.
123+
124+
Example config:
125+
126+
[source,yaml]
127+
----
128+
generator: html
129+
stylesheets:
130+
- custom.css
131+
linkcss: true
132+
stylesdir: css
133+
----
134+
135+
Equivalent CLI flags:
136+
137+
[source,shell]
138+
----
139+
mrdocs --generator=html --stylesheets custom.css --linkcss --stylesdir css
140+
----
141+
114142
[#dom_reference]
115143
== Document Object Model Reference
116144

docs/mrdocs.schema.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@
5555
"title": "Path to the compilation database",
5656
"type": "string"
5757
},
58+
"copycss": {
59+
"default": true,
60+
"description": "When `linkcss` is true, copy bundled and local stylesheet files into the output under `stylesdir`. Remote URLs are not copied. Set to false to skip copying.",
61+
"enum": [
62+
true,
63+
false
64+
],
65+
"title": "Copy local stylesheets when linking",
66+
"type": "boolean"
67+
},
5868
"defines": {
5969
"default": [],
6070
"description": "Additional defines passed to the compiler when building the source code. These defines are added to the compilation database regardless of the strategy to generate it.",
@@ -331,6 +341,16 @@
331341
"title": "Standard Library include paths",
332342
"type": "array"
333343
},
344+
"linkcss": {
345+
"default": false,
346+
"description": "When set to true, stylesheets are linked with `<link>` tags instead of being inlined. Links use `stylesdir` plus the stylesheet name (e.g. `css/custom.css`). Local styles are copied unless `copycss` is false; remote URLs are linked as-is.",
347+
"enum": [
348+
true,
349+
false
350+
],
351+
"title": "Link stylesheets instead of embedding them",
352+
"type": "boolean"
353+
},
334354
"log-level": {
335355
"default": "info",
336356
"description": "The reporting level determines the amount of information displayed during the generation of the documentation.",
@@ -372,6 +392,16 @@
372392
"title": "Generate a multipage documentation",
373393
"type": "boolean"
374394
},
395+
"no-default-styles": {
396+
"default": false,
397+
"description": "When set to true, the bundled stylesheet is not applied. Combine with an empty `stylesheets` list to emit no styles at all.",
398+
"enum": [
399+
true,
400+
false
401+
],
402+
"title": "Disable the bundled default stylesheet",
403+
"type": "boolean"
404+
},
375405
"output": {
376406
"default": "<config-dir>/reference-output",
377407
"description": "Multipage generators expect a directory. Single page generators expect a file or a directory where the file will be created. If the directory does not exist, it will be created.",
@@ -541,6 +571,21 @@
541571
"title": "C++ Standard Library include paths",
542572
"type": "array"
543573
},
574+
"stylesdir": {
575+
"default": "css",
576+
"description": "Directory used to build the href for linked stylesheets when `linkcss` is true. Defaults to `css`. The directory is created under the output root when copying local styles (e.g. `css/mrdocs-default.css`).",
577+
"title": "Directory for linked stylesheets",
578+
"type": "string"
579+
},
580+
"stylesheets": {
581+
"default": [],
582+
"description": "Ordered list of stylesheet names or paths. If empty, the bundled stylesheet is used. Entries can be local paths or remote URLs; remote URLs are only linked when `linkcss` is true. Inline mode embeds local styles; link mode emits `<link>` tags for each entry and copies local files.",
583+
"items": {
584+
"type": "string"
585+
},
586+
"title": "Ordered list of stylesheets to apply to HTML output",
587+
"type": "array"
588+
},
544589
"system-includes": {
545590
"default": [],
546591
"description": "System include paths. These paths are used to add directories to the system include search path. The system include search path is used to search for system headers. The system headers are headers that are provided by the system and are not part of the project. The system headers are used to provide the standard library headers and other system headers. The system headers are not part of the project and are not checked for warnings and errors.",

share/mrdocs/addons/generator/adoc/layouts/wrapper.adoc.hbs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,29 @@
1717
{{#if @root.config.multipage }}
1818
[#{{{symbol.anchor}}}]
1919
= {{> symbol/qualified-name-title symbol }}
20-
:relfileprefix: {{{ repeat "../" (count (remove_prefix symbol.url '/') '/') }}}
20+
{{#if page.relfileprefix}}
21+
:relfileprefix: {{{ page.relfileprefix }}}
22+
{{/if}}
2123
{{else}}
2224
= Reference
2325
{{/if}}
2426
:mrdocs:
2527

28+
{{!--
29+
Optional Asciidoctor stylesheet hints.
30+
These are ignored by Antora (it owns the UI bundle), but allow users
31+
who render the .adoc directly with Asciidoctor to select/link custom CSS.
32+
--}}
33+
{{~#if page.stylesheets}}
34+
{{#each page.stylesheets}}
35+
:stylesheet: {{path}}
36+
{{/each}}
37+
{{#if @root.config.stylesdir}}
38+
:stylesdir: {{@root.config.stylesdir}}
39+
{{/if}}
40+
{{#if @root.config.linkcss}}
41+
:linkcss:
42+
{{/if}}
43+
{{~/if}}
2644
{{{contents}}}
2745
{{#>markup/span class="small"}}Created with https://www.mrdocs.com[MrDocs]{{/markup/span}}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* highlight.js Lightfair theme (unmodified) */
2+
pre code.hljs{
3+
display:block;
4+
overflow-x:auto;
5+
padding:1em;
6+
}
7+
code.hljs{
8+
padding:3px 5px;
9+
}
10+
.hljs{
11+
color:#444;
12+
background:#fff;
13+
}
14+
.hljs-name{
15+
color:#01a3a3;
16+
}
17+
.hljs-meta,
18+
.hljs-tag{
19+
color:#789;
20+
}
21+
.hljs-comment{
22+
color:#888;
23+
}
24+
.hljs-attribute,
25+
.hljs-doctag,
26+
.hljs-keyword,
27+
.hljs-meta .hljs-keyword,
28+
.hljs-name,
29+
.hljs-selector-tag{
30+
font-weight:700;
31+
}
32+
.hljs-deletion,
33+
.hljs-number,
34+
.hljs-quote,
35+
.hljs-selector-class,
36+
.hljs-selector-id,
37+
.hljs-string,
38+
.hljs-template-tag,
39+
.hljs-type{
40+
color:#4286f4;
41+
}
42+
.hljs-section,
43+
.hljs-title{
44+
color:#4286f4;
45+
font-weight:700;
46+
}
47+
.hljs-link,
48+
.hljs-regexp,
49+
.hljs-selector-attr,
50+
.hljs-selector-pseudo,
51+
.hljs-symbol,
52+
.hljs-template-variable,
53+
.hljs-variable{
54+
color:#bc6060;
55+
}
56+
.hljs-literal{
57+
color:#62bcbc;
58+
}
59+
.hljs-addition,
60+
.hljs-built_in,
61+
.hljs-bullet,
62+
.hljs-code{
63+
color:#25c6c6;
64+
}
65+
.hljs-meta .hljs-string{
66+
color:#4d99bf;
67+
}
68+
.hljs-emphasis{
69+
font-style:italic;
70+
}
71+
.hljs-strong{
72+
font-weight:700;
73+
}

0 commit comments

Comments
 (0)