mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-02 20:12:24 +12:00
Use regex to remove comments before counting
This commit is contained in:
parent
6f6abc6f65
commit
f25b47149b
|
@ -30,18 +30,7 @@ def safeTranslate(qApp, group, text):
|
|||
return text
|
||||
|
||||
def wordCount(text):
|
||||
words = re.findall(r"\S+", text)
|
||||
count = 0
|
||||
in_comment = False
|
||||
for word in words:
|
||||
if in_comment and word == '-->':
|
||||
in_comment = False
|
||||
if not in_comment:
|
||||
if word == '<!--':
|
||||
in_comment = True
|
||||
else:
|
||||
count += 1
|
||||
return count
|
||||
return len(re.findall(r"\S+", re.sub(r"(<!--).+?(-->)", "", text)))
|
||||
|
||||
|
||||
def charCount(text, use_spaces = True):
|
||||
|
|
Loading…
Reference in a new issue