|
12 | 12 | # ******************************************************************************* |
13 | 13 | from sphinx.application import Sphinx |
14 | 14 |
|
| 15 | +from src.helper_lib import config_setdefault |
| 16 | + |
15 | 17 | # Note: order matters! |
16 | 18 | # Extensions are loaded in this order. |
17 | 19 | # e.g. plantuml MUST be loaded before sphinx-needs |
|
33 | 35 |
|
34 | 36 |
|
35 | 37 | def setup(app: Sphinx) -> dict[str, object]: |
36 | | - app.config.html_copy_source = False |
37 | | - app.config.html_show_sourcelink = False |
| 38 | + config_setdefault(app.config, "html_copy_source", False) |
| 39 | + config_setdefault(app.config, "html_show_sourcelink", False) |
38 | 40 |
|
39 | 41 | # Global settings |
40 | 42 | # Note: the "sub-extensions" also set their own config values |
41 | 43 |
|
42 | 44 | # Same as current VS Code extension |
43 | | - app.config.mermaid_version = "11.6.0" |
44 | | - |
45 | | - # enable "..."-syntax in markdown |
46 | | - app.config.myst_enable_extensions = ["colon_fence"] |
| 45 | + config_setdefault(app.config, "mermaid_version", "11.6.0") |
47 | 46 |
|
48 | | - app.config.exclude_patterns = [ |
49 | | - # The following entries are not required when building the documentation via |
50 | | - # 'bazel build //:docs', as that command runs in a sandboxed environment. |
51 | | - # However, when building the documentation via 'bazel run //:docs' or esbonio, |
52 | | - # these entries are required to prevent the build from failing. |
53 | | - "bazel-*", |
54 | | - ".venv*", |
55 | | - ] |
| 47 | + # The following entries are not required when building the documentation via |
| 48 | + # 'bazel build //:docs', as that command runs in a sandboxed environment. |
| 49 | + # However, when building the documentation via 'bazel run //:docs' or esbonio, |
| 50 | + # these entries are required to prevent the build from failing. |
| 51 | + app.config.exclude_patterns += ["bazel-*", ".venv*"] |
56 | 52 |
|
57 | 53 | # Enable markdown rendering |
58 | | - app.config.source_suffix = { |
59 | | - ".rst": "restructuredtext", |
60 | | - ".md": "markdown", |
61 | | - } |
| 54 | + app.config.source_suffix.setdefault(".rst", "restructuredtext") |
| 55 | + app.config.source_suffix.setdefault(".md", "markdown") |
62 | 56 |
|
63 | | - app.config.templates_path = ["templates"] |
| 57 | + if "templates" not in app.config.templates_path: |
| 58 | + app.config.templates_path += ["templates"] |
64 | 59 |
|
65 | | - app.config.numfig = True |
66 | | - |
67 | | - app.config.author = "S-CORE" |
| 60 | + config_setdefault(app.config, "numfig", True) |
| 61 | + config_setdefault(app.config, "author", "S-CORE") |
68 | 62 |
|
69 | 63 | # Load the actual extensions list |
70 | 64 | for e in score_extensions: |
71 | 65 | app.setup_extension(e) |
72 | 66 |
|
| 67 | + # enable "..."-syntax in markdown — must come after myst_parser is loaded above |
| 68 | + if isinstance(app.config.myst_enable_extensions, list): |
| 69 | + app.config.myst_enable_extensions.append("colon_fence") |
| 70 | + elif isinstance(app.config.myst_enable_extensions, set): |
| 71 | + app.config.myst_enable_extensions.add("colon_fence") |
| 72 | + else: |
| 73 | + print( |
| 74 | + "Unexpected type for myst_enable_extensions: %s", |
| 75 | + type(app.config.myst_enable_extensions), |
| 76 | + ) |
| 77 | + |
73 | 78 | return { |
74 | 79 | "version": "3.0.0", |
75 | 80 | # Keep this in sync with the score_docs_as_code version in MODULE.bazel |
|
0 commit comments