Added support for hard line breaks, with higlighting and export support
This commit is contained in:
@@ -67,7 +67,8 @@ class ToHtml(Tokenizer):
|
||||
|
||||
if tType == self.T_EMPTY:
|
||||
if len(thisPar) > 0:
|
||||
self.theResult += "<p%s>%s</p>\n" % (hStyle," ".join(thisPar))
|
||||
tTemp = "".join(thisPar)
|
||||
self.theResult += "<p%s>%s</p>\n" % (hStyle,tTemp.rstrip())
|
||||
thisPar = []
|
||||
|
||||
elif tType == self.T_HEAD1:
|
||||
@@ -92,7 +93,10 @@ class ToHtml(Tokenizer):
|
||||
tTemp = tText
|
||||
for xPos, xLen, xFmt in reversed(tFormat):
|
||||
tTemp = tTemp[:xPos]+htmlTags[xFmt]+tTemp[xPos+xLen:]
|
||||
thisPar.append(tTemp)
|
||||
if tText.endswith(" "):
|
||||
thisPar.append(tTemp.rstrip()+"<br/>")
|
||||
else:
|
||||
thisPar.append(tTemp.rstrip()+" ")
|
||||
|
||||
elif tType == self.T_COMMENT and self.doComments:
|
||||
self.theResult += "<div class='comment'>%s</div>\n" % tText
|
||||
|
||||
@@ -95,7 +95,10 @@ class ToLaTeX(Tokenizer):
|
||||
self.theResult += "\\bigskip\n\n"
|
||||
|
||||
elif tType == self.T_TEXT:
|
||||
thisPar.append(self._escapeUnicode(tText))
|
||||
if tText.endswith(" "):
|
||||
thisPar.append(self._escapeUnicode(tText.rstrip())+"\\newline")
|
||||
else:
|
||||
thisPar.append(self._escapeUnicode(tText.rstrip()))
|
||||
|
||||
elif tType == self.T_PBREAK:
|
||||
self.theResult += "\\newpage\n\n"
|
||||
|
||||
@@ -80,7 +80,8 @@ class ToText(Tokenizer):
|
||||
# indicating a new paragraph.
|
||||
if tType == self.T_EMPTY:
|
||||
if len(thisPar) > 0:
|
||||
self.theResult += "%s\n\n" % " ".join(thisPar)
|
||||
tTemp = " ".join(thisPar)
|
||||
self.theResult += "%s\n\n" % tTemp.rstrip())
|
||||
thisPar = []
|
||||
|
||||
elif tType == self.T_HEAD1:
|
||||
|
||||
@@ -171,10 +171,9 @@ class Tokenizer():
|
||||
|
||||
self.theTokens = []
|
||||
for aLine in self.theText.splitlines():
|
||||
aLine = aLine.strip()
|
||||
|
||||
# Tag lines starting with specific characters
|
||||
if len(aLine) == 0:
|
||||
if len(aLine.strip()) == 0:
|
||||
self.theTokens.append((self.T_EMPTY,"",None,self.A_LEFT))
|
||||
elif aLine[0] == "%":
|
||||
self.theTokens.append((self.T_COMMENT,aLine[1:].strip(),None,self.A_LEFT))
|
||||
|
||||
+13
-2
@@ -13,8 +13,8 @@
|
||||
import logging
|
||||
import nw
|
||||
|
||||
from PyQt5.QtCore import QRegularExpression
|
||||
from PyQt5.QtGui import QColor, QTextCharFormat, QFont, QSyntaxHighlighter
|
||||
from PyQt5.QtCore import Qt, QRegularExpression
|
||||
from PyQt5.QtGui import QColor, QTextCharFormat, QFont, QSyntaxHighlighter, QBrush
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -71,6 +71,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
||||
self.colSpell = QColor(*self.theTheme.colSpell)
|
||||
self.colTagErr = QColor(*self.theTheme.colTagErr)
|
||||
self.colRepTag = QColor(*self.theTheme.colRepTag)
|
||||
self.colTrail = QColor(*self.theTheme.colEmph,64)
|
||||
|
||||
self.hStyles = {
|
||||
"header1" : self._makeFormat(self.colHead, "bold",1.8),
|
||||
@@ -85,6 +86,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
||||
"italic" : self._makeFormat(self.colEmph, "italic"),
|
||||
"strike" : self._makeFormat(self.colEmph, "strike"),
|
||||
"underline" : self._makeFormat(self.colEmph, "underline"),
|
||||
"trailing" : self._makeFormat(self.colTrail,"background"),
|
||||
"dialogue1" : self._makeFormat(self.colDialN),
|
||||
"dialogue2" : self._makeFormat(self.colDialD),
|
||||
"dialogue3" : self._makeFormat(self.colDialS),
|
||||
@@ -136,6 +138,13 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
||||
}
|
||||
))
|
||||
|
||||
# Trailing Spaces, 2+
|
||||
self.hRules.append((
|
||||
r"[ ]{2,}$", {
|
||||
0 : self.hStyles["trailing"],
|
||||
}
|
||||
))
|
||||
|
||||
# Markdown
|
||||
self.hRules.append((
|
||||
r"(?<![\w|\\])([\*]{2})(?!\s)(?m:(.+?))(?<![\s|\\])(\1)(?!\w)", {
|
||||
@@ -283,6 +292,8 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
||||
theFormat.setFontStrikeOut(True)
|
||||
if "underline" in fmtStyle:
|
||||
theFormat.setFontUnderline(True)
|
||||
if "background" in fmtStyle:
|
||||
theFormat.setBackground(QBrush(fmtCol,Qt.SolidPattern))
|
||||
|
||||
if fmtSize is not None:
|
||||
theFormat.setFontPointSize(round(fmtSize*self.mainConf.textSize))
|
||||
|
||||
Reference in New Issue
Block a user