diff --git a/nw/core/tokenizer.py b/nw/core/tokenizer.py index 583eb948..d0bc33eb 100644 --- a/nw/core/tokenizer.py +++ b/nw/core/tokenizer.py @@ -436,6 +436,31 @@ class Tokenizer(): # Skip all body text continue + # Check Alignment + tagLeft = False + tagRight = False + if aLine.startswith(">>"): + tagRight = True + aLine = aLine[2:].lstrip() + elif aLine.startswith(">>"): + tagRight = True + aLine = aLine[8:].lstrip() + + if aLine.endswith("<<"): + tagLeft = True + aLine = aLine[:-2].rstrip() + elif aLine.endswith("<<"): + tagLeft = True + aLine = aLine[:-8].rstrip() + + textAlign = self.A_NONE + if tagLeft and tagRight: + textAlign = self.A_CENTRE + elif tagLeft: + textAlign = self.A_LEFT + elif tagRight: + textAlign = self.A_RIGHT + # Otherwise we use RegEx to find formatting tags within a line of text fmtPos = [] for theRX, theKeys in rxFormats: @@ -452,7 +477,7 @@ class Tokenizer(): # sorted by position fmtPos = sorted(fmtPos, key=itemgetter(0)) self.theTokens.append(( - self.T_TEXT, nLine, aLine, fmtPos, self.A_NONE + self.T_TEXT, nLine, aLine, fmtPos, textAlign )) if self.keepMarkdown: tmpMarkdown.append("%s\n" % aLine) diff --git a/nw/gui/dochighlight.py b/nw/gui/dochighlight.py index ceeacf45..f33b94b9 100644 --- a/nw/gui/dochighlight.py +++ b/nw/gui/dochighlight.py @@ -198,6 +198,13 @@ class GuiDocHighlighter(QSyntaxHighlighter): } )) + # Alignment Tags + self.hRules.append(( + r"(^>{1,2}|<{1,2}$)", { + 1 : self.hStyles["hidden"], + } + )) + # Auto-Replace Tags self.hRules.append(( r"<(\S+?)>", { diff --git a/sample/content/636b6aa9b697b.nwd b/sample/content/636b6aa9b697b.nwd index be611dce..e05d4041 100644 --- a/sample/content/636b6aa9b697b.nwd +++ b/sample/content/636b6aa9b697b.nwd @@ -24,3 +24,13 @@ Thin spaces and thin non-breaking spaces are also supported from the Insert menu If you need to split a scene file up into further pieces, you can do so with the level four heading, like above. This is referred to as a section. Both scene and section titles can be left out of the final exported document. The formatting of titles can be selected from the Build Novel Project dialog. You can also have them replaced with scene separators like “* * *”. + +#### Text Alignment + +The text by default will have the left or justified alignment. You can also specify alignment for a specific paragraph by “pushing” it away from an edge with a set of ‘>>’ or ‘<<’ symbols, like so: + +This text is left-aligned. << + +>> This text is right-aligned. + +>> This text is centred. << \ No newline at end of file diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index fe3bcc24..a5e489bc 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,13 +1,13 @@ - + Sample Project Sample Project Jane Smith Jay Doh - 1062 - 166 - 49870 + 1083 + 172 + 50790 False @@ -17,8 +17,8 @@ True 636b6aa9b697b 636b6aa9b697b - 1077 - 701 + 1132 + 756 376 B @@ -118,10 +118,10 @@ 1st Draft True SCENE - 1810 - 318 - 8 - 1505 + 2107 + 373 + 12 + 2049 Another Scene @@ -145,7 +145,7 @@ 633 101 3 - 0 + 308 A Note on Structure