Improved the html export a bit, with a max width and comments formatted as yellow notes

This commit is contained in:
Veronica K. B. Olsen
2019-10-27 14:18:01 +01:00
parent fde7975a0b
commit 25c92d8b2e
3 changed files with 29 additions and 18 deletions
+12 -1
View File
@@ -39,10 +39,20 @@ class HtmlFile(TextFile):
self.outFile.write("<html>\n") self.outFile.write("<html>\n")
self.outFile.write("<head>\n") self.outFile.write("<head>\n")
self.outFile.write("<style>\n") self.outFile.write("<style>\n")
self.outFile.write(" pre {background-color: #ffff99;}\n") self.outFile.write(" #page {\n")
self.outFile.write(" margin: 40px auto;\n")
self.outFile.write(" max-width: 769px;\n")
self.outFile.write(" }\n")
self.outFile.write(" .comment {\n")
self.outFile.write(" background-color: #fbfabd;\n")
self.outFile.write(" border: 1px solid #b4b000;\n")
self.outFile.write(" margin: 10px 20px;\n")
self.outFile.write(" padding: 6px;\n")
self.outFile.write(" }\n")
self.outFile.write("</style>\n") self.outFile.write("</style>\n")
self.outFile.write("</head>\n") self.outFile.write("</head>\n")
self.outFile.write("<body>\n") self.outFile.write("<body>\n")
self.outFile.write("<article id='page'>\n")
except Exception as e: except Exception as e:
self.makeAlert(["Failed to open file.",str(e)], nwAlert.ERROR) self.makeAlert(["Failed to open file.",str(e)], nwAlert.ERROR)
return False return False
@@ -50,6 +60,7 @@ class HtmlFile(TextFile):
def _doCloseFile(self): def _doCloseFile(self):
if self.outFile is not None: if self.outFile is not None:
self.outFile.write("</article>\n")
self.outFile.write("</body>\n") self.outFile.write("</body>\n")
self.outFile.write("</html>\n") self.outFile.write("</html>\n")
self.outFile.close() self.outFile.close()
+1 -1
View File
@@ -92,7 +92,7 @@ class ToHtml(Tokenizer):
thisPar.append(tTemp) thisPar.append(tTemp)
elif tType == self.T_COMMENT and self.doComments: elif tType == self.T_COMMENT and self.doComments:
self.theResult += "<pre>%s</pre>\n" % tText self.theResult += "<div class='comment'>%s</div>\n" % tText
elif tType == self.T_COMMAND and self.doCommands: elif tType == self.T_COMMAND and self.doCommands:
self.theResult += "<pre>%s</pre>\n" % tText self.theResult += "<pre>%s</pre>\n" % tText
+16 -16
View File
@@ -209,23 +209,27 @@ class GuiExport(QDialog):
class GuiExportMain(QWidget): class GuiExportMain(QWidget):
FMT_TXT = 1 # Plain text file FMT_NWD = 1 # novelWriter markdown
FMT_MD = 2 # Markdown file FMT_TXT = 2 # Plain text file
FMT_HTML = 3 # HTML file FMT_MD = 3 # Markdown file
FMT_EBOOK = 4 # E-book friendly HTML FMT_HTML = 4 # HTML file
FMT_ODT = 5 # Open document FMT_EBOOK = 5 # E-book friendly HTML
FMT_TEX = 6 # LaTeX file FMT_ODT = 6 # Open document
FMT_NWD = 7 # novelWriter markdown FMT_TEX = 7 # LaTeX file
FMT_EXT = { FMT_EXT = {
FMT_NWD : ".nwd",
FMT_TXT : ".txt", FMT_TXT : ".txt",
FMT_MD : ".md", FMT_MD : ".md",
FMT_HTML : ".htm", FMT_HTML : ".htm",
FMT_EBOOK : ".htm", FMT_EBOOK : ".htm",
FMT_ODT : ".odt", FMT_ODT : ".odt",
FMT_TEX : ".tex", FMT_TEX : ".tex",
FMT_NWD : ".nwd",
} }
FMT_HELP = { FMT_HELP = {
FMT_NWD : (
"Exports a document using the novelWriter markdown format. "
"The files selected by the filters are appended as-is, including comments and other settings."
),
FMT_TXT : ( FMT_TXT : (
"Exports a plain text file. " "Exports a plain text file. "
"All formatting is stripped and comments are in square brackets." "All formatting is stripped and comments are in square brackets."
@@ -236,7 +240,7 @@ class GuiExportMain(QWidget):
), ),
FMT_HTML : ( FMT_HTML : (
"Exports a plain html5 file. " "Exports a plain html5 file. "
"Comments are converted to preformatted text blocks." "Comments are wrapped in blocks with a yellow background colour."
), ),
FMT_EBOOK : ( FMT_EBOOK : (
"Exports an html5 file that can be converted to eBook with Calibre. " "Exports an html5 file that can be converted to eBook with Calibre. "
@@ -250,10 +254,6 @@ class GuiExportMain(QWidget):
"Exports a LaTeX file that can be compiled to PDF using for instance PDFLaTeX. " "Exports a LaTeX file that can be compiled to PDF using for instance PDFLaTeX. "
"Comments are exported as LaTeX comments." "Comments are exported as LaTeX comments."
), ),
FMT_NWD : (
"Exports a document using the novelWriter markdown format. "
"The files selected by the filters are appended as-is."
),
} }
def __init__(self, theParent, theProject, optState): def __init__(self, theParent, theProject, optState):
@@ -355,13 +355,13 @@ class GuiExportMain(QWidget):
self.outputHelp.setAlignment(Qt.AlignTop) self.outputHelp.setAlignment(Qt.AlignTop)
self.outputFormat = QComboBox(self) self.outputFormat = QComboBox(self)
self.outputFormat.addItem("novelWriter Markdown (.nwd)", self.FMT_NWD)
self.outputFormat.addItem("Plain Text (.txt)", self.FMT_TXT) self.outputFormat.addItem("Plain Text (.txt)", self.FMT_TXT)
self.outputFormat.addItem("Markdown (.md)", self.FMT_MD) self.outputFormat.addItem("Markdown (.md)", self.FMT_MD)
self.outputFormat.addItem("HTML5 (.htm)", self.FMT_HTML) self.outputFormat.addItem("HTML5 (.htm)", self.FMT_HTML)
# self.outputFormat.addItem("HTML5 for eBook (.htm)", self.FMT_EBOOK) # self.outputFormat.addItem("HTML5 for eBook (.htm)", self.FMT_EBOOK)
# self.outputFormat.addItem("Open Document (.odt)", self.FMT_ODT) # self.outputFormat.addItem("Open Document (.odt)", self.FMT_ODT)
self.outputFormat.addItem("LaTeX for PDF (.tex)", self.FMT_TEX) self.outputFormat.addItem("LaTeX for PDF (.tex)", self.FMT_TEX)
self.outputFormat.addItem("novelWriter Markdown (.nwd)", self.FMT_NWD)
self.outputFormat.currentIndexChanged.connect(self._updateFormat) self.outputFormat.currentIndexChanged.connect(self._updateFormat)
optIdx = self.outputFormat.findData(self.optState.getSetting("eFormat")) optIdx = self.outputFormat.findData(self.optState.getSetting("eFormat"))
@@ -426,12 +426,12 @@ class GuiExportMain(QWidget):
currDir = "" currDir = ""
extFilter = [ extFilter = [
"novelWriter document files (*.nwd)",
"Text files (*.txt)", "Text files (*.txt)",
"Markdown files (*.md)", "Markdown files (*.md)",
"HTML files (*.htm *.html)", "HTML files (*.htm *.html)",
# "Open document files (*.odt)", # "Open document files (*.odt)",
"LaTeX files (*.tex)", "LaTeX files (*.tex)",
"novelWriter document files (*.nwd)",
"All files (*.*)", "All files (*.*)",
] ]
@@ -465,7 +465,7 @@ class ExportLastState(OptLastState):
self.theState = { self.theState = {
"wNovel" : True, "wNovel" : True,
"wNotes" : False, "wNotes" : False,
"eFormat" : 2, "eFormat" : 1,
"fixWidth" : 80, "fixWidth" : 80,
"wComments" : False, "wComments" : False,
"chFormat" : "Chapter %numword%", "chFormat" : "Chapter %numword%",