Update document build formats to support text highlighting

This commit is contained in:
Veronica Berglyd Olsen
2024-02-25 16:34:24 +01:00
parent 69bf6a64aa
commit 0566fc38af
6 changed files with 36 additions and 9 deletions
+4
View File
@@ -133,6 +133,8 @@ class ToHtml(Tokenizer):
self.FMT_D_E: "</span>", self.FMT_D_E: "</span>",
self.FMT_U_B: "<u>", self.FMT_U_B: "<u>",
self.FMT_U_E: "</u>", self.FMT_U_E: "</u>",
self.FMT_M_B: "<span style='background-color: yellow;'>",
self.FMT_M_E: "</span>",
} }
else: else:
htmlTags = { # HTML5 (for export) htmlTags = { # HTML5 (for export)
@@ -144,6 +146,8 @@ class ToHtml(Tokenizer):
self.FMT_D_E: "</del>", self.FMT_D_E: "</del>",
self.FMT_U_B: "<span style='text-decoration: underline;'>", self.FMT_U_B: "<span style='text-decoration: underline;'>",
self.FMT_U_E: "</span>", self.FMT_U_E: "</span>",
self.FMT_M_B: "<mark>",
self.FMT_M_E: "</mark>",
} }
htmlTags[self.FMT_SUP_B] = "<sup>" htmlTags[self.FMT_SUP_B] = "<sup>"
+4
View File
@@ -95,6 +95,8 @@ class ToMarkdown(Tokenizer):
self.FMT_D_E: "", self.FMT_D_E: "",
self.FMT_U_B: "", self.FMT_U_B: "",
self.FMT_U_E: "", self.FMT_U_E: "",
self.FMT_M_B: "",
self.FMT_M_E: "",
self.FMT_SUP_B: "", self.FMT_SUP_B: "",
self.FMT_SUP_E: "", self.FMT_SUP_E: "",
self.FMT_SUB_B: "", self.FMT_SUB_B: "",
@@ -111,6 +113,8 @@ class ToMarkdown(Tokenizer):
self.FMT_D_E: "~~", self.FMT_D_E: "~~",
self.FMT_U_B: "", self.FMT_U_B: "",
self.FMT_U_E: "", self.FMT_U_E: "",
self.FMT_M_B: "==",
self.FMT_M_E: "==",
self.FMT_SUP_B: "^", self.FMT_SUP_B: "^",
self.FMT_SUP_E: "^", self.FMT_SUP_E: "^",
self.FMT_SUB_B: "~", self.FMT_SUB_B: "~",
+19 -2
View File
@@ -84,14 +84,16 @@ X_BLD = 0x01 # Bold format
X_ITA = 0x02 # Italic format X_ITA = 0x02 # Italic format
X_DEL = 0x04 # Strikethrough format X_DEL = 0x04 # Strikethrough format
X_UND = 0x08 # Underline format X_UND = 0x08 # Underline format
X_SUP = 0x10 # Superscript X_MRK = 0x10 # Marked format
X_SUB = 0x20 # Subscript X_SUP = 0x20 # Superscript
X_SUB = 0x40 # Subscript
# Formatting Masks # Formatting Masks
M_BLD = ~X_BLD M_BLD = ~X_BLD
M_ITA = ~X_ITA M_ITA = ~X_ITA
M_DEL = ~X_DEL M_DEL = ~X_DEL
M_UND = ~X_UND M_UND = ~X_UND
M_MRK = ~X_MRK
M_SUP = ~X_SUP M_SUP = ~X_SUP
M_SUB = ~X_SUB M_SUB = ~X_SUB
@@ -189,6 +191,7 @@ class ToOdt(Tokenizer):
self._opaHead34 = None self._opaHead34 = None
self._colMetaTx = None self._colMetaTx = None
self._opaMetaTx = None self._opaMetaTx = None
self._markText = "#ffffa6"
return return
@@ -643,6 +646,10 @@ class ToOdt(Tokenizer):
xFmt |= X_UND xFmt |= X_UND
elif fFmt == self.FMT_U_E: elif fFmt == self.FMT_U_E:
xFmt &= M_UND xFmt &= M_UND
elif fFmt == self.FMT_M_B:
xFmt |= X_MRK
elif fFmt == self.FMT_M_E:
xFmt &= M_MRK
elif fFmt == self.FMT_SUP_B: elif fFmt == self.FMT_SUP_B:
xFmt |= X_SUP xFmt |= X_SUP
elif fFmt == self.FMT_SUP_E: elif fFmt == self.FMT_SUP_E:
@@ -710,6 +717,8 @@ class ToOdt(Tokenizer):
newStyle.setUnderlineStyle("solid") newStyle.setUnderlineStyle("solid")
newStyle.setUnderlineWidth("auto") newStyle.setUnderlineWidth("auto")
newStyle.setUnderlineColour("font-color") newStyle.setUnderlineColour("font-color")
if hFmt & X_MRK:
newStyle.setBackgroundColor(self._markText)
if hFmt & X_SUP: if hFmt & X_SUP:
newStyle.setTextPosition("super") newStyle.setTextPosition("super")
if hFmt & X_SUB: if hFmt & X_SUB:
@@ -1279,6 +1288,7 @@ class ODTTextStyle:
self._tAttr = { self._tAttr = {
"font-weight": ["fo", None], "font-weight": ["fo", None],
"font-style": ["fo", None], "font-style": ["fo", None],
"background-color": ["fo", None],
"text-position": ["style", None], "text-position": ["style", None],
"text-line-through-style": ["style", None], "text-line-through-style": ["style", None],
"text-line-through-type": ["style", None], "text-line-through-type": ["style", None],
@@ -1306,6 +1316,13 @@ class ODTTextStyle:
self._tAttr["font-style"][1] = None self._tAttr["font-style"][1] = None
return return
def setBackgroundColor(self, value: str | None) -> None:
if value and len(value) == 7 and value[0] == "#":
self._tAttr["background-color"][1] = value
else:
self._tAttr["background-color"][1] = None
return
def setTextPosition(self, value: str | None) -> None: def setTextPosition(self, value: str | None) -> None:
if value in self.VALID_POS: if value in self.VALID_POS:
self._tAttr["text-position"][1] = f"{value} 58%" self._tAttr["text-position"][1] = f"{value} 58%"
+2
View File
@@ -768,6 +768,8 @@ class _PreviewWidget(QTextBrowser):
html = html.replace("\t", "!!tab!!") html = html.replace("\t", "!!tab!!")
html = html.replace("<del>", "<span style='text-decoration: line-through;'>") html = html.replace("<del>", "<span style='text-decoration: line-through;'>")
html = html.replace("</del>", "</span>") html = html.replace("</del>", "</span>")
html = html.replace("<mark>", "<span style='background-color: #ffffa6;'>")
html = html.replace("</mark>", "</span>")
self.setHtml(html) self.setHtml(html)
qApp.processEvents() qApp.processEvents()
while self.find("!!tab!!"): while self.find("!!tab!!"):
+3 -3
View File
@@ -1,8 +1,8 @@
%%~name: Making a Scene %%~name: Making a Scene
%%~path: 6a2d6d5f4f401/636b6aa9b697b %%~path: 6a2d6d5f4f401/636b6aa9b697b
%%~kind: NOVEL/DOCUMENT %%~kind: NOVEL/DOCUMENT
%%~hash: d7920fe95fb48140278ae160fe7c3c1ce530072c %%~hash: e1c58699b05b512306a534da70c2952aafc60e8b
%%~date: Unknown/2023-10-20 22:57:56 %%~date: Unknown/2024-02-25 16:33:40
### Making a Scene ### Making a Scene
@pov: Jane @pov: Jane
@@ -13,7 +13,7 @@ A scene is defined by a level three heading, like the one at the top of this pag
Each paragraph in the scene is separated by a blank line. The text supports minimal formatting, like **bold**, _italic_ and **_bold italic_**. You can also ~~strike through~~ text. There is **some support for _nested_ emphasis**, but there are some known limitations. If the syntax highlighter doesnt show it correctly, the export tool will not either. Each paragraph in the scene is separated by a blank line. The text supports minimal formatting, like **bold**, _italic_ and **_bold italic_**. You can also ~~strike through~~ text. There is **some support for _nested_ emphasis**, but there are some known limitations. If the syntax highlighter doesnt show it correctly, the export tool will not either.
For special formatting aside from standard emphasis, you can use “shortcodes”. Here we have super[sup]script[/sup] and sub[sub]script[/sub], and [b]part[/b]ial bold too, which ends in the middle of a word. The shortcodes also support [u]underline[/u]. For special formatting aside from standard emphasis, you can use “shortcodes”. Here we have super[sup]script[/sup] and sub[sub]script[/sub], and [b]part[/b]ial bold too, which ends in the middle of a word. The shortcodes also support [u]underline[/u], and you can [m]highlight text as well[/m].
In addition, the editor supports automatic formatting of “quotes”, both double and single. Depending on the syntax highlighter settings and colour theme, these can be in different colours. “You can of course use **bold** and _italic_ text inside of quotes too.” In addition, the editor supports automatic formatting of “quotes”, both double and single. Depending on the syntax highlighter settings and colour theme, these can be in different colours. “You can of course use **bold** and _italic_ text inside of quotes too.”
+4 -4
View File
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="2.3b1" hexVersion="0x020300b1" fileVersion="1.5" fileRevision="2" timeStamp="2024-02-15 22:37:50"> <novelWriterXML appVersion="2.4a0" hexVersion="0x020400a0" fileVersion="1.5" fileRevision="2" timeStamp="2024-02-25 16:33:49">
<project id="e2be99af-f9bf-4403-857a-c3d1ac25abea" saveCount="1681" autoCount="263" editTime="82755"> <project id="e2be99af-f9bf-4403-857a-c3d1ac25abea" saveCount="1690" autoCount="264" editTime="83277">
<name>Sample Project</name> <name>Sample Project</name>
<author>Jane Smith</author> <author>Jane Smith</author>
</project> </project>
@@ -35,7 +35,7 @@
<entry key="i56be10" count="1" red="117" green="0" blue="175">Main</entry> <entry key="i56be10" count="1" red="117" green="0" blue="175">Main</entry>
</importance> </importance>
</settings> </settings>
<content items="31" novelWords="991" notesWords="416"> <content items="31" novelWords="998" 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>
@@ -57,7 +57,7 @@
<name status="sf24ce6" import="ia857f0" active="yes">Chapter One</name> <name status="sf24ce6" import="ia857f0" active="yes">Chapter One</name>
</item> </item>
<item handle="636b6aa9b697b" parent="6a2d6d5f4f401" root="7031beac91f75" order="0" type="FILE" class="NOVEL" layout="DOCUMENT"> <item handle="636b6aa9b697b" parent="6a2d6d5f4f401" root="7031beac91f75" order="0" type="FILE" class="NOVEL" layout="DOCUMENT">
<meta expanded="no" heading="H3" charCount="2901" wordCount="513" paraCount="15" cursorPos="66" /> <meta expanded="no" heading="H3" charCount="2937" wordCount="520" paraCount="15" cursorPos="1465" />
<name status="s90e6c9" import="ia857f0" active="yes">Making a Scene</name> <name status="s90e6c9" import="ia857f0" active="yes">Making a Scene</name>
</item> </item>
<item handle="bc0cbd2a407f3" parent="6a2d6d5f4f401" root="7031beac91f75" order="1" type="FILE" class="NOVEL" layout="DOCUMENT"> <item handle="bc0cbd2a407f3" parent="6a2d6d5f4f401" root="7031beac91f75" order="1" type="FILE" class="NOVEL" layout="DOCUMENT">