github.com/rigado/snapd@v2.42.5-go-mod+incompatible/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 def lint_li(fname, text): 13 """Ensure that the list-items are multiplies of 4""" 14 is_clean = True 15 for i, line in enumerate(text.splitlines()): 16 if line.lstrip().startswith("*") and line.index("*") % 4 != 0: 17 print("%s: line %i list has non-4 spaces indent" % (fname, i)) 18 is_clean = False 19 return is_clean 20 21 22 def lint(md_files): 23 """lint all md files""" 24 all_clean = True 25 for md in md_files: 26 with codecs.open(md, "r", "utf-8") as f: 27 buf = f.read() 28 for fname, func in globals().items(): 29 if fname.startswith("lint_"): 30 all_clean &= func(md, buf) 31 return all_clean 32 33 34 if __name__ == "__main__": 35 if not lint(sys.argv): 36 sys.exit(1)