github.com/chipaca/snappy@v0.0.0-20210104084008-1f06296fe8ad/mdlint.py (about) 1 #!/usr/bin/python3 2 # 3 # see http://daringfireball.net/projects/markdown/syntax 4 # for the "canonical" reference 5 # 6 # We support django-markdown which uses python-markdown, see: 7 # http://pythonhosted.org/Markdown/ 8 9 import sys 10 import codecs 11 12 13 def lint_li(fname, text): 14 """Ensure that the list-items are multiplies of 4""" 15 is_clean = True 16 for i, line in enumerate(text.splitlines()): 17 if line.lstrip().startswith("*") and line.index("*") % 4 != 0: 18 print("%s: line %i list has non-4 spaces indent" % (fname, i)) 19 is_clean = False 20 return is_clean 21 22 23 def lint(md_files): 24 """lint all md files""" 25 all_clean = True 26 for md in md_files: 27 with codecs.open(md, "r", "utf-8") as f: 28 buf = f.read() 29 for fname, func in globals().items(): 30 if fname.startswith("lint_"): 31 all_clean &= func(md, buf) 32 return all_clean 33 34 35 if __name__ == "__main__": 36 if not lint(sys.argv): 37 sys.exit(1)