Files
snapd/mdlint.py
Samuele Pedroni 0024d29bba many: allow for more compact Markdown as CODING.md is quite nested
extend the minal markdown checking to all the files, fix one
2023-01-17 13:18:40 +01:00

38 lines
996 B
Python
Executable File

#!/usr/bin/python3
#
# see http://daringfireball.net/projects/markdown/syntax
# for the "canonical" reference
#
# We support django-markdown which uses python-markdown, see:
# http://pythonhosted.org/Markdown/
import sys
import codecs
def lint_li(fname, text):
"""Ensure that the list-items are multiplies of 2"""
is_clean = True
for i, line in enumerate(text.splitlines()):
if line.lstrip().startswith("*") and line.index("*") % 2 != 0:
print("%s: line %i list has non-2 spaces indent" % (fname, i))
is_clean = False
return is_clean
def lint(md_files):
"""lint all md files"""
all_clean = True
for md in md_files:
with codecs.open(md, "r", "utf-8") as f:
buf = f.read()
for fname, func in globals().items():
if fname.startswith("lint_"):
all_clean &= func(md, buf)
return all_clean
if __name__ == "__main__":
if not lint(sys.argv):
sys.exit(1)