Added back in strikethrough support

This commit is contained in:
Veronica K. B. Olsen
2020-06-13 10:27:02 +02:00
parent 31ca1718a0
commit d2b1b8b57e
10 changed files with 106 additions and 38 deletions
+1
View File
@@ -39,6 +39,7 @@ class nwRegEx():
FMT_B = r"(?<![\w|\*|_|\\])([\*|_]{2})(?!\s|\*|_)(.+?)(?<![\s|\\])(\1)(?!\w)" FMT_B = r"(?<![\w|\*|_|\\])([\*|_]{2})(?!\s|\*|_)(.+?)(?<![\s|\\])(\1)(?!\w)"
FMT_I = r"(?<![\w|\*|_|\\])([\*|_])(?!\s|\*|_)(.+?)(?<![\s|\\])(\1)(?!\w)" FMT_I = r"(?<![\w|\*|_|\\])([\*|_])(?!\s|\*|_)(.+?)(?<![\s|\\])(\1)(?!\w)"
FMT_BI = r"(?<![\w|\*|\\])([\*]{3})(?!\s|\*)(.+?)(?<![\s|\\])(\1)(?!\w)" FMT_BI = r"(?<![\w|\*|\\])([\*]{3})(?!\s|\*)(.+?)(?<![\s|\\])(\1)(?!\w)"
FMT_ST = r"(?<![\w|~|\\])([~]{2})(?!\s|~)(.+?)(?<![\s|\\])(\1)(?!\w)"
# END Class nwRegEx # END Class nwRegEx
+16 -15
View File
@@ -77,21 +77,22 @@ class nwDocAction(Enum):
ITALIC = 6 ITALIC = 6
BOLD = 7 BOLD = 7
BOLDITALIC = 8 BOLDITALIC = 8
S_QUOTE = 9 STRIKE = 9
D_QUOTE = 10 S_QUOTE = 10
SEL_ALL = 11 D_QUOTE = 11
SEL_PARA = 12 SEL_ALL = 12
FIND = 13 SEL_PARA = 13
REPLACE = 14 FIND = 14
GO_NEXT = 15 REPLACE = 15
GO_PREV = 16 GO_NEXT = 16
REPL_NEXT = 17 GO_PREV = 17
BLOCK_H1 = 18 REPL_NEXT = 18
BLOCK_H2 = 19 BLOCK_H1 = 19
BLOCK_H3 = 20 BLOCK_H2 = 20
BLOCK_H4 = 21 BLOCK_H3 = 21
BLOCK_COM = 22 BLOCK_H4 = 22
BLOCK_TXT = 23 BLOCK_COM = 23
BLOCK_TXT = 24
# END Enum nwDocAction # END Enum nwDocAction
+22 -8
View File
@@ -116,14 +116,28 @@ class ToHtml(Tokenizer):
"""Convert the list of text tokens into a HTML document saved """Convert the list of text tokens into a HTML document saved
to theResult. to theResult.
""" """
htmlTags = { if self.genMode == self.M_PREVIEW:
self.FMT_B_B : "<strong>", htmlTags = { # HTML4 + CSS2
self.FMT_B_E : "</strong>", self.FMT_B_B : "<b>",
self.FMT_I_B : "<em>", self.FMT_B_E : "</b>",
self.FMT_I_E : "</em>", self.FMT_I_B : "<i>",
self.FMT_S_B : "<strong><em>", self.FMT_I_E : "</i>",
self.FMT_S_E : "</em></strong>", self.FMT_S_B : "<b><i>",
} self.FMT_S_E : "</i></b>",
self.FMT_D_B : "<span style='text-decoration: line-through;'>",
self.FMT_D_E : "</span>",
}
else:
htmlTags = { # HTML5
self.FMT_B_B : "<strong>",
self.FMT_B_E : "</strong>",
self.FMT_I_B : "<em>",
self.FMT_I_E : "</em>",
self.FMT_S_B : "<strong><em>",
self.FMT_S_E : "</em></strong>",
self.FMT_D_B : "<del>",
self.FMT_D_E : "</del>",
}
if self.isNovel and self.genMode != self.M_PREVIEW: if self.isNovel and self.genMode != self.M_PREVIEW:
# For novel files for export, we bump the titles one level # For novel files for export, we bump the titles one level
+9 -5
View File
@@ -46,6 +46,8 @@ class Tokenizer():
FMT_I_E = 4 # End italics FMT_I_E = 4 # End italics
FMT_S_B = 5 # Begin bold italic FMT_S_B = 5 # Begin bold italic
FMT_S_E = 6 # End bold italic FMT_S_E = 6 # End bold italic
FMT_D_B = 7 # Begin strikeout
FMT_D_E = 8 # End strikeout
T_EMPTY = 1 # Empty line (new paragraph) T_EMPTY = 1 # Empty line (new paragraph)
T_SYNOPSIS = 2 # Synopsis comment T_SYNOPSIS = 2 # Synopsis comment
@@ -292,16 +294,18 @@ class Tokenizer():
The format of the token list is an entry with a four-tuple for The format of the token list is an entry with a four-tuple for
each line in the file. The tuple is as follows: each line in the file. The tuple is as follows:
1: The type of the block, self.T_* 1: The type of the block, self.T_*
2: The text content of the block, without leading tags 2: The line in file where this block occurred
3: The internal formatting map of the text, self.FMT_* 3: The text content of the block, without leading tags
4: The style of the block, self.A_* 4: The internal formatting map of the text, self.FMT_*
5: The style of the block, self.A_*
""" """
# RegExes for adding formatting tags within text lines # RegExes for adding formatting tags within text lines
rxFormats = [ rxFormats = [
(QRegularExpression(nwRegEx.FMT_BI), [None, self.FMT_S_B, None, self.FMT_S_E]),
(QRegularExpression(nwRegEx.FMT_B), [None, self.FMT_B_B, None, self.FMT_B_E]),
(QRegularExpression(nwRegEx.FMT_I), [None, self.FMT_I_B, None, self.FMT_I_E]), (QRegularExpression(nwRegEx.FMT_I), [None, self.FMT_I_B, None, self.FMT_I_E]),
(QRegularExpression(nwRegEx.FMT_B), [None, self.FMT_B_B, None, self.FMT_B_E]),
(QRegularExpression(nwRegEx.FMT_BI), [None, self.FMT_S_B, None, self.FMT_S_E]),
(QRegularExpression(nwRegEx.FMT_ST), [None, self.FMT_D_B, None, self.FMT_D_E]),
] ]
self.theTokens = [] self.theTokens = []
+3 -1
View File
@@ -982,7 +982,9 @@ class GuiBuildNovelDocView(QTextBrowser):
""" """
if isinstance(theText, list): if isinstance(theText, list):
theText = "".join(theText) theText = "".join(theText)
theText = theText.replace("&emsp;","&nbsp;"*4) theText = theText.replace("&emsp;", "&nbsp;"*4)
theText = theText.replace("<del>", "<span style='text-decoration: line-through;'>")
theText = theText.replace("</del>", "</span>")
self.setHtml(theText) self.setHtml(theText)
return return
+32
View File
@@ -515,6 +515,8 @@ class GuiDocEditor(QTextEdit):
self._toggleEmph(2) self._toggleEmph(2)
elif theAction == nwDocAction.BOLDITALIC: elif theAction == nwDocAction.BOLDITALIC:
self._toggleEmph(3) self._toggleEmph(3)
elif theAction == nwDocAction.STRIKE:
self._toggleStrike()
elif theAction == nwDocAction.S_QUOTE: elif theAction == nwDocAction.S_QUOTE:
self._wrapSelection(self.typSQOpen, self.typSQClose) self._wrapSelection(self.typSQOpen, self.typSQClose)
elif theAction == nwDocAction.D_QUOTE: elif theAction == nwDocAction.D_QUOTE:
@@ -1000,6 +1002,36 @@ class GuiDocEditor(QTextEdit):
return return
def _toggleStrike(self):
"""Toggle strikethrough text.
"""
theCursor = self._autoSelect()
if theCursor.hasSelection():
posS = theCursor.selectionStart()
posE = theCursor.selectionEnd()
numB = 0
for n in range(2):
if self.qDocument.characterAt(posS-n-1) == "~":
numB += 1
else:
break
numA = 0
for n in range(2):
if self.qDocument.characterAt(posE+n) == "~":
numA += 1
else:
break
cLevel = min(numB, numA)
if cLevel == 2:
self._clearSurrounding(theCursor, 2)
else:
self._wrapSelection("~~")
return
def _formatBlock(self, docAction): def _formatBlock(self, docAction):
"""Changes the block format of the block under the cursor. """Changes the block format of the block under the cursor.
""" """
+7
View File
@@ -160,6 +160,13 @@ class GuiDocHighlighter(QSyntaxHighlighter):
3 : self.hStyles["hidden"], 3 : self.hStyles["hidden"],
} }
)) ))
self.hRules.append((
nwRegEx.FMT_ST, {
1 : self.hStyles["hidden"],
2 : self.hStyles["strike"],
3 : self.hStyles["hidden"],
}
))
# Quoted Strings # Quoted Strings
if self.mainConf.highlightQuotes: if self.mainConf.highlightQuotes:
+7
View File
@@ -536,6 +536,13 @@ class GuiMainMenu(QMenuBar):
self.aFmtBoldIt.triggered.connect(lambda: self._docAction(nwDocAction.BOLDITALIC)) self.aFmtBoldIt.triggered.connect(lambda: self._docAction(nwDocAction.BOLDITALIC))
self.fmtMenu.addAction(self.aFmtBoldIt) self.fmtMenu.addAction(self.aFmtBoldIt)
# Format > Strikethrough
self.aFmtStrike = QAction("Strikethrough Text", self)
self.aFmtStrike.setStatusTip("Strikethrough selected text")
self.aFmtStrike.setShortcut("Ctrl+-")
self.aFmtStrike.triggered.connect(lambda: self._docAction(nwDocAction.STRIKE))
self.fmtMenu.addAction(self.aFmtStrike)
# Edit > Separator # Edit > Separator
self.fmtMenu.addSeparator() self.fmtMenu.addSeparator()
+1 -1
View File
@@ -7,7 +7,7 @@
A scene is defined by a level three heading, like the one at the top of this page. The scene will be assigned to the chapter preceding it in the project tree. A scene is defined by a level three heading, like the one at the top of this page. The scene will be assigned to the chapter preceding it in the project tree.
Each paragraph in the scene is separated by a blank line. The text supports minimal formatting, like **bold**, *italic* and ***bold italic***. 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.
In addition, the editor supports automatic formatting of “quotes”, both double and single. Depending on the syntax highlighter, these can be in different colours. In addition, the editor supports automatic formatting of “quotes”, both double and single. Depending on the syntax highlighter, these can be in different colours.
+8 -8
View File
@@ -1,13 +1,13 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.9.0rc1" hexVersion="0x000900c1" fileVersion="1.1" timeStamp="2020-06-12 23:58:07"> <novelWriterXML appVersion="0.9.0rc1" hexVersion="0x000900c1" fileVersion="1.1" timeStamp="2020-06-13 10:26:35">
<project> <project>
<name>Sample Project</name> <name>Sample Project</name>
<title>Sample Project</title> <title>Sample Project</title>
<author>Jane Smith</author> <author>Jane Smith</author>
<author>Jay Doh</author> <author>Jay Doh</author>
<saveCount>319</saveCount> <saveCount>332</saveCount>
<autoCount>49</autoCount> <autoCount>56</autoCount>
<editTime>9675</editTime> <editTime>10692</editTime>
</project> </project>
<settings> <settings>
<doBackup>False</doBackup> <doBackup>False</doBackup>
@@ -15,7 +15,7 @@
<autoOutline>True</autoOutline> <autoOutline>True</autoOutline>
<lastEdited>636b6aa9b697b</lastEdited> <lastEdited>636b6aa9b697b</lastEdited>
<lastViewed>636b6aa9b697b</lastViewed> <lastViewed>636b6aa9b697b</lastViewed>
<lastWordCount>921</lastWordCount> <lastWordCount>927</lastWordCount>
<autoReplace> <autoReplace>
<A>B</A> <A>B</A>
<B>E</B> <B>E</B>
@@ -114,10 +114,10 @@
<status>1st Draft</status> <status>1st Draft</status>
<exported>True</exported> <exported>True</exported>
<layout>SCENE</layout> <layout>SCENE</layout>
<charCount>1202</charCount> <charCount>1240</charCount>
<wordCount>217</wordCount> <wordCount>223</wordCount>
<paraCount>7</paraCount> <paraCount>7</paraCount>
<cursorPos>248</cursorPos> <cursorPos>403</cursorPos>
</item> </item>
<item handle="bc0cbd2a407f3" order="2" parent="e7ded148d6e4a"> <item handle="bc0cbd2a407f3" order="2" parent="e7ded148d6e4a">
<name>Another Scene</name> <name>Another Scene</name>