Added left/right indentation to Tokenizer class

This commit is contained in:
Veronica Berglyd Olsen
2021-06-10 00:04:54 +02:00
parent e0de3ff191
commit 80c4826253
3 changed files with 82 additions and 27 deletions
+22 -1
View File
@@ -75,6 +75,8 @@ class Tokenizer():
A_PBA_AUT = 0x0080 # Page break after auto
A_Z_TOPMRG = 0x0100 # Zero top margin
A_Z_BTMMRG = 0x0200 # Zero bottom margin
A_IND_L = 0x0400 # Left indentation
A_IND_R = 0x0800 # Right indentation
def __init__(self, theProject):
@@ -442,15 +444,23 @@ class Tokenizer():
# Skip all body text
continue
# Check Alignment
# Check Alignment and Indentation
tagLeft = False
tagRight = False
indLeft = False
indRight = False
if aLine.startswith(">>"):
tagRight = True
aLine = aLine[2:].lstrip()
elif aLine.startswith(">>"):
tagRight = True
aLine = aLine[8:].lstrip()
elif aLine.startswith(">"):
indLeft = True
aLine = aLine[1:].lstrip()
elif aLine.startswith(">"):
indLeft = True
aLine = aLine[4:].lstrip()
if aLine.endswith("<<"):
tagLeft = True
@@ -458,6 +468,12 @@ class Tokenizer():
elif aLine.endswith("&lt;&lt;"):
tagLeft = True
aLine = aLine[:-8].rstrip()
elif aLine.endswith("<"):
indRight = True
aLine = aLine[:-1].rstrip()
elif aLine.endswith("&lt;"):
indRight = True
aLine = aLine[:-4].rstrip()
textAlign = defAlign
if tagLeft and tagRight:
@@ -467,6 +483,11 @@ class Tokenizer():
elif tagRight:
textAlign = self.A_RIGHT
if indLeft:
textAlign |= self.A_IND_L
if indRight:
textAlign |= self.A_IND_R
# Otherwise we use RegEx to find formatting tags within a line of text
fmtPos = []
for theRX, theKeys in rxFormats:
+21 -21
View File
@@ -106,27 +106,27 @@ class GuiDocHighlighter(QSyntaxHighlighter):
self.colEmph = QColor(*self.theTheme.colEmph)
self.hStyles = {
"header1" : self._makeFormat(self.colHead, "bold", 1.8),
"header2" : self._makeFormat(self.colHead, "bold", 1.6),
"header3" : self._makeFormat(self.colHead, "bold", 1.4),
"header4" : self._makeFormat(self.colHead, "bold", 1.2),
"header1h" : self._makeFormat(self.colHeadH, "bold", 1.8),
"header2h" : self._makeFormat(self.colHeadH, "bold", 1.6),
"header3h" : self._makeFormat(self.colHeadH, "bold", 1.4),
"header4h" : self._makeFormat(self.colHeadH, "bold", 1.2),
"bold" : self._makeFormat(self.colEmph, "bold"),
"italic" : self._makeFormat(self.colEmph, "italic"),
"strike" : self._makeFormat(self.colHidden, "strike"),
"mspaces" : self._makeFormat(self.colError, "errline"),
"nobreak" : self._makeFormat(self.colBreak, "background"),
"dialogue1" : self._makeFormat(self.colDialN),
"dialogue2" : self._makeFormat(self.colDialD),
"dialogue3" : self._makeFormat(self.colDialS),
"replace" : self._makeFormat(self.colRepTag),
"hidden" : self._makeFormat(self.colHidden),
"keyword" : self._makeFormat(self.colKey),
"modifier" : self._makeFormat(self.colMod),
"value" : self._makeFormat(self.colVal, "underline"),
"header1" : self._makeFormat(self.colHead, "bold", 1.8),
"header2" : self._makeFormat(self.colHead, "bold", 1.6),
"header3" : self._makeFormat(self.colHead, "bold", 1.4),
"header4" : self._makeFormat(self.colHead, "bold", 1.2),
"header1h" : self._makeFormat(self.colHeadH, "bold", 1.8),
"header2h" : self._makeFormat(self.colHeadH, "bold", 1.6),
"header3h" : self._makeFormat(self.colHeadH, "bold", 1.4),
"header4h" : self._makeFormat(self.colHeadH, "bold", 1.2),
"bold" : self._makeFormat(self.colEmph, "bold"),
"italic" : self._makeFormat(self.colEmph, "italic"),
"strike" : self._makeFormat(self.colHidden, "strike"),
"mspaces" : self._makeFormat(self.colError, "errline"),
"nobreak" : self._makeFormat(self.colBreak, "background"),
"dialogue1" : self._makeFormat(self.colDialN),
"dialogue2" : self._makeFormat(self.colDialD),
"dialogue3" : self._makeFormat(self.colDialS),
"replace" : self._makeFormat(self.colRepTag),
"hidden" : self._makeFormat(self.colHidden),
"keyword" : self._makeFormat(self.colKey),
"modifier" : self._makeFormat(self.colMod),
"value" : self._makeFormat(self.colVal, "underline"),
}
self.hRules = []