File: mdlint.py

package info (click to toggle)
snapd 2.49-1%2Bdeb11u2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 36,432 kB
  • sloc: ansic: 12,125; sh: 8,453; python: 2,163; makefile: 1,284; exp: 173; xml: 22
file content (37 lines) | stat: -rwxr-xr-x 996 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/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 4"""
    is_clean = True
    for i, line in enumerate(text.splitlines()):
        if line.lstrip().startswith("*") and line.index("*") % 4 != 0:
            print("%s: line %i list has non-4 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)