diff --git a/scripts/titlemd.py b/scripts/titlemd.py index 905a67d2a370935067be43968caf0e0fc4f5584e..84fd14b2570ca3f0864936b5f9043e4036cc040e 100755 --- a/scripts/titlemd.py +++ b/scripts/titlemd.py @@ -10,6 +10,14 @@ 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() @@ -26,9 +34,9 @@ def main(location): if line.startswith("``") and disabled == 1: disabled = 0 if line.startswith('#') and disabled == 0: - line = titlecase(line[:(line.find("]"))])+line[(line.find("]")):] + line = titlecase(line[:(line.find("]"))], callback=abbreviations)+line[(line.find("]")):] if line.startswith('---') or line.startswith('==='): - prev_line = titlecase(prev_line[:(prev_line.find("]"))])+prev_line[(prev_line.find("]")):] + 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) diff --git a/scripts/titlemd_test.py b/scripts/titlemd_test.py index d89f214462a6c477d8f4b107fa5b2a69a2e4c913..0c66d4413108d53fccb07e3c8bdf766cd1badfe7 100755 --- a/scripts/titlemd_test.py +++ b/scripts/titlemd_test.py @@ -11,6 +11,14 @@ 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() @@ -28,16 +36,16 @@ def main(location): if line.startswith("``") and disabled == 1: disabled = 0 if line.startswith('#') and disabled == 0: - if line != titlecase(line): + if line != titlecase(line[:(line.find("]"))], callback=abbreviations)+line[(line.find("]")):]: print() print("-"+line,end="") - print("+"+titlecase(line[:(line.find("]"))])+line[(line.find("]")):],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): + 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("]"))])+prev_line[(prev_line.find("]")):],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: