40
40
import sys
41
41
import os
42
42
from urllib .parse import quote
43
- import re
44
-
45
-
46
- def _validate_git_ref (ref : str ) -> str :
47
- """
48
- Validate if the provided string is a valid Git reference.
49
-
50
- Args:
51
- ref (str) -- The Git reference to validate.
52
-
53
- Returns:
54
- str -- The validated Git reference.
55
-
56
- Raises:
57
- ValueError -- If the reference contains invalid characters.
58
-
59
- Meta-Testing:
60
-
61
- Testcase 1: Valid reference.
62
-
63
- >>> _validate_git_ref('main')
64
- 'main'
65
-
66
- Testcase 2: Valid reference with special characters.
67
-
68
- >>> _validate_git_ref('feature/new-feature')
69
- 'feature/new-feature'
70
-
71
- Testcase 3: Invalid reference with disallowed characters.
72
-
73
- >>> _validate_git_ref('invalid$ref') #doctest: +IGNORE_EXCEPTION_DETAIL +ELLIPSIS
74
- Traceback (most recent call last):
75
- ...
76
- ValueError: Invalid Git reference: invalid$ref
77
-
78
- Testcase 4: Empty reference.
79
-
80
- >>> _validate_git_ref('') #doctest: +IGNORE_EXCEPTION_DETAIL +ELLIPSIS
81
- Traceback (most recent call last):
82
- ...
83
- ValueError: Invalid Git reference:...
84
- """
85
- if not re .match (r'^[a-zA-Z0-9_\-./]+$' , ref ):
86
- raise ValueError (f"Invalid Git reference: { ref } " )
87
- return ref
88
43
44
+ # If extensions (or modules to document with autodoc) are in another directory,
45
+ # add these directories to sys.path here. If the directory is relative to the
46
+ # documentation root, use os.path.abspath to make it absolute, like shown here.
47
+ sys .path .insert (0 , os .path .abspath ("""..""" ))
48
+ from docs .utils import _validate_git_ref
49
+ from docs .utils import slugify_header
89
50
90
51
# Define the branch reference for linkcode_resolve
91
52
DOCS_BUILD_REF : str = _validate_git_ref (os .environ .get ("DOCS_BUILD_REF" , "stable" ))
@@ -98,10 +59,6 @@ def _validate_git_ref(ref: str) -> str:
98
59
variable is not set.
99
60
"""
100
61
101
- # If extensions (or modules to document with autodoc) are in another directory,
102
- # add these directories to sys.path here. If the directory is relative to the
103
- # documentation root, use os.path.abspath to make it absolute, like shown here.
104
- sys .path .insert (0 , os .path .abspath ("""..""" ))
105
62
sys .path .insert (1 , os .path .abspath ("""multicast""" ))
106
63
sys .path .insert (1 , os .path .abspath ("""tests""" ))
107
64
@@ -116,7 +73,7 @@ def _validate_git_ref(ref: str) -> str:
116
73
# for rst use 'sphinx.ext.autodoc'
117
74
extensions = [
118
75
"""sphinx.ext.napoleon""" , """autodoc2""" , """sphinx.ext.autosectionlabel""" ,
119
- """sphinx.ext.githubpages""" , """myst_parser""" ,
76
+ """sphinx.ext.githubpages""" , """myst_parser""" , """sphinx_design""" ,
120
77
"""sphinx.ext.autosummary""" , """sphinx.ext.doctest""" , """sphinx.ext.todo""" ,
121
78
"""sphinx.ext.linkcode""" , """sphinx.ext.viewcode""" , """sphinx.ext.intersphinx""" ,
122
79
]
@@ -321,19 +278,46 @@ def _validate_git_ref(ref: str) -> str:
321
278
# see https://myst-parser.readthedocs.io/en/latest/syntax/roles-and-directives.html
322
279
323
280
# be more like GFM with style
324
- myst_enable_extensions = ("tasklist" , "strikethrough" , "fieldlist" )
281
+ myst_enable_extensions = ("tasklist" , "strikethrough" , "fieldlist" , "linkify" )
325
282
326
283
# for GFM diagrams and interoperability with other Markdown renderers
327
284
myst_fence_as_directive = ("mermaid" , "suggestion" , "note" )
328
285
286
+ # Add linkify configuration
287
+ myst_linkify_fuzzy_links = False
288
+
329
289
# Focus only on github markdown
330
- # myst_gfm_only = True
290
+ myst_gfm_only = True
291
+
292
+ myst_html_meta = {
293
+ "github_url" : f"https://github.com/reactive-firewall/{ project } "
294
+ }
295
+
296
+ # For GH-style admonitions to MyST conversion
297
+ myst_admonition_aliases = {
298
+ "note" : "note" ,
299
+ "warning" : "warning" ,
300
+ "important" : "important" ,
301
+ "tip" : "tip" ,
302
+ "caution" : "caution"
303
+ }
331
304
332
305
# how deep should markdown headers have anchors be generated
333
306
heading_anchors = 3
334
307
308
+ # Enable header anchors as requested
309
+ myst_heading_anchors = 3
310
+
311
+ # For better slug generation in header references
312
+ myst_heading_slug_func = slugify_header
313
+
335
314
# -- Options for napoleon ext --------------------------------------------------
336
315
316
+ napoleon_google_docstring = True
317
+ napoleon_numpy_docstring = False
318
+ napoleon_include_private_with_doc = False
319
+ napoleon_include_special_with_doc = False
320
+
337
321
# include __init__ when it has docstrings
338
322
napoleon_include_init_with_doc = True
339
323
@@ -432,9 +416,7 @@ def _validate_git_ref(ref: str) -> str:
432
416
433
417
# -- Link resolver -------------------------------------------------------------
434
418
435
- linkcode_url_prefix : str = str (
436
- """https://github.com/reactive-firewall/{proj}"""
437
- ).format (proj = project )
419
+ linkcode_url_prefix : str = f"https://github.com/reactive-firewall/{ project } "
438
420
439
421
extlinks = {
440
422
"""issue""" : (
0 commit comments