diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b5405032bc033d841de5fb6f3be27fb8c5d9b5b0..d166f892ad9a7a7d3463cc22b05a83e0e4ee4e76 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,6 +19,13 @@ two spaces: - echo "== Files having more than one space betwee two characters ==" - find docs.it4i/ -name '*.md' -exec grep "[[:alpha:]] [[:alpha:]]" -l {} + +capitalize: + stage: test + image: davidhrbac/docker-mkdocscheck:latest + allow_failure: true + script: + - find docs.it4i/ -name '*.md' -print0 | xargs -0 -n1 scripts/titlemd_test.py + spell check: stage: test image: davidhrbac/docker-npmcheck:latest diff --git a/scripts/titlemd.py b/scripts/titlemd.py new file mode 100755 index 0000000000000000000000000000000000000000..84fd14b2570ca3f0864936b5f9043e4036cc040e --- /dev/null +++ b/scripts/titlemd.py @@ -0,0 +1,48 @@ +#!/usr/bin/python + +import fnmatch +import os +import sys + +try: + from titlecase import titlecase +except ImportError: + print("Please install titlecase") + +def main(location): + # Spelling exceptions + with open('.spelling') as f: + spelling = f.readlines() + + def abbreviations(word, **kwargs): + if word+"\n" in spelling: + return word + + # Open the file and read the lines as a list + with open(location) as f: + lines = f.readlines() + + with open(location, 'w') as f: + # Loop through the list of lines and titlecase + # any line beginning with '#'. + prev_line = lines.pop(0) + disabled = 0 + for line in lines: + if line.startswith("``") and disabled == 0: + disabled = 1 + else: + if line.startswith("``") and disabled == 1: + disabled = 0 + if line.startswith('#') and disabled == 0: + line = titlecase(line[:(line.find("]"))], callback=abbreviations)+line[(line.find("]")):] + if line.startswith('---') or line.startswith('==='): + prev_line = titlecase(prev_line[:(prev_line.find("]"))], callback=abbreviations)+prev_line[(prev_line.find("]")):] + f.write(prev_line) + prev_line = line + f.write(prev_line) + +if __name__ == "__main__": + try: + main(sys.argv[1]) + except IndexError: + main('.') diff --git a/scripts/titlemd_test.py b/scripts/titlemd_test.py new file mode 100755 index 0000000000000000000000000000000000000000..0c66d4413108d53fccb07e3c8bdf766cd1badfe7 --- /dev/null +++ b/scripts/titlemd_test.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +from __future__ import print_function + +import fnmatch +import os +import sys + +try: + from titlecase import titlecase +except ImportError: + print("Please install titlecase") + +def main(location): + # Spelling exceptions + with open('.spelling') as f: + spelling = f.readlines() + + def abbreviations(word, **kwargs): + if word+"\n" in spelling: + return word + + # Open the file and read the lines as a list + with open(location) as f: + lines = f.readlines() + + # Loop through the list of lines and titlecase + # any line beginning with '#'. + return_value = 0 + prev_line = lines.pop(0) + disabled = 0 + print(`location`) + for line in lines: + if line.startswith("``") and disabled == 0: + disabled = 1 + else: + if line.startswith("``") and disabled == 1: + disabled = 0 + if line.startswith('#') and disabled == 0: + if line != titlecase(line[:(line.find("]"))], callback=abbreviations)+line[(line.find("]")):]: + print() + print("-"+line,end="") + print("+"+titlecase(line[:(line.find("]"))], callback=abbreviations)+line[(line.find("]")):],end="") + return_value = 1 + if line.startswith('---') or line.startswith('==='): + if prev_line != titlecase(prev_line[:(prev_line.find("]"))], callback=abbreviations)+prev_line[(prev_line.find("]")):]: + print() + print("-"+prev_line,end="") + print("+"+titlecase(prev_line[:(prev_line.find("]"))], callback=abbreviations)+prev_line[(prev_line.find("]")):],end="") + return_value = 1 + prev_line = line + if return_value == 0: + print("==Ok==") + exit(return_value) +if __name__ == "__main__": + try: + main(sys.argv[1]) + except IndexError: + main('.')