Merge Novel Layouts (#837)
* Merge novel layouts and simplify the Tokenizer class * Fix core tests * Delete auto-layout code * Remove no longer needed item layouts * Remove references to deleted item layouts in test * Make some minor changes to Tokenizer class and update tests * Update test reference files * Update sample project * Fix a few issues with the Tokenizer * Centre some text in the sample documents * Make some minor changes to how new projects are generated * Add support for New Page and VSpace commands to the Tokenizer * Remove Title and Page layouts and add codes for page break and vertical space * Add document layout and fix some issues in index class with new title formats * Update tests and reference files * Bump the project file version and fix a minor issue in items class * Update tests and test coverage * Clean up some warnings and issues in tests
This commit is contained in:
committed by
GitHub
parent
c6973043e6
commit
bb1a778277
+7
-7
@@ -468,14 +468,14 @@ class GuiDocEditor(QTextEdit):
|
||||
else:
|
||||
self.theParent.novelView.updateWordCounts(tHandle)
|
||||
|
||||
hLevel = "H0"
|
||||
if self._docHeaders:
|
||||
hLevel = self._docHeaders[0][1]
|
||||
# hLevel = "H0"
|
||||
# if self._docHeaders:
|
||||
# hLevel = self._docHeaders[0][1]
|
||||
|
||||
if self.theProject.projTree.updateItemLayout(tHandle, hLevel):
|
||||
self.theParent.treeView.setTreeItemValues(tHandle)
|
||||
self._nwDocument.writeDocument(docText)
|
||||
self.docFooter.updateInfo()
|
||||
# if self.theProject.projTree.updateItemLayout(tHandle, hLevel):
|
||||
# self.theParent.treeView.setTreeItemValues(tHandle)
|
||||
# self._nwDocument.writeDocument(docText)
|
||||
# self.docFooter.updateInfo()
|
||||
|
||||
# Update the status bar
|
||||
self.theParent.setStatus(
|
||||
|
||||
+44
-15
@@ -34,6 +34,7 @@ from PyQt5.QtGui import (
|
||||
)
|
||||
|
||||
from nw.constants import nwRegEx, nwUnicode
|
||||
from nw.common import checkInt
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -127,6 +128,8 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
||||
"keyword": self._makeFormat(self.colKey),
|
||||
"modifier": self._makeFormat(self.colMod),
|
||||
"value": self._makeFormat(self.colVal, "underline"),
|
||||
"codevalue": self._makeFormat(self.colVal),
|
||||
"codeinval": self._makeFormat(None, "errline"),
|
||||
}
|
||||
|
||||
self.hRules = []
|
||||
@@ -312,25 +315,32 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
||||
# so we force a return here
|
||||
return
|
||||
|
||||
elif theText.startswith("# "): # Header 1
|
||||
elif theText.startswith(("# ", "#! ", "## ", "##! ", "### ", "#### ")):
|
||||
self.setCurrentBlockState(self.BLOCK_TITLE)
|
||||
self.setFormat(0, 1, self.hStyles["header1h"])
|
||||
self.setFormat(1, len(theText), self.hStyles["header1"])
|
||||
|
||||
elif theText.startswith("## "): # Header 2
|
||||
self.setCurrentBlockState(self.BLOCK_TITLE)
|
||||
self.setFormat(0, 2, self.hStyles["header2h"])
|
||||
self.setFormat(2, len(theText), self.hStyles["header2"])
|
||||
if theText.startswith("# "): # Header 1
|
||||
self.setFormat(0, 1, self.hStyles["header1h"])
|
||||
self.setFormat(1, len(theText), self.hStyles["header1"])
|
||||
|
||||
elif theText.startswith("### "): # Header 3
|
||||
self.setCurrentBlockState(self.BLOCK_TITLE)
|
||||
self.setFormat(0, 3, self.hStyles["header3h"])
|
||||
self.setFormat(3, len(theText), self.hStyles["header3"])
|
||||
elif theText.startswith("## "): # Header 2
|
||||
self.setFormat(0, 2, self.hStyles["header2h"])
|
||||
self.setFormat(2, len(theText), self.hStyles["header2"])
|
||||
|
||||
elif theText.startswith("#### "): # Header 4
|
||||
self.setCurrentBlockState(self.BLOCK_TITLE)
|
||||
self.setFormat(0, 4, self.hStyles["header4h"])
|
||||
self.setFormat(4, len(theText), self.hStyles["header4"])
|
||||
elif theText.startswith("### "): # Header 3
|
||||
self.setFormat(0, 3, self.hStyles["header3h"])
|
||||
self.setFormat(3, len(theText), self.hStyles["header3"])
|
||||
|
||||
elif theText.startswith("#### "): # Header 4
|
||||
self.setFormat(0, 4, self.hStyles["header4h"])
|
||||
self.setFormat(4, len(theText), self.hStyles["header4"])
|
||||
|
||||
if theText.startswith("#! "): # Title
|
||||
self.setFormat(0, 2, self.hStyles["header1h"])
|
||||
self.setFormat(2, len(theText), self.hStyles["header1"])
|
||||
|
||||
elif theText.startswith("##! "): # Unnumbered
|
||||
self.setFormat(0, 3, self.hStyles["header2h"])
|
||||
self.setFormat(3, len(theText), self.hStyles["header2"])
|
||||
|
||||
elif theText.startswith("%"): # Comments
|
||||
self.setCurrentBlockState(self.BLOCK_TEXT)
|
||||
@@ -346,6 +356,25 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
||||
self.setFormat(0, tLen, self.hStyles["hidden"])
|
||||
|
||||
else: # Text Paragraph
|
||||
|
||||
if theText.startswith("["): # Special Command
|
||||
sText = theText.rstrip()
|
||||
if sText in ("[NEWPAGE]", "[NEW PAGE]", "[VSPACE]"):
|
||||
self.setFormat(0, len(theText), self.hStyles["keyword"])
|
||||
return
|
||||
|
||||
elif sText.startswith("[VSPACE:") and sText.endswith("]"):
|
||||
tLen = len(sText)
|
||||
tVal = checkInt(sText[8:-1], 0)
|
||||
self.setFormat(0, 8, self.hStyles["keyword"])
|
||||
if tVal > 0:
|
||||
self.setFormat(8, tLen-9, self.hStyles["codevalue"])
|
||||
else:
|
||||
self.setFormat(8, tLen-9, self.hStyles["codeinval"])
|
||||
self.setFormat(tLen-1, tLen, self.hStyles["keyword"])
|
||||
return
|
||||
|
||||
# Regular text
|
||||
self.setCurrentBlockState(self.BLOCK_TEXT)
|
||||
for rX, xFmt in self.rxRules:
|
||||
rxItt = rX.globalMatch(theText, 0)
|
||||
|
||||
@@ -187,6 +187,7 @@ class GuiDocViewer(QTextBrowser):
|
||||
logger.error("Failed to generate preview for document with handle '%s'", tHandle)
|
||||
nw.logException()
|
||||
self.setText(self.tr("An error occurred while generating the preview."))
|
||||
return False
|
||||
|
||||
# Refresh the tab stops
|
||||
if self.mainConf.verQtValue >= 51000:
|
||||
@@ -208,7 +209,9 @@ class GuiDocViewer(QTextBrowser):
|
||||
theCursor.insertText("\t")
|
||||
|
||||
if self._docHandle == tHandle:
|
||||
# This is a refresh, so we set the scrollbar back to where it was
|
||||
self.verticalScrollBar().setValue(sPos)
|
||||
|
||||
self._docHandle = tHandle
|
||||
self.theProject.setLastViewed(tHandle)
|
||||
self.docHeader.setTitleFromHandle(self._docHandle)
|
||||
@@ -539,6 +542,9 @@ class GuiDocViewer(QTextBrowser):
|
||||
".synopsis {{"
|
||||
" color: rgb({mColR}, {mColG}, {mColB});"
|
||||
"}}\n"
|
||||
".title {{"
|
||||
" text-align: center;"
|
||||
"}}\n"
|
||||
).format(
|
||||
tColR=self.theTheme.colText[0],
|
||||
tColG=self.theTheme.colText[1],
|
||||
|
||||
+1
-5
@@ -292,11 +292,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
curTxt = ""
|
||||
|
||||
if curTxt == "":
|
||||
if nwItem.itemLayout == nwItemLayout.CHAPTER:
|
||||
newText = f"## {nwItem.itemName}\n\n"
|
||||
elif nwItem.itemLayout == nwItemLayout.UNNUMBERED:
|
||||
newText = f"## {nwItem.itemName}\n\n"
|
||||
elif nwItem.itemLayout == nwItemLayout.SCENE:
|
||||
if nwItem.itemLayout == nwItemLayout.DOCUMENT:
|
||||
newText = f"### {nwItem.itemName}\n\n"
|
||||
else:
|
||||
newText = f"# {nwItem.itemName}\n\n"
|
||||
|
||||
Reference in New Issue
Block a user