4
4
5
5
import argparse
6
6
from functools import partial
7
- from typing import Mapping
7
+ from typing import Any , Mapping
8
8
9
9
from markdown_it import MarkdownIt
10
10
from mdformat .renderer import DEFAULT_RENDERERS , RenderContext , RenderTreeNode
25
25
pymd_abbreviations_plugin ,
26
26
)
27
27
28
- _IGNORE_MISSING_REFERENCES = None
29
- """user-specified flag to turn off bracket escaping when no link reference found.
28
+ ContextOptions = Mapping [str , Any ]
30
29
31
- Addresses: https://github.com/KyleKing/mdformat-mkdocs/issues/19
32
30
33
- """
31
+ def cli_is_ignore_missing_references (options : ContextOptions ) -> bool :
32
+ """user-specified flag to turn off bracket escaping when no link reference found.
34
33
35
- _ALIGN_SEMANTIC_BREAKS_IN_LISTS = None
36
- """user-specified flag for toggling semantic breaks.
34
+ Addresses: https://github.com/KyleKing/mdformat-mkdocs/issues/19
37
35
38
- - 3-spaces on subsequent lines in semantic numbered lists
39
- - and 2-spaces on subsequent bulleted items
36
+ """
37
+ return options ["mdformat" ].get ("ignore_missing_references" , False )
38
+
39
+
40
+ def cli_is_align_semantic_breaks_in_lists (options : ContextOptions ) -> bool :
41
+ """user-specified flag for toggling semantic breaks.
40
42
41
- """
43
+ - 3-spaces on subsequent lines in semantic numbered lists
44
+ - and 2-spaces on subsequent bulleted items
45
+
46
+ """
47
+ return options ["mdformat" ].get ("align_semantic_breaks_in_lists" , False )
42
48
43
49
44
50
def add_cli_options (parser : argparse .ArgumentParser ) -> None :
@@ -62,18 +68,7 @@ def update_mdit(mdit: MarkdownIt) -> None:
62
68
mdit .use (mkdocstrings_autorefs_plugin )
63
69
mdit .use (pymd_abbreviations_plugin )
64
70
65
- global _ALIGN_SEMANTIC_BREAKS_IN_LISTS # noqa: PLW0603
66
- _ALIGN_SEMANTIC_BREAKS_IN_LISTS = mdit .options ["mdformat" ].get (
67
- "align_semantic_breaks_in_lists" ,
68
- False ,
69
- )
70
-
71
- global _IGNORE_MISSING_REFERENCES # noqa: PLW0603
72
- _IGNORE_MISSING_REFERENCES = mdit .options ["mdformat" ].get (
73
- "ignore_missing_references" ,
74
- False ,
75
- )
76
- if _IGNORE_MISSING_REFERENCES :
71
+ if cli_is_ignore_missing_references (mdit .options ):
77
72
mdit .use (mkdocstrings_crossreference_plugin )
78
73
79
74
@@ -120,7 +115,7 @@ def _render_with_default_renderer(
120
115
121
116
def _render_cross_reference (node : RenderTreeNode , context : RenderContext ) -> str :
122
117
"""Render a MkDocs crossreference link."""
123
- if _IGNORE_MISSING_REFERENCES :
118
+ if cli_is_ignore_missing_references ( context . options ) :
124
119
return _render_meta_content (node , context )
125
120
# Default to treating the matched content as a link
126
121
return _render_with_default_renderer (node , context , "link" )
@@ -141,14 +136,9 @@ def _render_cross_reference(node: RenderTreeNode, context: RenderContext) -> str
141
136
}
142
137
143
138
144
- def check_if_align_semantic_breaks_in_lists () -> bool :
145
- """Return value of global variable."""
146
- return _ALIGN_SEMANTIC_BREAKS_IN_LISTS or False
147
-
148
-
149
139
normalize_list = partial (
150
140
unbounded_normalize_list ,
151
- check_if_align_semantic_breaks_in_lists = check_if_align_semantic_breaks_in_lists ,
141
+ check_if_align_semantic_breaks_in_lists = cli_is_align_semantic_breaks_in_lists ,
152
142
)
153
143
154
144
# A mapping from `RenderTreeNode.type` to a `Postprocess` that does
0 commit comments