Skip to content

Commit

Permalink
dev.markdown-checks: special-case first list-item lines before any em…
Browse files Browse the repository at this point in the history
…pty ones with 2-3 spaces to not reset list level
  • Loading branch information
mk-fg committed Nov 16, 2024
1 parent c414aec commit 9a7df74
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions dev/markdown-checks
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ md_esc_restore = lambda s: md_esc_strip(s, True)

def md_clean(md, code_re, errs):
'Return markdown with all code-blocks stripped'
st = adict( list_level=0, sep=None,
code=None, code_inline=None, code_prefix=None )
st = adict( list_level=0, list_start=False,
sep=None, code=None, code_inline=None, code_prefix=None )
lines_cut, lines = list(), f'\n{md}'.splitlines() # \n to skip line-number=0 easily

def _find_code_start(n, line):
Expand Down Expand Up @@ -97,13 +97,15 @@ def md_clean(md, code_re, errs):
for n, line in enumerate(lines):
if not line.strip(): st.sep = True; continue
if '\t' in line: errs.append(adict(n=n, t='tabs', s='Tab character(s)'))
if st.sep or st.code: st.list_start = False

if not st.code:
if st.list_level > 0:
level = st.list_level
while level and line.startswith(' '*4): line = line[4:]; level -= 1
if st.list_start and level == 1 and line.startswith(' '): level -= 1
st.list_level -= level
if line.startswith('- '): st.list_level += 1
if line.startswith('- '): st.list_level += 1; st.list_start = True
_find_code_start(n, line)

else:
Expand Down

0 comments on commit 9a7df74

Please sign in to comment.