Skip to content

Commit

Permalink
Use regex to remove comments before counting
Browse files Browse the repository at this point in the history
  • Loading branch information
sagev9000 committed Aug 25, 2023
1 parent 6f6abc6 commit f25b471
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions manuskript/functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f25b471

Please sign in to comment.