Fix counting error (#2062)

This commit is contained in:
Veronica Berglyd Olsen
2024-10-24 00:01:39 +02:00
committed by GitHub
3 changed files with 6 additions and 3 deletions
+2
View File
@@ -30,6 +30,7 @@ import re
from novelwriter.constants import nwRegEx, nwUnicode from novelwriter.constants import nwRegEx, nwUnicode
RX_SC = re.compile(nwRegEx.FMT_SC) RX_SC = re.compile(nwRegEx.FMT_SC)
RX_SV = re.compile(nwRegEx.FMT_SV)
RX_LO = re.compile(r"(?i)(?<!\\)(\[(?:vspace|newpage|new page)(:\d+)?)(?<!\\)(\])") RX_LO = re.compile(r"(?i)(?<!\\)(\[(?:vspace|newpage|new page)(:\d+)?)(?<!\\)(\])")
@@ -64,6 +65,7 @@ def preProcessText(text: str, keepHeaders: bool = True) -> list[str]:
# Strip shortcodes and special formatting # Strip shortcodes and special formatting
# RegEx is slow, so we do this only when necessary # RegEx is slow, so we do this only when necessary
line = RX_SC.sub("", line) line = RX_SC.sub("", line)
line = RX_SV.sub("", line)
line = RX_LO.sub("", line) line = RX_LO.sub("", line)
result.append(line) result.append(line)
@@ -17,7 +17,7 @@
}, },
"88d59a277361b": { "88d59a277361b": {
"headings": { "headings": {
"T0001": {"level": "H2", "title": "Prologue", "line": 1, "tag": "", "cCount": 600, "wCount": 92, "pCount": 1, "synopsis": "Explanation from the lipsum.com website."} "T0001": {"level": "H2", "title": "Prologue", "line": 1, "tag": "", "cCount": 584, "wCount": 92, "pCount": 1, "synopsis": "Explanation from the lipsum.com website."}
}, },
"notes": { "notes": {
"footnotes": ["f9kgf"] "footnotes": ["f9kgf"]
+3 -2
View File
@@ -46,6 +46,7 @@ def testTextCounting_preProcessText():
"A [b]paragraph[/b].\n\n" "A [b]paragraph[/b].\n\n"
"[vspace:3]\n\n" "[vspace:3]\n\n"
"[New Page]\n\n" "[New Page]\n\n"
"[footnote:abcd]\n\n"
"Dashes\u2013and even longer\u2014dashes.\n\n" "Dashes\u2013and even longer\u2014dashes.\n\n"
) )
@@ -59,7 +60,7 @@ def testTextCounting_preProcessText():
"#### Heading Four", "#### Heading Four",
"", "", "", "", "", "",
"A paragraph.", "", "A paragraph.", "",
"", "", "", "", "", "", "", "", "", "",
"Dashes and even longer dashes.", "" "Dashes and even longer dashes.", ""
] ]
@@ -67,7 +68,7 @@ def testTextCounting_preProcessText():
assert preProcessText(text, keepHeaders=False) == [ assert preProcessText(text, keepHeaders=False) == [
"", "", "", "", "", "",
"A paragraph.", "", "A paragraph.", "",
"", "", "", "", "", "", "", "", "", "",
"Dashes and even longer dashes.", "" "Dashes and even longer dashes.", ""
] ]