Add processing of fields in the Tokenizer
This commit is contained in:
@@ -89,6 +89,7 @@ class nwShortcode:
|
|||||||
BREAK = "[br]"
|
BREAK = "[br]"
|
||||||
|
|
||||||
FOOTNOTE_B = "[footnote:"
|
FOOTNOTE_B = "[footnote:"
|
||||||
|
FIELD_B = "[field:"
|
||||||
|
|
||||||
COMMENT_STYLES = {
|
COMMENT_STYLES = {
|
||||||
nwComment.FOOTNOTE: "[footnote:{0}]",
|
nwComment.FOOTNOTE: "[footnote:{0}]",
|
||||||
|
|||||||
@@ -92,7 +92,8 @@ class TextFmt(IntEnum):
|
|||||||
HRF_B = 21 # Begin href link
|
HRF_B = 21 # Begin href link
|
||||||
HRF_E = 22 # End href link
|
HRF_E = 22 # End href link
|
||||||
FNOTE = 23 # Footnote marker
|
FNOTE = 23 # Footnote marker
|
||||||
STRIP = 24 # Strip the format code
|
FIELD = 24 # Data field
|
||||||
|
STRIP = 25 # Strip the format code
|
||||||
|
|
||||||
|
|
||||||
class BlockTyp(IntEnum):
|
class BlockTyp(IntEnum):
|
||||||
|
|||||||
@@ -193,6 +193,7 @@ class Tokenizer(ABC):
|
|||||||
}
|
}
|
||||||
self._shortCodeVals = {
|
self._shortCodeVals = {
|
||||||
nwShortcode.FOOTNOTE_B: TextFmt.FNOTE,
|
nwShortcode.FOOTNOTE_B: TextFmt.FNOTE,
|
||||||
|
nwShortcode.FIELD_B: TextFmt.FIELD,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Dialogue
|
# Dialogue
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
%%~name: Title Page
|
%%~name: Title Page
|
||||||
%%~path: 7031beac91f75/53b69b83cdafc
|
%%~path: 7031beac91f75/53b69b83cdafc
|
||||||
%%~kind: NOVEL/DOCUMENT
|
%%~kind: NOVEL/DOCUMENT
|
||||||
%%~hash: 4072adb6d21ff877577f033f19714d9bd01396f3
|
%%~hash: 45ec619c9fd1b1185bc35b38d28cda13b05f0a88
|
||||||
%%~date: Unknown/2024-10-24 16:25:44
|
%%~date: Unknown/2024-10-28 16:42:26
|
||||||
|
|
||||||
Jane Smith[br]
|
Jane Smith[br]
|
||||||
42 Main Street[br]
|
42 Main Street[br]
|
||||||
@@ -16,3 +16,5 @@ Jane Smith[br]
|
|||||||
|
|
||||||
>> This is the title page. <<
|
>> This is the title page. <<
|
||||||
>> It should be the first document of the project. <<
|
>> It should be the first document of the project. <<
|
||||||
|
|
||||||
|
>> Word Count: [field:textWords] <<
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version='1.0' encoding='utf-8'?>
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
<novelWriterXML appVersion="2.6a2" hexVersion="0x020600a2" fileVersion="1.5" fileRevision="4" timeStamp="2024-10-26 16:59:09">
|
<novelWriterXML appVersion="2.6a3" hexVersion="0x020600a3" fileVersion="1.5" fileRevision="4" timeStamp="2024-10-28 16:42:35">
|
||||||
<project id="e2be99af-f9bf-4403-857a-c3d1ac25abea" saveCount="2132" autoCount="279" editTime="95062">
|
<project id="e2be99af-f9bf-4403-857a-c3d1ac25abea" saveCount="2134" autoCount="279" editTime="95103">
|
||||||
<name>Sample Project</name>
|
<name>Sample Project</name>
|
||||||
<author>Jane Smith</author>
|
<author>Jane Smith</author>
|
||||||
</project>
|
</project>
|
||||||
@@ -9,8 +9,8 @@
|
|||||||
<language>en_GB</language>
|
<language>en_GB</language>
|
||||||
<spellChecking auto="yes">None</spellChecking>
|
<spellChecking auto="yes">None</spellChecking>
|
||||||
<lastHandle>
|
<lastHandle>
|
||||||
<entry key="editor">636b6aa9b697b</entry>
|
<entry key="editor">53b69b83cdafc</entry>
|
||||||
<entry key="viewer">636b6aa9b697b</entry>
|
<entry key="viewer">53b69b83cdafc</entry>
|
||||||
<entry key="novelTree">7031beac91f75</entry>
|
<entry key="novelTree">7031beac91f75</entry>
|
||||||
<entry key="outline">7031beac91f75</entry>
|
<entry key="outline">7031beac91f75</entry>
|
||||||
</lastHandle>
|
</lastHandle>
|
||||||
@@ -36,13 +36,13 @@
|
|||||||
<entry key="i56be10" count="1" red="220" green="138" blue="221" shape="BLOCK_4">Main</entry>
|
<entry key="i56be10" count="1" red="220" green="138" blue="221" shape="BLOCK_4">Main</entry>
|
||||||
</importance>
|
</importance>
|
||||||
</settings>
|
</settings>
|
||||||
<content items="31" novelWords="1014" notesWords="416">
|
<content items="31" novelWords="1016" notesWords="416">
|
||||||
<item handle="7031beac91f75" parent="None" root="7031beac91f75" order="0" type="ROOT" class="NOVEL">
|
<item handle="7031beac91f75" parent="None" root="7031beac91f75" order="0" type="ROOT" class="NOVEL">
|
||||||
<meta expanded="yes" />
|
<meta expanded="yes" />
|
||||||
<name status="sc24b8f" import="ia857f0">Novel</name>
|
<name status="sc24b8f" import="ia857f0">Novel</name>
|
||||||
</item>
|
</item>
|
||||||
<item handle="53b69b83cdafc" parent="7031beac91f75" root="7031beac91f75" order="0" type="FILE" class="NOVEL" layout="DOCUMENT">
|
<item handle="53b69b83cdafc" parent="7031beac91f75" root="7031beac91f75" order="0" type="FILE" class="NOVEL" layout="DOCUMENT">
|
||||||
<meta expanded="no" heading="H1" charCount="136" wordCount="27" paraCount="3" cursorPos="69" />
|
<meta expanded="no" heading="H1" charCount="148" wordCount="29" paraCount="4" cursorPos="227" />
|
||||||
<name status="sc24b8f" import="ia857f0" active="yes">Title Page</name>
|
<name status="sc24b8f" import="ia857f0" active="yes">Title Page</name>
|
||||||
</item>
|
</item>
|
||||||
<item handle="974e400180a99" parent="7031beac91f75" root="7031beac91f75" order="1" type="FILE" class="NOVEL" layout="DOCUMENT">
|
<item handle="974e400180a99" parent="7031beac91f75" root="7031beac91f75" order="1" type="FILE" class="NOVEL" layout="DOCUMENT">
|
||||||
|
|||||||
@@ -1241,6 +1241,32 @@ def testFmtToken_LineBreak(mockGUI):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.core
|
||||||
|
def testFmtToken_ShortcodeValue(mockGUI):
|
||||||
|
"""Test processing of shortcodes with values."""
|
||||||
|
project = NWProject()
|
||||||
|
tokens = BareTokenizer(project)
|
||||||
|
tokens._handle = TMH
|
||||||
|
|
||||||
|
# Footnote
|
||||||
|
tokens._text = "Hello World[footnote:abcd] to you!"
|
||||||
|
tokens.tokenizeText()
|
||||||
|
assert tokens._blocks == [(
|
||||||
|
BlockTyp.TEXT, "", "Hello World to you!", [
|
||||||
|
(11, TextFmt.FNOTE, f"{TMH}:abcd"),
|
||||||
|
], BlockFmt.NONE
|
||||||
|
)]
|
||||||
|
|
||||||
|
# Field
|
||||||
|
tokens._text = "Hello World: [field:abcd] times!"
|
||||||
|
tokens.tokenizeText()
|
||||||
|
assert tokens._blocks == [(
|
||||||
|
BlockTyp.TEXT, "", "Hello World: times!", [
|
||||||
|
(13, TextFmt.FIELD, f"{TMH}:abcd"),
|
||||||
|
], BlockFmt.NONE
|
||||||
|
)]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.core
|
@pytest.mark.core
|
||||||
def testFmtToken_Dialogue(mockGUI):
|
def testFmtToken_Dialogue(mockGUI):
|
||||||
"""Test the tokenization of dialogue in the Tokenizer class."""
|
"""Test the tokenization of dialogue in the Tokenizer class."""
|
||||||
|
|||||||
Reference in New Issue
Block a user