Now the page breaks render properly on print

This commit is contained in:
Veronica K. B. Olsen
2020-05-23 19:30:01 +02:00
parent a5729cf0a9
commit cf58823f37
4 changed files with 81 additions and 59 deletions
+20 -25
View File
@@ -148,30 +148,26 @@ class ToHtml(Tokenizer):
# 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_AV:
# aStyle.append("page-break-before: left;") aStyle.append("page-break-before: avoid;")
# if tStyle & self.A_PBB_R: if tStyle & self.A_PBB_NO:
# aStyle.append("page-break-before: right;") aStyle.append("page-break-before: never;")
# if tStyle & self.A_PBB_AV: if tStyle & self.A_PBA:
# aStyle.append("page-break-before: avoid;") aStyle.append("page-break-after: always;")
# if tStyle & self.A_PBA: if tStyle & self.A_PBA_AV:
# aStyle.append("page-break-after: always;") aStyle.append("page-break-after: avoid;")
# if tStyle & self.A_PBA_L: if tStyle & self.A_PBA_NO:
# aStyle.append("page-break-after: left;") aStyle.append("page-break-after: never;")
# if tStyle & self.A_PBA_R:
# aStyle.append("page-break-after: right;")
# if tStyle & self.A_PBA_AV:
# aStyle.append("page-break-after: avoid;")
if len(aStyle) > 0: if len(aStyle) > 0:
hStyle = " style='%s'" % (" ".join(aStyle)) hStyle = " style='%s'" % (" ".join(aStyle))
@@ -195,7 +191,7 @@ class ToHtml(Tokenizer):
elif tType == self.T_TITLE: elif tType == self.T_TITLE:
tHead = tText.replace(r"\\", "<br/>") tHead = tText.replace(r"\\", "<br/>")
tmpResult.append("<header class='title'%s>%s</header>\n" % (hStyle, tHead)) tmpResult.append("<h1 class='title'%s>%s</h1>\n" % (hStyle, tHead))
elif tType == self.T_HEAD1: elif tType == self.T_HEAD1:
tHead = tText.replace(r"\\", "<br/>") tHead = tText.replace(r"\\", "<br/>")
@@ -258,8 +254,7 @@ class ToHtml(Tokenizer):
theStyles.append(r"h1, h2 {color: rgb(66, 113, 174);}") theStyles.append(r"h1, h2 {color: rgb(66, 113, 174);}")
theStyles.append(r"h3, h4 {color: rgb(50, 50, 50);}") 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, 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;}")
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".tags {color: rgb(245, 135, 31); font-weight: bold;}")
theStyles.append(r".break {text-align: left;}") theStyles.append(r".break {text-align: left;}")
theStyles.append(r".sep {text-align: center; margin-top: 1em; margin-bottom: 1em;}") theStyles.append(r".sep {text-align: center; margin-top: 1em; margin-bottom: 1em;}")
+40 -30
View File
@@ -60,14 +60,17 @@ class Tokenizer():
T_SEP = 11 # Scene separator T_SEP = 11 # Scene separator
T_SKIP = 12 # Paragraph break T_SKIP = 12 # Paragraph break
A_NONE = 0 # No special style
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 always
A_PBB_AV = 32 # Page break, avoid A_PBB_AV = 32 # Page break before avoid
A_PBA = 64 # Page break after A_PBB_NO = 64 # Page break before never
A_PBA_AV = 128 # Page break, avoid A_PBA = 128 # Page break after always
A_PBA_AV = 256 # Page break after avoid
A_PBA_NO = 512 # Page break after avoid
def __init__(self, theProject, theParent): def __init__(self, theProject, theParent):
@@ -288,7 +291,7 @@ class Tokenizer():
# Tag lines starting with specific characters # Tag lines starting with specific characters
if len(aLine.strip()) == 0: if len(aLine.strip()) == 0:
self.theTokens.append(( self.theTokens.append((
self.T_EMPTY, "", None, None self.T_EMPTY, "", None, self.A_NONE
)) ))
tmpMarkdown.append("\n") tmpMarkdown.append("\n")
@@ -296,45 +299,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, None self.T_SYNOPSIS, cLine[9:].strip(), None, self.A_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, None self.T_COMMENT, aLine[1:].strip(), None, self.A_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, None self.T_KEYWORD, aLine[1:].strip(), None, self.A_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, None self.T_HEAD1, aLine[2:].strip(), None, self.A_PBB
)) ))
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, None self.T_HEAD2, aLine[3:].strip(), None, self.A_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, None self.T_HEAD3, aLine[4:].strip(), None, self.A_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, None self.T_HEAD4, aLine[5:].strip(), None, self.A_NONE
)) ))
tmpMarkdown.append("%s\n" % aLine) tmpMarkdown.append("%s\n" % aLine)
@@ -359,13 +362,13 @@ class Tokenizer():
# sorted by position # sorted by position
fmtPos = sorted(fmtPos, key=itemgetter(0)) fmtPos = sorted(fmtPos, key=itemgetter(0))
self.theTokens.append(( self.theTokens.append((
self.T_TEXT, aLine, fmtPos, None self.T_TEXT, aLine, fmtPos, self.A_NONE
)) ))
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
self.theTokens.append(( self.theTokens.append((
self.T_EMPTY, "", None, None self.T_EMPTY, "", None, self.A_NONE
)) ))
tmpMarkdown.append("\n") tmpMarkdown.append("\n")
@@ -402,7 +405,7 @@ class Tokenizer():
tText = self._formatHeading(self.fmtTitle, tText) tText = self._formatHeading(self.fmtTitle, tText)
self.theTokens[n] = ( self.theTokens[n] = (
tType, tText, None, None tType, tText, None, self.A_NONE
) )
elif tType == self.T_HEAD2: elif tType == self.T_HEAD2:
@@ -418,7 +421,7 @@ class Tokenizer():
# Format the chapter header # Format the chapter header
self.theTokens[n] = ( self.theTokens[n] = (
tType, tText, None, None tType, tText, None, self.A_PBB
) )
# Set scene variables # Set scene variables
@@ -435,21 +438,21 @@ class Tokenizer():
tTemp = self._formatHeading(self.fmtScene, tText) tTemp = self._formatHeading(self.fmtScene, tText)
if tTemp == "" and self.hideScene: if tTemp == "" and self.hideScene:
self.theTokens[n] = ( self.theTokens[n] = (
self.T_EMPTY, "", None, None self.T_EMPTY, "", None, self.A_NONE
) )
elif tTemp == "" and not self.hideScene: elif tTemp == "" and not self.hideScene:
if self.firstScene: if self.firstScene:
self.theTokens[n] = ( self.theTokens[n] = (
self.T_EMPTY, "", None, None self.T_EMPTY, "", None, self.A_NONE
) )
else: else:
self.theTokens[n] = ( self.theTokens[n] = (
self.T_SKIP, "", None, None self.T_SKIP, "", None, self.A_NONE
) )
elif tTemp == self.fmtScene: elif tTemp == self.fmtScene:
if self.firstScene: if self.firstScene:
self.theTokens[n] = ( self.theTokens[n] = (
self.T_EMPTY, "", None, None self.T_EMPTY, "", None, self.A_NONE
) )
else: else:
self.theTokens[n] = ( self.theTokens[n] = (
@@ -457,7 +460,7 @@ class Tokenizer():
) )
else: else:
self.theTokens[n] = ( self.theTokens[n] = (
tType, tTemp, None, None tType, tTemp, None, self.A_NONE
) )
# Definitely no longer the first scene # Definitely no longer the first scene
@@ -470,11 +473,11 @@ class Tokenizer():
tTemp = self._formatHeading(self.fmtSection, tText) tTemp = self._formatHeading(self.fmtSection, tText)
if tTemp == "" and self.hideSection: if tTemp == "" and self.hideSection:
self.theTokens[n] = ( self.theTokens[n] = (
self.T_EMPTY, "", None, None self.T_EMPTY, "", None, self.A_NONE
) )
elif tTemp == "" and not self.hideSection: elif tTemp == "" and not self.hideSection:
self.theTokens[n] = ( self.theTokens[n] = (
self.T_SKIP, "", None, None self.T_SKIP, "", None, self.A_NONE
) )
elif tTemp == self.fmtSection: elif tTemp == self.fmtSection:
self.theTokens[n] = ( self.theTokens[n] = (
@@ -482,7 +485,7 @@ class Tokenizer():
) )
else: else:
self.theTokens[n] = ( self.theTokens[n] = (
tType, tTemp, None, None tType, tTemp, None, self.A_NONE
) )
# For title page and partitions, we need to centre all text. # For title page and partitions, we need to centre all text.
@@ -494,12 +497,19 @@ class Tokenizer():
tType = tToken[0] tType = tToken[0]
tText = tToken[1] tText = tToken[1]
tFormat = tToken[2] tFormat = tToken[2]
if self.isTitle: if tType == self.T_HEAD1:
if tType == self.T_HEAD1: if self.isTitle:
tType = self.T_TITLE self.theTokens[n] = (
self.theTokens[n] = ( self.T_TITLE, tText, tFormat, self.A_PBB_NO | self.A_CENTRE
tType, tText, tFormat, self.A_CENTRE )
) else:
self.theTokens[n] = (
tType, tText, tFormat, self.A_PBB | self.A_CENTRE
)
else:
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
@@ -0,0 +1,4 @@
%%~ edca4be2fcaf8:7031beac91f75:Part 1
# Part One
The first part.
+17 -4
View File
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.5" hexVersion="0x000500f0" fileVersion="1.0" saveCount="130" autoCount="17" timeStamp="2020-05-11 19:23:21"> <novelWriterXML appVersion="0.5.2" hexVersion="0x000502f0" fileVersion="1.0" saveCount="145" autoCount="18" timeStamp="2020-05-23 19:28:41">
<project> <project>
<name>Sample Project</name> <name>Sample Project</name>
<title>Sample Project</title> <title>Sample Project</title>
@@ -10,7 +10,7 @@
<settings> <settings>
<spellCheck>True</spellCheck> <spellCheck>True</spellCheck>
<autoOutline>True</autoOutline> <autoOutline>True</autoOutline>
<lastEdited>96b68994dfa3d</lastEdited> <lastEdited>636b6aa9b697b</lastEdited>
<lastViewed>6a2d6d5f4f401</lastViewed> <lastViewed>6a2d6d5f4f401</lastViewed>
<lastWordCount>875</lastWordCount> <lastWordCount>875</lastWordCount>
<autoReplace> <autoReplace>
@@ -44,7 +44,7 @@
<entry blue="175" green="0" red="117">Main</entry> <entry blue="175" green="0" red="117">Main</entry>
</importance> </importance>
</settings> </settings>
<content count="20"> <content count="21">
<item handle="7031beac91f75" order="0" parent="None"> <item handle="7031beac91f75" order="0" parent="None">
<name>Novel</name> <name>Novel</name>
<type>ROOT</type> <type>ROOT</type>
@@ -65,7 +65,20 @@
<paraCount>2</paraCount> <paraCount>2</paraCount>
<cursorPos>78</cursorPos> <cursorPos>78</cursorPos>
</item> </item>
<item handle="e7ded148d6e4a" order="1" parent="7031beac91f75"> <item handle="edca4be2fcaf8" order="1" parent="7031beac91f75">
<name>Part 1</name>
<type>FILE</type>
<class>NOVEL</class>
<status>New</status>
<expanded>False</expanded>
<exported>True</exported>
<layout>PARTITION</layout>
<charCount>0</charCount>
<wordCount>0</wordCount>
<paraCount>0</paraCount>
<cursorPos>0</cursorPos>
</item>
<item handle="e7ded148d6e4a" order="2" parent="7031beac91f75">
<name>A Folder</name> <name>A Folder</name>
<type>FOLDER</type> <type>FOLDER</type>
<class>NOVEL</class> <class>NOVEL</class>