From b2c7e45fe49606b9ee0f5b4508b908f8fda95151 Mon Sep 17 00:00:00 2001 From: Lubomir Prda <lubomir.prda@vsb.cz> Date: Thu, 26 Jan 2017 10:39:31 +0100 Subject: [PATCH] capitalize now checks abbrevations from .spelling --- scripts/titlemd.py | 12 ++++++++++-- scripts/titlemd_test.py | 16 ++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/scripts/titlemd.py b/scripts/titlemd.py index 905a67d2a..84fd14b25 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 d89f21446..0c66d4413 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: -- GitLab