Last active
June 22, 2021 16:13
-
-
Save natefoo/4f9ce9717ed77f4e97347304de1d94b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# run with: | |
# find topics -name \*.md -type f -print0 | xargs -0 python3 lamefix.py | |
import fileinput | |
import sys | |
def fix(mdfileobj): | |
in_diff = False | |
min_length = sys.maxsize | |
end = None | |
for line in mdfileobj: | |
# no newlines attrib on FileInput objs =( | |
#end = mdfileobj.newlines if line[-1] == mdfileobj.newlines else None | |
#line = line.rstrip(newline_char) | |
orig_line = line | |
line = line.rstrip('\r\n') | |
end_len = len(orig_line) - len(line) | |
end = orig_line[-end_len:] if end_len > 0 else '' | |
if '```diff' in line: | |
in_diff = True | |
min_length = line.index('`') + 1 | |
elif in_diff and '```' in line: | |
in_diff = False | |
min_length = sys.maxsize | |
elif in_diff and len(line) < min_length: | |
line = f'{line: <{min_length}}' | |
print(line, end=end) | |
def main(): | |
with fileinput.input(inplace=True) as mdfileobj: | |
fix(mdfileobj) | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
def lint(mdfileobj): | |
in_diff = False | |
min_length = sys.maxsize | |
for lineno, line in enumerate(mdfileobj): | |
line = line.rstrip('\n') | |
if '```diff' in line: | |
in_diff = True | |
min_length = line.index('`') + 1 | |
elif in_diff and '```' in line: | |
in_diff = False | |
min_length = sys.maxsize | |
elif in_diff and len(line) < min_length: | |
print(f'{mdfileobj.name}: {lineno}: diff line too short!: "{line}"') | |
def main(): | |
mdfiles = sys.argv[1:] | |
for mdfile in mdfiles: | |
with open(mdfile) as mdfileobj: | |
lint(mdfileobj) | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nate@sokolov% cd topics; find . -name \*.md -type f -print0 | xargs -0 python3 ../lamelint.py | |
./admin/tutorials/cvmfs/tutorial.md: 493: diff line too short!: ">" | |
./admin/tutorials/job-destinations/tutorial.md: 89: diff line too short!: ">" | |
./admin/tutorials/job-destinations/tutorial.md: 249: diff line too short!: ">" | |
./admin/tutorials/job-destinations/tutorial.md: 254: diff line too short!: ">" | |
./admin/tutorials/job-destinations/tutorial.md: 363: diff line too short!: ">" | |
./admin/tutorials/job-destinations/tutorial.md: 372: diff line too short!: ">" | |
./admin/tutorials/job-destinations/tutorial.md: 378: diff line too short!: ">" | |
./admin/tutorials/job-destinations/tutorial.md: 476: diff line too short!: ">" | |
./admin/tutorials/job-destinations/tutorial.md: 632: diff line too short!: ">" | |
./admin/tutorials/job-destinations/tutorial.md: 644: diff line too short!: ">" | |
./admin/tutorials/tiaas/tutorial.md: 171: diff line too short!: ">" | |
./admin/tutorials/tiaas/tutorial.md: 339: diff line too short!: ">" | |
./admin/tutorials/external-auth/tutorial.md: 63: diff line too short!: ">" | |
./admin/tutorials/singularity/tutorial.md: 180: diff line too short!: ">" | |
./admin/tutorials/singularity/tutorial.md: 198: diff line too short!: ">" | |
./admin/tutorials/ansible-galaxy/tutorial.md: 1730: diff line too short!: ">" | |
./admin/tutorials/ansible-galaxy/tutorial.md: 2111: diff line too short!: ">" | |
./admin/tutorials/ansible-galaxy/tutorial.md: 2118: diff line too short!: ">" | |
./admin/tutorials/ansible-galaxy/tutorial.md: 2340: diff line too short!: "" | |
./admin/tutorials/connect-to-compute-cluster/tutorial.md: 362: diff line too short!: ">" | |
./admin/tutorials/connect-to-compute-cluster/tutorial.md: 366: diff line too short!: ">" | |
./admin/tutorials/reports/tutorial.md: 94: diff line too short!: ">" | |
./admin/tutorials/reports/tutorial.md: 109: diff line too short!: ">" | |
./admin/tutorials/reports/tutorial.md: 114: diff line too short!: ">" | |
./admin/tutorials/monitoring/tutorial.md: 524: diff line too short!: ">" | |
./admin/tutorials/data-library/tutorial.md: 80: diff line too short!: ">" | |
./admin/tutorials/object-store/tutorial.md: 328: diff line too short!: ">" | |
./dev/tutorials/core-contributing/test_users.py_diff.md: 45: diff line too short!: "> " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment