Fix default alignment

This commit is contained in:
Veronica Berglyd Olsen
2021-06-09 23:05:16 +02:00
parent 7d067f807d
commit 6f9e3168b0
3 changed files with 41 additions and 33 deletions
+28 -22
View File
@@ -366,6 +366,12 @@ class Tokenizer():
(QRegularExpression(nwRegEx.FMT_ST), [None, self.FMT_D_B, None, self.FMT_D_E]), (QRegularExpression(nwRegEx.FMT_ST), [None, self.FMT_D_B, None, self.FMT_D_E]),
] ]
# Determine default text alignment
if self.isTitle or self.isPart:
defAlign = self.A_CENTRE
else:
defAlign = self.A_NONE
self.theTokens = [] self.theTokens = []
tmpMarkdown = [] tmpMarkdown = []
nLine = 0 nLine = 0
@@ -375,7 +381,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, nLine, "", None, self.A_NONE self.T_EMPTY, nLine, "", None, defAlign
)) ))
if self.keepMarkdown: if self.keepMarkdown:
tmpMarkdown.append("\n") tmpMarkdown.append("\n")
@@ -385,48 +391,48 @@ class Tokenizer():
synTag = cLine[:9].lower() synTag = cLine[:9].lower()
if synTag == "synopsis:": if synTag == "synopsis:":
self.theTokens.append(( self.theTokens.append((
self.T_SYNOPSIS, nLine, cLine[9:].strip(), None, self.A_NONE self.T_SYNOPSIS, nLine, cLine[9:].strip(), None, defAlign
)) ))
if self.doSynopsis and self.keepMarkdown: if self.doSynopsis and self.keepMarkdown:
tmpMarkdown.append("%s\n" % aLine) tmpMarkdown.append("%s\n" % aLine)
else: else:
self.theTokens.append(( self.theTokens.append((
self.T_COMMENT, nLine, aLine[1:].strip(), None, self.A_NONE self.T_COMMENT, nLine, aLine[1:].strip(), None, defAlign
)) ))
if self.doComments and self.keepMarkdown: if self.doComments and self.keepMarkdown:
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, nLine, aLine[1:].strip(), None, self.A_NONE self.T_KEYWORD, nLine, aLine[1:].strip(), None, defAlign
)) ))
if self.doKeywords and self.keepMarkdown: if self.doKeywords and self.keepMarkdown:
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, nLine, aLine[2:].strip(), None, self.A_NONE self.T_HEAD1, nLine, aLine[2:].strip(), None, defAlign
)) ))
if self.keepMarkdown: if self.keepMarkdown:
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, nLine, aLine[3:].strip(), None, self.A_NONE self.T_HEAD2, nLine, aLine[3:].strip(), None, defAlign
)) ))
if self.keepMarkdown: if self.keepMarkdown:
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, nLine, aLine[4:].strip(), None, self.A_NONE self.T_HEAD3, nLine, aLine[4:].strip(), None, defAlign
)) ))
if self.keepMarkdown: if self.keepMarkdown:
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, nLine, aLine[5:].strip(), None, self.A_NONE self.T_HEAD4, nLine, aLine[5:].strip(), None, defAlign
)) ))
if self.keepMarkdown: if self.keepMarkdown:
tmpMarkdown.append("%s\n" % aLine) tmpMarkdown.append("%s\n" % aLine)
@@ -453,7 +459,7 @@ class Tokenizer():
tagLeft = True tagLeft = True
aLine = aLine[:-8].rstrip() aLine = aLine[:-8].rstrip()
textAlign = self.A_NONE textAlign = defAlign
if tagLeft and tagRight: if tagLeft and tagRight:
textAlign = self.A_CENTRE textAlign = self.A_CENTRE
elif tagLeft: elif tagLeft:
@@ -484,7 +490,7 @@ class Tokenizer():
# 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, nLine, "", None, self.A_NONE self.T_EMPTY, nLine, "", None, defAlign
)) ))
if self.keepMarkdown: if self.keepMarkdown:
tmpMarkdown.append("\n") tmpMarkdown.append("\n")
@@ -496,8 +502,8 @@ class Tokenizer():
# =========== # ===========
# Some items need a second pass # Some items need a second pass
pToken = (self.T_EMPTY, 0, "", None, self.A_NONE) pToken = (self.T_EMPTY, 0, "", None, defAlign)
nToken = (self.T_EMPTY, 0, "", None, self.A_NONE) nToken = (self.T_EMPTY, 0, "", None, defAlign)
tCount = len(self.theTokens) tCount = len(self.theTokens)
for n, tToken in enumerate(self.theTokens): for n, tToken in enumerate(self.theTokens):
@@ -626,27 +632,27 @@ class Tokenizer():
tToken[0], tToken[1], tTemp, None, self.A_NONE tToken[0], tToken[1], tTemp, None, self.A_NONE
) )
# For title page and partitions, we need to centre all text. # For title page we use a different title class, and we will set
# For partition, we also add a page break before, and for # an automatic page break before (i.e. added if needed). For
# both types we always add a page break after the content. # partitions we always need a page break before.
# 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):
aStyle = tToken[4]
if n == 0:
if self.isTitle:
aStyle |= self.A_PBB_AUT
else:
aStyle |= self.A_PBB
if tToken[0] == self.T_HEAD1: if tToken[0] == self.T_HEAD1:
if self.isTitle: if self.isTitle:
aStyle = self.A_PBB_AUT | self.A_CENTRE
self.theTokens[n] = ( self.theTokens[n] = (
self.T_TITLE, tToken[1], tToken[2], tToken[3], aStyle self.T_TITLE, tToken[1], tToken[2], tToken[3], aStyle
) )
else: else:
aStyle = self.A_PBB | self.A_CENTRE
self.theTokens[n] = ( self.theTokens[n] = (
tToken[0], tToken[1], tToken[2], tToken[3], aStyle tToken[0], tToken[1], tToken[2], tToken[3], aStyle
) )
else:
self.theTokens[n] = (
tToken[0], tToken[1], tToken[2], tToken[3], 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
+3 -1
View File
@@ -5,4 +5,6 @@
**By Jane Doh** **By Jane Doh**
Its also possible to add some text on this page. Its also possible to add some text on this page. All text on Title and Partition pages are by default centred when the document is exported, but this can be overridden on individual paragraphs.
The text can be left-aligned like this. <<
+10 -10
View File
@@ -1,13 +1,13 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="1.4a0" hexVersion="0x010400a0" fileVersion="1.2" timeStamp="2021-06-09 22:06:41"> <novelWriterXML appVersion="1.4a0" hexVersion="0x010400a0" fileVersion="1.2" timeStamp="2021-06-09 22:47:04">
<project> <project>
<name>Sample Project</name> <name>Sample Project</name>
<title>Sample Project</title> <title>Sample Project</title>
<author>Jane Smith</author> <author>Jane Smith</author>
<author>Jay Doh</author> <author>Jay Doh</author>
<saveCount>1083</saveCount> <saveCount>1088</saveCount>
<autoCount>172</autoCount> <autoCount>176</autoCount>
<editTime>50790</editTime> <editTime>51413</editTime>
</project> </project>
<settings> <settings>
<doBackup>False</doBackup> <doBackup>False</doBackup>
@@ -17,8 +17,8 @@
<autoOutline>True</autoOutline> <autoOutline>True</autoOutline>
<lastEdited>636b6aa9b697b</lastEdited> <lastEdited>636b6aa9b697b</lastEdited>
<lastViewed>636b6aa9b697b</lastViewed> <lastViewed>636b6aa9b697b</lastViewed>
<lastWordCount>1132</lastWordCount> <lastWordCount>1164</lastWordCount>
<novelWordCount>756</novelWordCount> <novelWordCount>788</novelWordCount>
<notesWordCount>376</notesWordCount> <notesWordCount>376</notesWordCount>
<autoReplace> <autoReplace>
<entry key="A">B</entry> <entry key="A">B</entry>
@@ -63,10 +63,10 @@
<status>Started</status> <status>Started</status>
<exported>True</exported> <exported>True</exported>
<layout>TITLE</layout> <layout>TITLE</layout>
<charCount>72</charCount> <charCount>259</charCount>
<wordCount>15</wordCount> <wordCount>47</wordCount>
<paraCount>2</paraCount> <paraCount>3</paraCount>
<cursorPos>78</cursorPos> <cursorPos>268</cursorPos>
</item> </item>
<item handle="974e400180a99" order="1" parent="7031beac91f75"> <item handle="974e400180a99" order="1" parent="7031beac91f75">
<name>Page</name> <name>Page</name>