mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-17 19:32:30 +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
|
return text
|
||||||
|
|
||||||
def wordCount(text):
|
def wordCount(text):
|
||||||
words = re.findall(r"\S+", text)
|
return len(re.findall(r"\S+", re.sub(r"(<!--).+?(-->)", "", 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
|
|
||||||
|
|
||||||
|
|
||||||
def charCount(text, use_spaces = True):
|
def charCount(text, use_spaces = True):
|
||||||
|
|
Loading…
Reference in a new issue