10
10
"""Use 4-spaces for mkdocs."""
11
11
12
12
_ALIGN_SEMANTIC_BREAKS_IN_NUMBERED_LISTS = False
13
- """use 3-space on subsequent lines in semantic lists."""
13
+ """user-specified flag for toggling semantic breaks.
14
+
15
+ - 3-spaces on subsequent lines in semantic numbered lists
16
+ - and 2-spaces on subsequent bulleted items within a numbered list
17
+
18
+ """
14
19
15
20
16
21
def add_cli_options (parser : argparse .ArgumentParser ) -> None :
@@ -47,6 +52,7 @@ def _normalize_list(text: str, node: RenderTreeNode, context: RenderContext) ->
47
52
indent_counter = 0
48
53
indent_lookup : Dict [str , int ] = {}
49
54
is_numbered = False
55
+ use_semantic_breaks = _ALIGN_SEMANTIC_BREAKS_IN_NUMBERED_LISTS
50
56
for line in text .split (eol ):
51
57
match = _RE_INDENT .match (line )
52
58
assert match is not None # for pylint
@@ -60,7 +66,7 @@ def _normalize_list(text: str, node: RenderTreeNode, context: RenderContext) ->
60
66
this_indent = match ["indent" ]
61
67
if this_indent :
62
68
indent_diff = len (this_indent ) - len (last_indent )
63
- if indent_diff == 0 :
69
+ if not indent_diff :
64
70
...
65
71
elif indent_diff > 0 :
66
72
indent_counter += 1
@@ -71,10 +77,13 @@ def _normalize_list(text: str, node: RenderTreeNode, context: RenderContext) ->
71
77
raise NotImplementedError (f"Error in indentation of: `{ line } `" )
72
78
else :
73
79
indent_counter = 0
80
+ # Handle bulleted items within a numbered list
81
+ use_semantic_breaks = use_semantic_breaks and is_numbered
74
82
last_indent = this_indent
75
83
new_indent = indent * indent_counter
76
- if _ALIGN_SEMANTIC_BREAKS_IN_NUMBERED_LISTS and not list_match and is_numbered :
77
- new_indent = new_indent [:- 1 ]
84
+ if use_semantic_breaks and not list_match :
85
+ removed_indents = - 1 if is_numbered else - 2
86
+ new_indent = new_indent [:removed_indents ]
78
87
rendered += f"{ new_indent } { new_line .strip ()} { eol } "
79
88
return rendered .rstrip ()
80
89
0 commit comments