Skip to content

Commit

Permalink
dev.markdown-checks: add check for lines starting with \[
Browse files Browse the repository at this point in the history
Those seem to translate into centered text in codeberg md renderer.
  • Loading branch information
mk-fg committed Jan 18, 2024
1 parent f352cc2 commit 275c2c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2808,6 +2808,7 @@ Current full list of checks that it runs:
- link-files-weird :: Relative links that start with non-letter/digit/hashmark.
- link-files-git :: If .md file is in a git repo, warn if linked files are not under git control.
- link-dups :: Multiple same-title links with URLs.
- quirks :: Minor non-obvious md syntax quirks which are almost never intentional.
- rx-in-code :: Command-line-specified regexp (if any) detected inside code block(s).
- tabs :: Make sure md file contains no tab characters.
- syntax :: Any kind of incorrect syntax, e.g. blocks opened and not closed and such.
Expand Down
16 changes: 13 additions & 3 deletions dev/markdown-checks
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ checks_all = dict(
link_files_weird='Relative links that start with non-letter/digit/hashmark.',
link_files_git='If .md file is in a git repo, warn if linked files are not under git control.',
link_dups='Multiple same-title links with URLs.',
quirks='Minor non-obvious md syntax quirks which are almost never intentional.',
rx_in_code='Command-line-specified regexp (if any) detected inside code block(s).',
tabs='Make sure md file contains no tab characters.',
syntax='Any kind of incorrect syntax, e.g. blocks opened and not closed and such.' )
Expand Down Expand Up @@ -121,6 +122,14 @@ def md_clean(md, code_re, errs):
return lines


def md_check_quirks(md_lines, errs):
for n, line in md_lines:
if line.strip().startswith(r'\['):
# \[stuff\] at BOL translates into centered "stuff" line on codeberg
errs.append(adict( n=n, t='quirks',
s=f'Line starting with \[ can turn into some weird centered-text thing' ))


def md_check_header_anchors(md_lines, errs, name_max_len=40):
'Check/return a list of header/anchor lines that needs some kind of fixing'
anchors, str_map = dict(), dict()
Expand Down Expand Up @@ -330,8 +339,9 @@ def main(argv=None):

err_code, code_re = 0, (rx := opts.code_rx) and re.compile(rx)
if not opts.md_files: parser.error('At least one markdown file argument must be specified.')
for p, name in zip(ps := list(map(pl.Path, opts.md_files)), path_names(*ps)):
for p, p_name in zip(ps := list(map(pl.Path, opts.md_files)), path_names(*ps)):
md_lines = md_clean((p := pl.Path(p)).read_text(), code_re, errs := list())
md_check_quirks(md_lines, errs)

anchor_map = md_check_header_anchors(md_lines, errs)
if opts.add_anchors:
Expand All @@ -351,7 +361,7 @@ def main(argv=None):
finally:
if p_tmp: p_tmp.unlink(missing_ok=True)
if anchor_map:
print( f'{name} :: Fixed {len(anchor_map)}'
print( f'{p_name} :: Fixed {len(anchor_map)}'
' missing/mismatching anchor(s)', file=sys.stderr )
err_code = 1
continue
Expand All @@ -377,7 +387,7 @@ def main(argv=None):

for err in errs:
if err.t not in checks: continue
print(f'{name}:{err.n} :: {err.t} :: {err.s}', file=sys.stderr); err_code = 1
print(f'{p_name}:{err.n} :: {err.t} :: {err.s}', file=sys.stderr); err_code = 1

return err_code

Expand Down

0 comments on commit 275c2c8

Please sign in to comment.