Merge pull request #83 from vkbo/hard_line_breaks

Hard line breaks
This commit is contained in:
Veronica K. Berglyd Olsen
2019-10-28 21:47:49 +01:00
committed by GitHub
8 changed files with 49 additions and 21 deletions
+6 -2
View File
@@ -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
+4 -1
View File
@@ -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"
+2 -1
View File
@@ -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:
+1 -2
View File
@@ -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))
+9 -1
View File
@@ -81,6 +81,8 @@ class GuiDocEditor(QTextEdit):
# Custom Shortcuts
QShortcut(QKeySequence("Ctrl+."), self, context=Qt.WidgetShortcut, activated=self._openSpellContext)
QShortcut(Qt.Key_Return | Qt.ControlModifier, self, context=Qt.WidgetShortcut, activated=self._insertHardBreak)
QShortcut(Qt.Key_Enter | Qt.ControlModifier, self, context=Qt.WidgetShortcut, activated=self._insertHardBreak)
# Set Up Word Count Thread and Timer
self.wcInterval = self.mainConf.wordCountTimer
@@ -323,6 +325,13 @@ class GuiDocEditor(QTextEdit):
# Internal Functions
##
def _insertHardBreak(self):
theCursor = self.textCursor()
theCursor.beginEditBlock()
theCursor.insertText(" \n")
theCursor.endEditBlock()
return
def _openSpellContext(self):
self._openContextMenu(self.cursorRect().center())
return
@@ -388,7 +397,6 @@ class GuiDocEditor(QTextEdit):
self.wcTimer.start()
if self.mainConf.doReplace and not self.hasSelection:
self._docAutoReplace(self.qDocument.findBlock(thePos))
# logger.verbose("Doc change signal took %.3f µs" % ((time()-self.lastEdit)*1e6))
return
def _docAutoReplace(self, theBlock):
+13 -2
View File
@@ -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))
@@ -1,16 +1,18 @@
## Interlude
I am the very model of a modern Major-General
I've information vegetable, animal, and mineral
I know the kings of England, and I quote the fights historical
I am the very model of a modern Major-General
I've information vegetable, animal, and mineral
I know the kings of England, and I quote the fights historical
From Marathon to Waterloo, in order categorical
I'm very well acquainted, too, with matters mathematical
I understand equations, both the simple and quadratical
About binomial theorem I'm teeming with a lot o news
I'm very well acquainted, too, with matters mathematical
I understand equations, both the simple and quadratical
About binomial theorem I'm teeming with a lot o news
With many cheerful facts about the square of the hypotenuse
With many cheerful facts about the square of the hypotenuse
With many cheerful facts about the square of the hypotenuse
With many cheerful facts about the square of the hypotenuse
With many cheerful facts about the square of the hypotenuse
With many cheerful facts about the square of the hypotepotenuse
+4 -4
View File
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.3.1" fileVersion="1.0" timeStamp="2019-10-23 21:21:02">
<novelWriterXML appVersion="0.3.2" fileVersion="1.0" timeStamp="2019-10-28 21:42:26">
<project>
<name>Sample Project</name>
<title>Sample Project</title>
@@ -10,7 +10,7 @@
<settings>
<spellCheck>True</spellCheck>
<lastEdited>ba8a28a246524</lastEdited>
<lastViewed>636b6aa9b697b</lastViewed>
<lastViewed>ba8a28a246524</lastViewed>
<lastWordCount>859</lastWordCount>
<autoReplace>
<A>B</A>
@@ -103,10 +103,10 @@
<status>Finished</status>
<expanded>False</expanded>
<layout>UNNUMBERED</layout>
<charCount>614</charCount>
<charCount>626</charCount>
<wordCount>101</wordCount>
<paraCount>3</paraCount>
<cursorPos>633</cursorPos>
<cursorPos>583</cursorPos>
</item>
<item handle="96b68994dfa3d" order="4" parent="e7ded148d6e4a">
<name>A Note on Ipsums</name>