Cleaned up html export
This commit is contained in:
+102
-39
@@ -48,20 +48,16 @@ class ToHtml(Tokenizer):
|
|||||||
"<" : "<",
|
"<" : "<",
|
||||||
">" : ">",
|
">" : ">",
|
||||||
"&" : "&",
|
"&" : "&",
|
||||||
"\t" : " ",
|
"\t" : " "*2,
|
||||||
nwUnicode.U_ENDASH : nwUnicode.H_ENDASH,
|
nwUnicode.U_ENDASH : nwUnicode.H_ENDASH,
|
||||||
nwUnicode.U_EMDASH : nwUnicode.H_EMDASH,
|
nwUnicode.U_EMDASH : nwUnicode.H_EMDASH,
|
||||||
nwUnicode.U_HELLIP : nwUnicode.H_HELLIP,
|
nwUnicode.U_HELLIP : nwUnicode.H_HELLIP,
|
||||||
nwUnicode.U_NBSP : nwUnicode.H_NBSP,
|
nwUnicode.U_NBSP : nwUnicode.H_NBSP,
|
||||||
}
|
}
|
||||||
self.revDict = dict(map(reversed, self.repDict.items()))
|
self.revDict = {}
|
||||||
|
self.reReplace = []
|
||||||
self.reReplace = re.compile(
|
self.reReverse = []
|
||||||
"|".join([re.escape(k) for k in self.repDict.keys()]), flags=re.DOTALL
|
self._buildRegEx()
|
||||||
)
|
|
||||||
self.reReverse = re.compile(
|
|
||||||
"|".join([re.escape(k) for k in self.revDict.keys()]), flags=re.DOTALL
|
|
||||||
)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -79,6 +75,7 @@ class ToHtml(Tokenizer):
|
|||||||
self.doKeywords = True
|
self.doKeywords = True
|
||||||
self.doComments = doComments
|
self.doComments = doComments
|
||||||
self.repDict["\t"] = " "*8
|
self.repDict["\t"] = " "*8
|
||||||
|
self._buildRegEx()
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -120,40 +117,61 @@ class ToHtml(Tokenizer):
|
|||||||
self.FMT_U_E : "</u>",
|
self.FMT_U_E : "</u>",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.isNovel and self.genMode != self.M_PREVIEW:
|
||||||
|
# For novel files for export, we bump the titles one level
|
||||||
|
# up, as this is more useful for printing and word processor
|
||||||
|
# imports.
|
||||||
|
h1 = "h1 class=\"title\""
|
||||||
|
h2 = "h1"
|
||||||
|
h3 = "h2"
|
||||||
|
h4 = "h3"
|
||||||
|
else:
|
||||||
|
h1 = "h1"
|
||||||
|
h2 = "h2"
|
||||||
|
h3 = "h3"
|
||||||
|
h4 = "h4"
|
||||||
|
|
||||||
|
alignHead = self.A_LEFT
|
||||||
|
if self.doJustify:
|
||||||
|
alignPar = self.A_JUSTIFY
|
||||||
|
else:
|
||||||
|
alignPar = self.A_LEFT
|
||||||
|
|
||||||
self.theResult = ""
|
self.theResult = ""
|
||||||
|
|
||||||
thisPar = []
|
thisPar = []
|
||||||
parStyle = None
|
parStyle = None
|
||||||
tmpResult = []
|
tmpResult = []
|
||||||
|
hasHardBreak = False
|
||||||
for tType, tText, tFormat, tStyle in self.theTokens:
|
for tType, tText, tFormat, tStyle in self.theTokens:
|
||||||
|
|
||||||
# Styles
|
# Styles
|
||||||
aStyle = []
|
aStyle = []
|
||||||
if tStyle is not None:
|
if tStyle is not None:
|
||||||
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:
|
||||||
aStyle.append("text-align: right;")
|
# aStyle.append("text-align: right;")
|
||||||
if tStyle & self.A_CENTRE:
|
if tStyle & self.A_CENTRE:
|
||||||
aStyle.append("text-align: center;")
|
aStyle.append("text-align: center;")
|
||||||
if tStyle & self.A_JUSTIFY:
|
# if tStyle & self.A_JUSTIFY:
|
||||||
aStyle.append("text-align: justify;")
|
# aStyle.append("text-align: justify;")
|
||||||
if tStyle & self.A_PBB:
|
# if tStyle & self.A_PBB:
|
||||||
aStyle.append("page-break-before: always;")
|
# aStyle.append("page-break-before: always;")
|
||||||
if tStyle & self.A_PBB_L:
|
# if tStyle & self.A_PBB_L:
|
||||||
aStyle.append("page-break-before: left;")
|
# aStyle.append("page-break-before: left;")
|
||||||
if tStyle & self.A_PBB_R:
|
# if tStyle & self.A_PBB_R:
|
||||||
aStyle.append("page-break-before: right;")
|
# aStyle.append("page-break-before: right;")
|
||||||
if tStyle & self.A_PBB_AV:
|
# if tStyle & self.A_PBB_AV:
|
||||||
aStyle.append("page-break-before: avoid;")
|
# aStyle.append("page-break-before: avoid;")
|
||||||
if tStyle & self.A_PBA:
|
# if tStyle & self.A_PBA:
|
||||||
aStyle.append("page-break-after: always;")
|
# aStyle.append("page-break-after: always;")
|
||||||
if tStyle & self.A_PBA_L:
|
# if tStyle & self.A_PBA_L:
|
||||||
aStyle.append("page-break-after: left;")
|
# aStyle.append("page-break-after: left;")
|
||||||
if tStyle & self.A_PBA_R:
|
# if tStyle & self.A_PBA_R:
|
||||||
aStyle.append("page-break-after: right;")
|
# aStyle.append("page-break-after: right;")
|
||||||
if tStyle & self.A_PBA_AV:
|
# if tStyle & self.A_PBA_AV:
|
||||||
aStyle.append("page-break-after: avoid;")
|
# aStyle.append("page-break-after: avoid;")
|
||||||
|
|
||||||
if len(aStyle) > 0:
|
if len(aStyle) > 0:
|
||||||
hStyle = " style='%s'" % (" ".join(aStyle))
|
hStyle = " style='%s'" % (" ".join(aStyle))
|
||||||
@@ -164,33 +182,42 @@ 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:
|
||||||
|
parClass = " class='break'"
|
||||||
|
else:
|
||||||
|
parClass = ""
|
||||||
if len(thisPar) > 0:
|
if len(thisPar) > 0:
|
||||||
tTemp = "".join(thisPar)
|
tTemp = "".join(thisPar)
|
||||||
tmpResult.append("<p%s>%s</p>\n" % (parStyle, tTemp.rstrip()))
|
tmpResult.append("<p%s%s>%s</p>\n" % (parStyle, parClass, tTemp.rstrip()))
|
||||||
thisPar = []
|
thisPar = []
|
||||||
parStyle = None
|
parStyle = None
|
||||||
|
hasHardBreak = False
|
||||||
|
|
||||||
|
elif tType == self.T_TITLE:
|
||||||
|
tHead = tText.replace(r"\\", "<br/>")
|
||||||
|
tmpResult.append("<header class='title'%s>%s</header>\n" % (hStyle, tHead))
|
||||||
|
|
||||||
elif tType == self.T_HEAD1:
|
elif tType == self.T_HEAD1:
|
||||||
tHead = tText.replace(r"\\", "<br/>")
|
tHead = tText.replace(r"\\", "<br/>")
|
||||||
tmpResult.append("<h1%s>%s</h1>\n" % (hStyle, tHead))
|
tmpResult.append("<%s%s>%s</%s>\n" % (h1, hStyle, tHead, h1))
|
||||||
|
|
||||||
elif tType == self.T_HEAD2:
|
elif tType == self.T_HEAD2:
|
||||||
tHead = tText.replace(r"\\", "<br/>")
|
tHead = tText.replace(r"\\", "<br/>")
|
||||||
tmpResult.append("<h2%s>%s</h2>\n" % (hStyle, tHead))
|
tmpResult.append("<%s%s>%s</%s>\n" % (h2, hStyle, tHead, h2))
|
||||||
|
|
||||||
elif tType == self.T_HEAD3:
|
elif tType == self.T_HEAD3:
|
||||||
tHead = tText.replace(r"\\", "<br/>")
|
tHead = tText.replace(r"\\", "<br/>")
|
||||||
tmpResult.append("<h3%s>%s</h3>\n" % (hStyle, tHead))
|
tmpResult.append("<%s%s>%s</%s>\n" % (h3, hStyle, tHead, h3))
|
||||||
|
|
||||||
elif tType == self.T_HEAD4:
|
elif tType == self.T_HEAD4:
|
||||||
tHead = tText.replace(r"\\", "<br/>")
|
tHead = tText.replace(r"\\", "<br/>")
|
||||||
tmpResult.append("<h4%s>%s</h4>\n" % (hStyle, tHead))
|
tmpResult.append("<%s%s>%s</%s>\n" % (h4, hStyle, tHead, h4))
|
||||||
|
|
||||||
elif tType == self.T_SEP:
|
elif tType == self.T_SEP:
|
||||||
tmpResult.append("<p%s>%s</p>\n" % (hStyle, tText))
|
tmpResult.append("<p class='sep'>%s</p>\n" % tText)
|
||||||
|
|
||||||
elif tType == self.T_SKIP:
|
elif tType == self.T_SKIP:
|
||||||
tmpResult.append("<p%s> </p>\n" % hStyle)
|
tmpResult.append("<p class='skip'> </p>\n")
|
||||||
|
|
||||||
elif tType == self.T_TEXT:
|
elif tType == self.T_TEXT:
|
||||||
tTemp = tText
|
tTemp = tText
|
||||||
@@ -200,6 +227,7 @@ class ToHtml(Tokenizer):
|
|||||||
tTemp = tTemp[:xPos]+htmlTags[xFmt]+tTemp[xPos+xLen:]
|
tTemp = tTemp[:xPos]+htmlTags[xFmt]+tTemp[xPos+xLen:]
|
||||||
if tText.endswith(" "):
|
if tText.endswith(" "):
|
||||||
thisPar.append(tTemp.rstrip()+"<br/>")
|
thisPar.append(tTemp.rstrip()+"<br/>")
|
||||||
|
hasHardBreak = True
|
||||||
else:
|
else:
|
||||||
thisPar.append(tTemp.rstrip()+" ")
|
thisPar.append(tTemp.rstrip()+" ")
|
||||||
|
|
||||||
@@ -217,6 +245,30 @@ class ToHtml(Tokenizer):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def getStylesheet(self):
|
||||||
|
"""Generate a stylesheet appropriate for the current settings.
|
||||||
|
"""
|
||||||
|
theStyles = []
|
||||||
|
|
||||||
|
if self.doJustify:
|
||||||
|
theStyles.append(r"p {text-align: justify;}")
|
||||||
|
else:
|
||||||
|
theStyles.append(r"p {text-align: left;}")
|
||||||
|
|
||||||
|
theStyles.append(r"h1, h2 {color: rgb(66, 113, 174);}")
|
||||||
|
theStyles.append(r"h3, h4 {color: rgb(50, 50, 50);}")
|
||||||
|
theStyles.append(r"h1, h2, h3, h4 {page-break-after: avoid;}")
|
||||||
|
theStyles.append(r"h1 {page-break-before: always;}")
|
||||||
|
theStyles.append(r".title {font-size: 2.5em; font-weight: bold; page-break-before: never;}")
|
||||||
|
theStyles.append(r".tags {color: rgb(245, 135, 31); font-weight: bold;}")
|
||||||
|
theStyles.append(r".break {text-align: left;}")
|
||||||
|
theStyles.append(r".sep {text-align: center; margin-top: 1em; margin-bottom: 1em;}")
|
||||||
|
theStyles.append(r".skip {margin-top: 1em; margin-bottom: 1em;}")
|
||||||
|
theStyles.append(r".synopsis {font-style: italic;}")
|
||||||
|
theStyles.append(r".comment {font-style: italic; color: rgb(100, 100, 100);}")
|
||||||
|
|
||||||
|
return theStyles
|
||||||
|
|
||||||
##
|
##
|
||||||
# Internal Functions
|
# Internal Functions
|
||||||
##
|
##
|
||||||
@@ -240,7 +292,6 @@ class ToHtml(Tokenizer):
|
|||||||
def _formatKeywords(self, tText):
|
def _formatKeywords(self, tText):
|
||||||
"""Apply HTML formatting to keywords.
|
"""Apply HTML formatting to keywords.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
tText = "@"+tText
|
tText = "@"+tText
|
||||||
isValid, theBits, thePos = self.theParent.theIndex.scanThis(tText)
|
isValid, theBits, thePos = self.theParent.theIndex.scanThis(tText)
|
||||||
if not isValid or not theBits:
|
if not isValid or not theBits:
|
||||||
@@ -270,4 +321,16 @@ class ToHtml(Tokenizer):
|
|||||||
|
|
||||||
return "<div>%s</div>" % retText
|
return "<div>%s</div>" % retText
|
||||||
|
|
||||||
|
def _buildRegEx(self):
|
||||||
|
"""Build the regular expressions
|
||||||
|
"""
|
||||||
|
self.revDict = dict(map(reversed, self.repDict.items()))
|
||||||
|
self.reReplace = re.compile(
|
||||||
|
"|".join([re.escape(k) for k in self.repDict.keys()]), flags=re.DOTALL
|
||||||
|
)
|
||||||
|
self.reReverse = re.compile(
|
||||||
|
"|".join([re.escape(k) for k in self.revDict.keys()]), flags=re.DOTALL
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
# END Class ToHtml
|
# END Class ToHtml
|
||||||
|
|||||||
+36
-46
@@ -51,26 +51,23 @@ class Tokenizer():
|
|||||||
T_SYNOPSIS = 2 # Synopsis comment
|
T_SYNOPSIS = 2 # Synopsis comment
|
||||||
T_COMMENT = 3 # Comment line
|
T_COMMENT = 3 # Comment line
|
||||||
T_KEYWORD = 4 # Command line
|
T_KEYWORD = 4 # Command line
|
||||||
T_HEAD1 = 5 # Header 1 (title)
|
T_TITLE = 5 # Title
|
||||||
T_HEAD2 = 6 # Header 2 (chapter)
|
T_HEAD1 = 6 # Header 1
|
||||||
T_HEAD3 = 7 # Header 3 (scene)
|
T_HEAD2 = 7 # Header 2
|
||||||
T_HEAD4 = 8 # Header 4
|
T_HEAD3 = 8 # Header 3
|
||||||
T_TEXT = 9 # Text line
|
T_HEAD4 = 9 # Header 4
|
||||||
T_SEP = 10 # Scene separator
|
T_TEXT = 10 # Text line
|
||||||
T_SKIP = 11 # Paragraph break
|
T_SEP = 11 # Scene separator
|
||||||
|
T_SKIP = 12 # Paragraph break
|
||||||
|
|
||||||
A_LEFT = 1 # Left aligned
|
A_LEFT = 1 # Left aligned
|
||||||
A_RIGHT = 2 # Right aligned
|
A_RIGHT = 2 # Right aligned
|
||||||
A_CENTRE = 4 # Centred
|
A_CENTRE = 4 # Centred
|
||||||
A_JUSTIFY = 8 # Justified
|
A_JUSTIFY = 8 # Justified
|
||||||
A_PBB = 16 # Page break before
|
A_PBB = 16 # Page break before
|
||||||
A_PBB_L = 32 # Page break before, left
|
A_PBB_AV = 32 # Page break, avoid
|
||||||
A_PBB_R = 64 # Page break before, right
|
A_PBA = 64 # Page break after
|
||||||
A_PBB_AV = 128 # Page break, avoid
|
A_PBA_AV = 128 # Page break, avoid
|
||||||
A_PBA = 256 # Page break after
|
|
||||||
A_PBA_L = 512 # Page break after, left
|
|
||||||
A_PBA_R = 1024 # Page break after, right
|
|
||||||
A_PBA_AV = 2048 # Page break, avoid
|
|
||||||
|
|
||||||
def __init__(self, theProject, theParent):
|
def __init__(self, theProject, theParent):
|
||||||
|
|
||||||
@@ -283,11 +280,6 @@ class Tokenizer():
|
|||||||
[None, self.FMT_U_B, None, self.FMT_U_E]
|
[None, self.FMT_U_B, None, self.FMT_U_E]
|
||||||
)]
|
)]
|
||||||
|
|
||||||
if self.doJustify:
|
|
||||||
defAlign = self.A_JUSTIFY
|
|
||||||
else:
|
|
||||||
defAlign = self.A_LEFT
|
|
||||||
|
|
||||||
self.theTokens = []
|
self.theTokens = []
|
||||||
self.theMarkdown = ""
|
self.theMarkdown = ""
|
||||||
tmpMarkdown = []
|
tmpMarkdown = []
|
||||||
@@ -304,45 +296,45 @@ class Tokenizer():
|
|||||||
cLine = aLine[1:].strip()
|
cLine = aLine[1:].strip()
|
||||||
if cLine.lower().startswith("synopsis:"):
|
if cLine.lower().startswith("synopsis:"):
|
||||||
self.theTokens.append((
|
self.theTokens.append((
|
||||||
self.T_SYNOPSIS, cLine[9:].strip(), None, defAlign
|
self.T_SYNOPSIS, cLine[9:].strip(), None, None
|
||||||
))
|
))
|
||||||
if self.doSynopsis:
|
if self.doSynopsis:
|
||||||
tmpMarkdown.append("%s\n" % aLine)
|
tmpMarkdown.append("%s\n" % aLine)
|
||||||
else:
|
else:
|
||||||
self.theTokens.append((
|
self.theTokens.append((
|
||||||
self.T_COMMENT, aLine[1:].strip(), None, defAlign
|
self.T_COMMENT, aLine[1:].strip(), None, None
|
||||||
))
|
))
|
||||||
if self.doComments:
|
if self.doComments:
|
||||||
tmpMarkdown.append("%s\n" % aLine)
|
tmpMarkdown.append("%s\n" % aLine)
|
||||||
|
|
||||||
elif aLine[0] == "@":
|
elif aLine[0] == "@":
|
||||||
self.theTokens.append((
|
self.theTokens.append((
|
||||||
self.T_KEYWORD, aLine[1:].strip(), None, self.A_LEFT
|
self.T_KEYWORD, aLine[1:].strip(), None, None
|
||||||
))
|
))
|
||||||
if self.doKeywords:
|
if self.doKeywords:
|
||||||
tmpMarkdown.append("%s\n" % aLine)
|
tmpMarkdown.append("%s\n" % aLine)
|
||||||
|
|
||||||
elif aLine[:2] == "# ":
|
elif aLine[:2] == "# ":
|
||||||
self.theTokens.append((
|
self.theTokens.append((
|
||||||
self.T_HEAD1, aLine[2:].strip(), None, self.A_LEFT | self.A_PBB
|
self.T_HEAD1, aLine[2:].strip(), None, None
|
||||||
))
|
))
|
||||||
tmpMarkdown.append("%s\n" % aLine)
|
tmpMarkdown.append("%s\n" % aLine)
|
||||||
|
|
||||||
elif aLine[:3] == "## ":
|
elif aLine[:3] == "## ":
|
||||||
self.theTokens.append((
|
self.theTokens.append((
|
||||||
self.T_HEAD2, aLine[3:].strip(), None, self.A_LEFT | self.A_PBA_AV
|
self.T_HEAD2, aLine[3:].strip(), None, None
|
||||||
))
|
))
|
||||||
tmpMarkdown.append("%s\n" % aLine)
|
tmpMarkdown.append("%s\n" % aLine)
|
||||||
|
|
||||||
elif aLine[:4] == "### ":
|
elif aLine[:4] == "### ":
|
||||||
self.theTokens.append((
|
self.theTokens.append((
|
||||||
self.T_HEAD3, aLine[4:].strip(), None, self.A_LEFT | self.A_PBA_AV
|
self.T_HEAD3, aLine[4:].strip(), None, None
|
||||||
))
|
))
|
||||||
tmpMarkdown.append("%s\n" % aLine)
|
tmpMarkdown.append("%s\n" % aLine)
|
||||||
|
|
||||||
elif aLine[:5] == "#### ":
|
elif aLine[:5] == "#### ":
|
||||||
self.theTokens.append((
|
self.theTokens.append((
|
||||||
self.T_HEAD4, aLine[5:].strip(), None, self.A_LEFT | self.A_PBA_AV
|
self.T_HEAD4, aLine[5:].strip(), None, None
|
||||||
))
|
))
|
||||||
tmpMarkdown.append("%s\n" % aLine)
|
tmpMarkdown.append("%s\n" % aLine)
|
||||||
|
|
||||||
@@ -366,14 +358,9 @@ class Tokenizer():
|
|||||||
# Save the line as is, but append the array of formatting locations
|
# Save the line as is, but append the array of formatting locations
|
||||||
# sorted by position
|
# sorted by position
|
||||||
fmtPos = sorted(fmtPos, key=itemgetter(0))
|
fmtPos = sorted(fmtPos, key=itemgetter(0))
|
||||||
if aLine.endswith(" "):
|
self.theTokens.append((
|
||||||
self.theTokens.append((
|
self.T_TEXT, aLine, fmtPos, None
|
||||||
self.T_TEXT, aLine, fmtPos, self.A_LEFT
|
))
|
||||||
))
|
|
||||||
else:
|
|
||||||
self.theTokens.append((
|
|
||||||
self.T_TEXT, aLine, fmtPos, defAlign
|
|
||||||
))
|
|
||||||
tmpMarkdown.append("%s\n" % aLine)
|
tmpMarkdown.append("%s\n" % aLine)
|
||||||
|
|
||||||
# Always add an empty line at the end
|
# Always add an empty line at the end
|
||||||
@@ -415,7 +402,7 @@ class Tokenizer():
|
|||||||
|
|
||||||
tText = self._formatHeading(self.fmtTitle, tText)
|
tText = self._formatHeading(self.fmtTitle, tText)
|
||||||
self.theTokens[n] = (
|
self.theTokens[n] = (
|
||||||
tType, tText, None, self.A_LEFT | self.A_PBB_R
|
tType, tText, None, None
|
||||||
)
|
)
|
||||||
|
|
||||||
elif tType == self.T_HEAD2:
|
elif tType == self.T_HEAD2:
|
||||||
@@ -431,7 +418,7 @@ class Tokenizer():
|
|||||||
|
|
||||||
# Format the chapter header
|
# Format the chapter header
|
||||||
self.theTokens[n] = (
|
self.theTokens[n] = (
|
||||||
tType, tText, None, self.A_LEFT | self.A_PBB_R
|
tType, tText, None, None
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set scene variables
|
# Set scene variables
|
||||||
@@ -470,7 +457,7 @@ class Tokenizer():
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.theTokens[n] = (
|
self.theTokens[n] = (
|
||||||
tType, tTemp, None, self.A_LEFT | self.A_PBA_AV
|
tType, tTemp, None, None
|
||||||
)
|
)
|
||||||
|
|
||||||
# Definitely no longer the first scene
|
# Definitely no longer the first scene
|
||||||
@@ -495,21 +482,24 @@ class Tokenizer():
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.theTokens[n] = (
|
self.theTokens[n] = (
|
||||||
tType, tTemp, None, self.A_LEFT | self.A_PBA_AV
|
tType, tTemp, None, None
|
||||||
)
|
)
|
||||||
|
|
||||||
# For title page and partitions, we need to centre all text.
|
# For title page and partitions, we need to centre all text.
|
||||||
# For partition, we also add a page break before, and for
|
# For partition, we also add a page break before, and for
|
||||||
# both types we always add a page break after the content.
|
# both types we always add a page break after the content.
|
||||||
|
# We also swap header level 1 with a title type instead.
|
||||||
if self.isTitle or self.isPart:
|
if self.isTitle or self.isPart:
|
||||||
for n, tToken in enumerate(self.theTokens):
|
for n, tToken in enumerate(self.theTokens):
|
||||||
tType = tToken[0]
|
tType = tToken[0]
|
||||||
tText = tToken[1]
|
tText = tToken[1]
|
||||||
tFormat = tToken[2]
|
tFormat = tToken[2]
|
||||||
if self.isTitle:
|
if self.isTitle:
|
||||||
self.theTokens[n] = (
|
if tType == self.T_HEAD1:
|
||||||
tType, tText, tFormat, self.A_CENTRE
|
tType = self.T_TITLE
|
||||||
)
|
self.theTokens[n] = (
|
||||||
|
tType, tText, tFormat, self.A_CENTRE
|
||||||
|
)
|
||||||
|
|
||||||
# Add a page break after the last entry
|
# Add a page break after the last entry
|
||||||
n = len(self.theTokens) - 1
|
n = len(self.theTokens) - 1
|
||||||
|
|||||||
+28
-29
@@ -70,6 +70,7 @@ class GuiBuildNovel(QDialog):
|
|||||||
self.optState = self.theProject.optState
|
self.optState = self.theProject.optState
|
||||||
|
|
||||||
self.htmlText = [] # List of html document
|
self.htmlText = [] # List of html document
|
||||||
|
self.htmlStyle = [] # List of html styles
|
||||||
self.nwdText = [] # List of markdown documents
|
self.nwdText = [] # List of markdown documents
|
||||||
self.textLayout = [] # List of nwItemLayout entries
|
self.textLayout = [] # List of nwItemLayout entries
|
||||||
|
|
||||||
@@ -320,6 +321,7 @@ class GuiBuildNovel(QDialog):
|
|||||||
tStart = time()
|
tStart = time()
|
||||||
|
|
||||||
self.htmlText = []
|
self.htmlText = []
|
||||||
|
self.htmlStyle = []
|
||||||
self.nwdText = []
|
self.nwdText = []
|
||||||
self.textLayout = []
|
self.textLayout = []
|
||||||
|
|
||||||
@@ -340,9 +342,11 @@ class GuiBuildNovel(QDialog):
|
|||||||
|
|
||||||
tEnd = time()
|
tEnd = time()
|
||||||
logger.debug("Built project in %.3f ms" % (1000*(tEnd-tStart)))
|
logger.debug("Built project in %.3f ms" % (1000*(tEnd-tStart)))
|
||||||
|
self.htmlStyle = makeHtml.getStylesheet()
|
||||||
|
|
||||||
# Load the preview document with the html data
|
# Load the preview document with the html data
|
||||||
self.docView.setHtml("".join(self.htmlText))
|
self.docView.setStyleSheet(self.htmlStyle)
|
||||||
|
self.docView.setContent(self.htmlText)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -484,6 +488,9 @@ class GuiBuildNovel(QDialog):
|
|||||||
outFile.write("<head>\n")
|
outFile.write("<head>\n")
|
||||||
outFile.write("<meta charset='utf-8'>\n")
|
outFile.write("<meta charset='utf-8'>\n")
|
||||||
outFile.write("</head>\n")
|
outFile.write("</head>\n")
|
||||||
|
outFile.write("<style>\n")
|
||||||
|
outFile.write("%s\n" % "\n".join(self.htmlStyle))
|
||||||
|
outFile.write("</style>\n")
|
||||||
outFile.write("<body>\n")
|
outFile.write("<body>\n")
|
||||||
outFile.write("<article style='width: 800px; margin: 40px auto'>\n")
|
outFile.write("<article style='width: 800px; margin: 40px auto'>\n")
|
||||||
for aLine in self.htmlText:
|
for aLine in self.htmlText:
|
||||||
@@ -612,7 +619,8 @@ class GuiBuildNovel(QDialog):
|
|||||||
if path.isfile(docPath):
|
if path.isfile(docPath):
|
||||||
with open(docPath, mode="r", encoding="utf8") as inFile:
|
with open(docPath, mode="r", encoding="utf8") as inFile:
|
||||||
helpText = inFile.read()
|
helpText = inFile.read()
|
||||||
self.docView.setText(helpText)
|
self.docView.setStyleSheet()
|
||||||
|
self.docView.setContent(helpText)
|
||||||
else:
|
else:
|
||||||
self.theParent.makeAlert(
|
self.theParent.makeAlert(
|
||||||
"Could not open help text file for Build Project.", nwAlert.ERROR
|
"Could not open help text file for Build Project.", nwAlert.ERROR
|
||||||
@@ -648,7 +656,7 @@ class GuiBuildNovelDocView(QTextBrowser):
|
|||||||
docPalette.setColor(QPalette.Text, QColor( 0, 0, 0))
|
docPalette.setColor(QPalette.Text, QColor( 0, 0, 0))
|
||||||
self.setPalette(docPalette)
|
self.setPalette(docPalette)
|
||||||
|
|
||||||
self._makeStyleSheet()
|
self.setStyleSheet()
|
||||||
|
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
@@ -656,35 +664,26 @@ class GuiBuildNovelDocView(QTextBrowser):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def setText(self, theText):
|
def setContent(self, theText):
|
||||||
self.setHtml(theText)
|
"""Set the content, either from text or list of text.
|
||||||
|
"""
|
||||||
|
if isinstance(theText, str):
|
||||||
|
self.setHtml(theText)
|
||||||
|
else:
|
||||||
|
self.setHtml("".join(theText))
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
def setStyleSheet(self, theStyles=[]):
|
||||||
# Internal Functions
|
"""Set the stylesheet for the preview document.
|
||||||
##
|
"""
|
||||||
|
if not theStyles:
|
||||||
|
theStyles.append(r"h1, h2 {color: rgb(66, 113, 174);}")
|
||||||
|
theStyles.append(r"h3, h4 {color: rgb(50, 50, 50);}")
|
||||||
|
theStyles.append(r"a {color: rgb(137, 89, 168);}")
|
||||||
|
theStyles.append(r"mark {background-color: rgb(240, 198, 116);}")
|
||||||
|
theStyles.append(r".tags {color: rgb(245, 135, 31); font-weight: bold;}")
|
||||||
|
|
||||||
def _makeStyleSheet(self):
|
self.qDocument.setDefaultStyleSheet("\n".join(theStyles))
|
||||||
|
|
||||||
styleSheet = (
|
|
||||||
"h1, h2 {"
|
|
||||||
" color: rgb(66, 113, 174);"
|
|
||||||
"}\n"
|
|
||||||
"h3, h4 {"
|
|
||||||
" color: rgb(50, 50, 50);"
|
|
||||||
"}\n"
|
|
||||||
"a {"
|
|
||||||
" color: rgb(137, 89, 168);"
|
|
||||||
"}\n"
|
|
||||||
"mark {"
|
|
||||||
" background-color: rgb(240, 198, 116);"
|
|
||||||
"}\n"
|
|
||||||
".tags {"
|
|
||||||
" color: rgb(245, 135, 31);"
|
|
||||||
" font-wright: bold;"
|
|
||||||
"}\n"
|
|
||||||
)
|
|
||||||
self.qDocument.setDefaultStyleSheet(styleSheet)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user