Merge pull request #276 from vkbo/no_format_export

Export w/o Styling
This commit is contained in:
Veronica K. Berglyd Olsen
2020-06-01 22:51:15 +02:00
committed by GitHub
2 changed files with 47 additions and 12 deletions
+12 -2
View File
@@ -43,6 +43,7 @@ class ToHtml(Tokenizer):
def __init__(self, theProject, theParent): def __init__(self, theProject, theParent):
Tokenizer.__init__(self, theProject, theParent) Tokenizer.__init__(self, theProject, theParent)
self.genMode = self.M_EXPORT self.genMode = self.M_EXPORT
self.cssStyles = True
self.repDict = { self.repDict = {
"<" : "&lt;", "<" : "&lt;",
@@ -78,6 +79,13 @@ class ToHtml(Tokenizer):
self._buildRegEx() self._buildRegEx()
return return
def setStyles(self, cssStyles):
"""Enable/disable CSS styling. Some elements may still have
class tags.
"""
self.cssStyles = cssStyles
return
## ##
# Class Methods # Class Methods
## ##
@@ -147,7 +155,7 @@ class ToHtml(Tokenizer):
# Styles # Styles
aStyle = [] aStyle = []
if tStyle is not None: if tStyle is not None and self.cssStyles:
if tStyle & self.A_LEFT: if tStyle & self.A_LEFT:
aStyle.append("text-align: left;") aStyle.append("text-align: left;")
if tStyle & self.A_RIGHT: if tStyle & self.A_RIGHT:
@@ -183,7 +191,7 @@ class ToHtml(Tokenizer):
if tType == self.T_EMPTY: if tType == self.T_EMPTY:
if parStyle is None: if parStyle is None:
parStyle = "" parStyle = ""
if hasHardBreak: if hasHardBreak and self.cssStyles:
parClass = " class='break'" parClass = " class='break'"
else: else:
parClass = "" parClass = ""
@@ -250,6 +258,8 @@ class ToHtml(Tokenizer):
"""Generate a stylesheet appropriate for the current settings. """Generate a stylesheet appropriate for the current settings.
""" """
theStyles = [] theStyles = []
if not self.cssStyles:
return theStyles
if self.doJustify: if self.doJustify:
theStyles.append(r"p {text-align: justify;}") theStyles.append(r"p {text-align: justify;}")
+35 -10
View File
@@ -204,13 +204,23 @@ class GuiBuildNovel(QDialog):
self.optState.getBool("GuiBuildNovel", "justifyText", False) self.optState.getBool("GuiBuildNovel", "justifyText", False)
) )
self.textForm.addWidget(QLabel("Font family"), 0, 0, 1, 1, Qt.AlignLeft) self.noStyling = QSwitch()
self.textForm.addWidget(self.textFont, 0, 1, 1, 1, Qt.AlignRight) self.noStyling.setToolTip(
self.textForm.addWidget(self.fontButton, 0, 2, 1, 1, Qt.AlignRight) "Disable all styling of the text."
self.textForm.addWidget(QLabel("Font size"), 1, 0, 1, 1, Qt.AlignLeft) )
self.textForm.addWidget(self.textSize, 1, 1, 1, 2, Qt.AlignRight) self.noStyling.setChecked(
self.textForm.addWidget(QLabel("Justify text"), 2, 0, 1, 1, Qt.AlignLeft) self.optState.getBool("GuiBuildNovel", "noStyling", False)
self.textForm.addWidget(self.justifyText, 2, 1, 1, 2, Qt.AlignRight) )
self.textForm.addWidget(QLabel("Font family"), 0, 0, 1, 1, Qt.AlignLeft)
self.textForm.addWidget(self.textFont, 0, 1, 1, 1, Qt.AlignRight)
self.textForm.addWidget(self.fontButton, 0, 2, 1, 1, Qt.AlignRight)
self.textForm.addWidget(QLabel("Font size"), 1, 0, 1, 1, Qt.AlignLeft)
self.textForm.addWidget(self.textSize, 1, 1, 1, 2, Qt.AlignRight)
self.textForm.addWidget(QLabel("Justify text"), 2, 0, 1, 1, Qt.AlignLeft)
self.textForm.addWidget(self.justifyText, 2, 1, 1, 2, Qt.AlignRight)
self.textForm.addWidget(QLabel("Disable styling"), 3, 0, 1, 1, Qt.AlignLeft)
self.textForm.addWidget(self.noStyling, 3, 1, 1, 2, Qt.AlignRight)
self.textForm.setColumnStretch(0, 1) self.textForm.setColumnStretch(0, 1)
self.textForm.setColumnStretch(1, 0) self.textForm.setColumnStretch(1, 0)
@@ -305,7 +315,7 @@ class GuiBuildNovel(QDialog):
# ============ # ============
self.buildProgress = QProgressBar() self.buildProgress = QProgressBar()
self.buildNovel = QPushButton("Build Novel Project") self.buildNovel = QPushButton("Build Project")
self.buildNovel.clicked.connect(self._buildPreview) self.buildNovel.clicked.connect(self._buildPreview)
# Action Buttons # Action Buttons
@@ -390,7 +400,10 @@ class GuiBuildNovel(QDialog):
justifyText = self.justifyText.isChecked() justifyText = self.justifyText.isChecked()
self.docView.setTextFont(textFont, textSize) self.docView.setTextFont(textFont, textSize)
self.docView.setJustify(justifyText) self.docView.setJustify(justifyText)
self.docView.setStyleSheet(self.htmlStyle) if self.noStyling.isChecked():
self.docView.clearStyleSheet()
else:
self.docView.setStyleSheet(self.htmlStyle)
self.docView.setContent(self.htmlText) self.docView.setContent(self.htmlText)
else: else:
self.htmlText = [] self.htmlText = []
@@ -414,6 +427,7 @@ class GuiBuildNovel(QDialog):
fmtScene = self.fmtScene.text().strip() fmtScene = self.fmtScene.text().strip()
fmtSection = self.fmtSection.text().strip() fmtSection = self.fmtSection.text().strip()
justifyText = self.justifyText.isChecked() justifyText = self.justifyText.isChecked()
noStyling = self.noStyling.isChecked()
textFont = self.textFont.text() textFont = self.textFont.text()
textSize = self.textSize.value() textSize = self.textSize.value()
incSynopsis = self.includeSynopsis.isChecked() incSynopsis = self.includeSynopsis.isChecked()
@@ -435,6 +449,7 @@ class GuiBuildNovel(QDialog):
makeHtml.setComments(incComments) makeHtml.setComments(incComments)
makeHtml.setKeywords(incKeywords) makeHtml.setKeywords(incKeywords)
makeHtml.setJustify(justifyText) makeHtml.setJustify(justifyText)
makeHtml.setStyles(not noStyling)
# Make sure the tree order is correct # Make sure the tree order is correct
self.theParent.treeView.saveTreeOrder() self.theParent.treeView.saveTreeOrder()
@@ -481,7 +496,10 @@ class GuiBuildNovel(QDialog):
# Load the preview document with the html data # Load the preview document with the html data
self.docView.setTextFont(textFont, textSize) self.docView.setTextFont(textFont, textSize)
self.docView.setJustify(justifyText) self.docView.setJustify(justifyText)
self.docView.setStyleSheet(self.htmlStyle) if noStyling:
self.docView.clearStyleSheet()
else:
self.docView.setStyleSheet(self.htmlStyle)
self.docView.setContent(self.htmlText) self.docView.setContent(self.htmlText)
self._saveCache() self._saveCache()
@@ -843,6 +861,7 @@ class GuiBuildNovel(QDialog):
self.optState.setValue("GuiBuildNovel", "winWidth", self.width()) self.optState.setValue("GuiBuildNovel", "winWidth", self.width())
self.optState.setValue("GuiBuildNovel", "winHeight", self.height()) self.optState.setValue("GuiBuildNovel", "winHeight", self.height())
self.optState.setValue("GuiBuildNovel", "justifyText", self.justifyText.isChecked()) self.optState.setValue("GuiBuildNovel", "justifyText", self.justifyText.isChecked())
self.optState.setValue("GuiBuildNovel", "noStyling", self.noStyling.isChecked())
self.optState.setValue("GuiBuildNovel", "textFont", self.textFont.text()) self.optState.setValue("GuiBuildNovel", "textFont", self.textFont.text())
self.optState.setValue("GuiBuildNovel", "textSize", self.textSize.value()) self.optState.setValue("GuiBuildNovel", "textSize", self.textSize.value())
self.optState.setValue("GuiBuildNovel", "addNovel", self.novelFiles.isChecked()) self.optState.setValue("GuiBuildNovel", "addNovel", self.novelFiles.isChecked())
@@ -950,4 +969,10 @@ class GuiBuildNovelDocView(QTextBrowser):
return return
def clearStyleSheet(self):
"""Clears the document stylesheet.
"""
self.qDocument.setDefaultStyleSheet("")
return
# END Class GuiBuildNovelDocView # END Class GuiBuildNovelDocView