Minor tweaks in text parsing and highlighting
This commit is contained in:
+3
-2
@@ -305,11 +305,12 @@ class NWIndex():
|
|||||||
|
|
||||||
elif aLine.startswith(r"%"):
|
elif aLine.startswith(r"%"):
|
||||||
if nTitle > 0:
|
if nTitle > 0:
|
||||||
toCheck = aLine[1:].lstrip().lower()
|
toCheck = aLine[1:].lstrip()
|
||||||
|
synTag = toCheck[:9].lower()
|
||||||
tLen = len(aLine)
|
tLen = len(aLine)
|
||||||
cLen = len(toCheck)
|
cLen = len(toCheck)
|
||||||
cOff = tLen - cLen
|
cOff = tLen - cLen
|
||||||
if toCheck.startswith("synopsis:"):
|
if synTag == "synopsis:":
|
||||||
self._indexSynopsis(tHandle, isNovel, aLine[cOff+9:].strip(), nTitle)
|
self._indexSynopsis(tHandle, isNovel, aLine[cOff+9:].strip(), nTitle)
|
||||||
|
|
||||||
# Count words for remaining text after last heading
|
# Count words for remaining text after last heading
|
||||||
|
|||||||
@@ -327,8 +327,9 @@ class Tokenizer():
|
|||||||
tmpMarkdown.append("\n")
|
tmpMarkdown.append("\n")
|
||||||
|
|
||||||
elif aLine[0] == "%":
|
elif aLine[0] == "%":
|
||||||
cLine = aLine[1:].strip()
|
cLine = aLine[1:].lstrip()
|
||||||
if cLine.lower().startswith("synopsis:"):
|
synTag = cLine[:9].lower()
|
||||||
|
if synTag == "synopsis:":
|
||||||
self.theTokens.append((
|
self.theTokens.append((
|
||||||
self.T_SYNOPSIS,
|
self.T_SYNOPSIS,
|
||||||
nLine,
|
nLine,
|
||||||
|
|||||||
+10
-10
@@ -78,7 +78,6 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
"""Initialise the syntax highlighter, setting all the colour
|
"""Initialise the syntax highlighter, setting all the colour
|
||||||
rules and building the regexes.
|
rules and building the regexes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
logger.debug("Setting up highlighting rules")
|
logger.debug("Setting up highlighting rules")
|
||||||
|
|
||||||
self.colHead = QColor(*self.theTheme.colHead)
|
self.colHead = QColor(*self.theTheme.colHead)
|
||||||
@@ -108,8 +107,8 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
"header4h" : self._makeFormat(self.colHeadH, "bold", 1.2),
|
"header4h" : self._makeFormat(self.colHeadH, "bold", 1.2),
|
||||||
"bold" : self._makeFormat(self.colEmph, "bold"),
|
"bold" : self._makeFormat(self.colEmph, "bold"),
|
||||||
"italic" : self._makeFormat(self.colEmph, "italic"),
|
"italic" : self._makeFormat(self.colEmph, "italic"),
|
||||||
"strike" : self._makeFormat(self.colEmph, "strike"),
|
|
||||||
"bolditalic" : self._makeFormat(self.colEmph, ("bold","italic")),
|
"bolditalic" : self._makeFormat(self.colEmph, ("bold","italic")),
|
||||||
|
"strike" : self._makeFormat(self.colEmph, "strike"),
|
||||||
"trailing" : self._makeFormat(self.colTrail, "background"),
|
"trailing" : self._makeFormat(self.colTrail, "background"),
|
||||||
"nobreak" : self._makeFormat(self.colTrail, "background"),
|
"nobreak" : self._makeFormat(self.colTrail, "background"),
|
||||||
"dialogue1" : self._makeFormat(self.colDialN),
|
"dialogue1" : self._makeFormat(self.colDialN),
|
||||||
@@ -131,7 +130,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
}
|
}
|
||||||
))
|
))
|
||||||
|
|
||||||
# Non-breaking Space
|
# Non-Breaking Spaces
|
||||||
self.hRules.append((
|
self.hRules.append((
|
||||||
"[%s]+" % nwUnicode.U_NBSP, {
|
"[%s]+" % nwUnicode.U_NBSP, {
|
||||||
0 : self.hStyles["nobreak"],
|
0 : self.hStyles["nobreak"],
|
||||||
@@ -203,7 +202,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
# Build a QRegExp for spell checker
|
# Build a QRegExp for spell checker
|
||||||
# Include additional characters that the highlighter should
|
# Include additional characters that the highlighter should
|
||||||
# consider to be word separators
|
# consider to be word separators
|
||||||
wordSep = "_\+"
|
wordSep = r"_\+"
|
||||||
wordSep += nwUnicode.U_ENDASH
|
wordSep += nwUnicode.U_ENDASH
|
||||||
wordSep += nwUnicode.U_EMDASH
|
wordSep += nwUnicode.U_EMDASH
|
||||||
self.spellRx = QRegularExpression(r"\b[^\s"+wordSep+r"]+\b")
|
self.spellRx = QRegularExpression(r"\b[^\s"+wordSep+r"]+\b")
|
||||||
@@ -241,7 +240,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
def highlightBlock(self, theText):
|
def highlightBlock(self, theText):
|
||||||
"""Highlight a single block. Prefer to check first character for
|
"""Highlight a single block. Prefer to check first character for
|
||||||
all formats that are defined by their initial characters. This
|
all formats that are defined by their initial characters. This
|
||||||
is significantly faster than running the regex checks we use for
|
is significantly faster than running the regex checks used for
|
||||||
text paragraphs.
|
text paragraphs.
|
||||||
"""
|
"""
|
||||||
if self.theHandle is None or not theText:
|
if self.theHandle is None or not theText:
|
||||||
@@ -252,9 +251,9 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
isValid, theBits, thePos = self.theIndex.scanThis(theText)
|
isValid, theBits, thePos = self.theIndex.scanThis(theText)
|
||||||
isGood = self.theIndex.checkThese(theBits, tItem)
|
isGood = self.theIndex.checkThese(theBits, tItem)
|
||||||
if isValid:
|
if isValid:
|
||||||
for n in range(len(theBits)):
|
for n, theBit in enumerate(theBits):
|
||||||
xPos = thePos[n]
|
xPos = thePos[n]
|
||||||
xLen = len(theBits[n])
|
xLen = len(theBit)
|
||||||
if isGood[n]:
|
if isGood[n]:
|
||||||
if n == 0:
|
if n == 0:
|
||||||
self.setFormat(xPos, xLen, self.hStyles["keyword"])
|
self.setFormat(xPos, xLen, self.hStyles["keyword"])
|
||||||
@@ -287,11 +286,12 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
self.setFormat(4, len(theText), self.hStyles["header4"])
|
self.setFormat(4, len(theText), self.hStyles["header4"])
|
||||||
|
|
||||||
elif theText.startswith("%"): # Comments
|
elif theText.startswith("%"): # Comments
|
||||||
toCheck = theText[1:].lstrip().lower()
|
toCheck = theText[1:].lstrip()
|
||||||
|
synTag = toCheck[:9].lower()
|
||||||
tLen = len(theText)
|
tLen = len(theText)
|
||||||
cLen = len(toCheck)
|
cLen = len(toCheck)
|
||||||
cOff = tLen - cLen
|
cOff = tLen - cLen
|
||||||
if toCheck.startswith("synopsis:"):
|
if synTag == "synopsis:":
|
||||||
self.setFormat(0, cOff+9, self.hStyles["modifier"])
|
self.setFormat(0, cOff+9, self.hStyles["modifier"])
|
||||||
self.setFormat(cOff+9, tLen, self.hStyles["hidden"])
|
self.setFormat(cOff+9, tLen, self.hStyles["hidden"])
|
||||||
else:
|
else:
|
||||||
@@ -349,7 +349,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
if "underline" in fmtStyle:
|
if "underline" in fmtStyle:
|
||||||
theFormat.setFontUnderline(True)
|
theFormat.setFontUnderline(True)
|
||||||
if "background" in fmtStyle:
|
if "background" in fmtStyle:
|
||||||
theFormat.setBackground(QBrush(fmtCol,Qt.SolidPattern))
|
theFormat.setBackground(QBrush(fmtCol, Qt.SolidPattern))
|
||||||
|
|
||||||
if fmtSize is not None:
|
if fmtSize is not None:
|
||||||
theFormat.setFontPointSize(round(fmtSize*self.mainConf.textSize))
|
theFormat.setFontPointSize(round(fmtSize*self.mainConf.textSize))
|
||||||
|
|||||||
Reference in New Issue
Block a user