|
4 | 4 | # list see the documentation: |
5 | 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html |
6 | 6 |
|
| 7 | +import hashlib |
7 | 8 | from datetime import date |
| 9 | +from pathlib import Path |
8 | 10 |
|
9 | 11 | from sphinx.application import Sphinx |
10 | | -from sphinx.transforms.post_transforms import SphinxPostTransform |
11 | 12 |
|
12 | 13 | from myst_parser import __version__ |
13 | 14 |
|
|
32 | 33 | "sphinx.ext.intersphinx", |
33 | 34 | "sphinx.ext.viewcode", |
34 | 35 | "sphinx.ext.autodoc", |
| 36 | + "sphinx.ext.autosummary", |
35 | 37 | "sphinx_design", |
36 | 38 | "sphinx_copybutton", |
37 | 39 | "sphinxext.rediraffe", |
|
40 | 42 | "sphinxext.opengraph", |
41 | 43 | "sphinx_pyscript", |
42 | 44 | "sphinx_tippy", |
| 45 | + "sphinx_togglebutton", |
43 | 46 | ] |
44 | 47 |
|
45 | 48 | # Add any paths that contain templates here, relative to this directory. |
|
61 | 64 | # -- Autodoc settings --------------------------------------------------- |
62 | 65 |
|
63 | 66 | autodoc2_packages = ["../myst_parser"] |
| 67 | +autodoc2_exclude_files = ["_docs.py"] |
64 | 68 | autodoc2_hidden_objects = ["dunder", "private", "inherited"] |
65 | 69 | autodoc2_replace_annotations = [ |
66 | 70 | ("re.Pattern", "typing.Pattern"), |
|
71 | 75 | ("myst_parser._compat.TypedDict", "typing.TypedDict"), |
72 | 76 | ("sphinx.directives.SphinxDirective", "sphinx.util.docutils.SphinxDirective"), |
73 | 77 | ] |
| 78 | +autodoc2_docstring_parser_regexes = [ |
| 79 | + ("myst_parser", "myst"), |
| 80 | + (r"myst_parser\.setup", "myst"), |
| 81 | +] |
74 | 82 | nitpicky = True |
75 | 83 | nitpick_ignore_regex = [ |
76 | 84 | (r"py:.*", r"docutils\..*"), |
| 85 | + (r"py:.*", r"pygments\..*"), |
77 | 86 | ] |
78 | 87 | nitpick_ignore = [ |
79 | 88 | ("py:obj", "myst_parser._docs._ConfigBase"), |
|
101 | 110 | "tasklist", |
102 | 111 | "attrs_inline", |
103 | 112 | "attrs_block", |
104 | | - "inv_link", |
105 | 113 | ] |
106 | 114 | myst_url_schemes = { |
107 | 115 | "http": None, |
|
131 | 139 | myst_footnote_transition = True |
132 | 140 | myst_dmath_double_inline = True |
133 | 141 | myst_enable_checkboxes = True |
| 142 | +myst_substitutions = { |
| 143 | + "role": "[role](#syntax/roles)", |
| 144 | + "directive": "[directive](#syntax/directives)", |
| 145 | +} |
134 | 146 |
|
135 | 147 | # -- HTML output ------------------------------------------------- |
136 | 148 |
|
|
146 | 158 | "path_to_docs": "docs", |
147 | 159 | "use_repository_button": True, |
148 | 160 | "use_edit_page_button": True, |
| 161 | + "use_issues_button": True, |
149 | 162 | } |
150 | 163 | # OpenGraph metadata |
151 | 164 | ogp_site_url = "https://myst-parser.readthedocs.io/en/latest" |
|
163 | 176 |
|
164 | 177 | rediraffe_redirects = { |
165 | 178 | "using/intro.md": "sphinx/intro.md", |
| 179 | + "syntax/syntax.md": "syntax/typography.md", |
166 | 180 | "sphinx/intro.md": "intro.md", |
167 | 181 | "using/use_api.md": "api/index.md", |
168 | 182 | "api/index.md": "api/reference.rst", |
|
191 | 205 | # -- Local Sphinx extensions ------------------------------------------------- |
192 | 206 |
|
193 | 207 |
|
194 | | -class StripUnsupportedLatex(SphinxPostTransform): |
195 | | - """Remove unsupported nodes from the doctree.""" |
196 | | - |
197 | | - default_priority = 900 |
198 | | - |
199 | | - def run(self): |
200 | | - if self.app.builder.format != "latex": |
201 | | - return |
202 | | - from docutils import nodes |
203 | | - |
204 | | - for node in self.document.findall(): |
205 | | - if node.tagname == "image" and node["uri"].endswith(".svg"): |
206 | | - node.parent.replace(node, nodes.inline("", "Removed SVG image")) |
207 | | - if node.tagname == "mermaid": |
208 | | - node.parent.replace(node, nodes.inline("", "Removed Mermaid diagram")) |
209 | | - |
210 | | - |
211 | 208 | def setup(app: Sphinx): |
212 | 209 | """Add functions to the Sphinx setup.""" |
213 | 210 | from myst_parser._docs import ( |
214 | 211 | DirectiveDoc, |
215 | 212 | DocutilsCliHelpDirective, |
| 213 | + MystAdmonitionDirective, |
216 | 214 | MystConfigDirective, |
217 | 215 | MystExampleDirective, |
| 216 | + MystLexer, |
| 217 | + MystToHTMLDirective, |
218 | 218 | MystWarningsDirective, |
| 219 | + NumberSections, |
| 220 | + StripUnsupportedLatex, |
219 | 221 | ) |
220 | 222 |
|
221 | 223 | app.add_directive("myst-config", MystConfigDirective) |
222 | 224 | app.add_directive("docutils-cli-help", DocutilsCliHelpDirective) |
223 | 225 | app.add_directive("doc-directive", DirectiveDoc) |
224 | 226 | app.add_directive("myst-warnings", MystWarningsDirective) |
225 | 227 | app.add_directive("myst-example", MystExampleDirective) |
| 228 | + app.add_directive("myst-admonitions", MystAdmonitionDirective) |
| 229 | + app.add_directive("myst-to-html", MystToHTMLDirective) |
226 | 230 | app.add_post_transform(StripUnsupportedLatex) |
| 231 | + app.add_post_transform(NumberSections) |
227 | 232 | app.connect("html-page-context", add_version_to_css) |
| 233 | + app.add_lexer("myst", MystLexer) |
228 | 234 |
|
229 | 235 |
|
230 | | -def add_version_to_css(app, pagename, templatename, context, doctree): |
| 236 | +def add_version_to_css(app: Sphinx, pagename, templatename, context, doctree): |
231 | 237 | """Add the version number to the local.css file, to bust the cache for changes.""" |
232 | 238 | if app.builder.name != "html": |
233 | 239 | return |
234 | 240 | if "_static/local.css" in context.get("css_files", {}): |
| 241 | + css = Path(app.srcdir, "_static/local.css").read_text("utf8") |
| 242 | + hashed = hashlib.sha256(css.encode("utf-8")).hexdigest() |
235 | 243 | index = context["css_files"].index("_static/local.css") |
236 | | - context["css_files"][index] = f"_static/local.css?v={__version__}" |
| 244 | + context["css_files"][index] = f"_static/local.css?hash={hashed}" |
0 commit comments