Moved the emphasis regexes to a constants class

This commit is contained in:
Veronica K. B. Olsen
2020-06-13 10:08:00 +02:00
parent 6951b3d2fa
commit 49049e19d8
3 changed files with 14 additions and 5 deletions
+2 -1
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from nw.constants.iso import isoLanguage, isoCountry from nw.constants.iso import isoLanguage, isoCountry
from nw.constants.constants import ( from nw.constants.constants import (
nwConst, nwFiles, nwKeyWords, nwLabels, nwQuotes, nwUnicode nwConst, nwRegEx, nwFiles, nwKeyWords, nwLabels, nwQuotes, nwUnicode
) )
from nw.constants.enum import ( from nw.constants.enum import (
nwAlert, nwDocAction, nwItemClass, nwItemLayout, nwItemType, nwOutline nwAlert, nwDocAction, nwItemClass, nwItemLayout, nwItemType, nwOutline
@@ -11,6 +11,7 @@ __all__ = [
"isoLanguage", "isoLanguage",
"isoCountry", "isoCountry",
"nwConst", "nwConst",
"nwRegEx",
"nwFiles", "nwFiles",
"nwKeyWords", "nwKeyWords",
"nwLabels", "nwLabels",
+8
View File
@@ -34,6 +34,14 @@ class nwConst():
# END Class nwConst # END Class nwConst
class nwRegEx():
FMT_B = r"(?<![\w|\*|_|\\])([\*|_]{2})(?!\s|\*|_)(.+?)(?<![\s|\\])(\1)(?!\w)"
FMT_I = r"(?<![\w|\*|_|\\])([\*|_])(?!\s|\*|_)(.+?)(?<![\s|\\])(\1)(?!\w)"
FMT_BI = r"(?<![\w|\*|\\])([\*]{3})(?!\s|\*)(.+?)(?<![\s|\\])(\1)(?!\w)"
# END Class nwRegEx
class nwFiles(): class nwFiles():
PROJ_FILE = "nwProject.nwx" PROJ_FILE = "nwProject.nwx"
+4 -4
View File
@@ -33,7 +33,7 @@ from PyQt5.QtGui import (
QColor, QTextCharFormat, QFont, QSyntaxHighlighter, QBrush QColor, QTextCharFormat, QFont, QSyntaxHighlighter, QBrush
) )
from nw.constants import nwUnicode from nw.constants import nwUnicode, nwRegEx
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -140,21 +140,21 @@ class GuiDocHighlighter(QSyntaxHighlighter):
# Markdown # Markdown
self.hRules.append(( self.hRules.append((
r"(?<![\w|\*|\\])([\*])(?!\s|\1)(.+?)(?<![\s|\\])(\1)(?!\w)", { nwRegEx.FMT_I, {
1 : self.hStyles["hidden"], 1 : self.hStyles["hidden"],
2 : self.hStyles["italic"], 2 : self.hStyles["italic"],
3 : self.hStyles["hidden"], 3 : self.hStyles["hidden"],
} }
)) ))
self.hRules.append(( self.hRules.append((
r"(?<![\w|\*|\\])([\*]{2})(?!\s|\*)(.+?)(?<![\s|\\])(\1)(?!\w)", { nwRegEx.FMT_B, {
1 : self.hStyles["hidden"], 1 : self.hStyles["hidden"],
2 : self.hStyles["bold"], 2 : self.hStyles["bold"],
3 : self.hStyles["hidden"], 3 : self.hStyles["hidden"],
} }
)) ))
self.hRules.append(( self.hRules.append((
r"(?<![\w|\*|\\])([\*]{3})(?!\s|\*)(.+?)(?<![\s|\\])(\1)(?!\w)", { nwRegEx.FMT_BI, {
1 : self.hStyles["hidden"], 1 : self.hStyles["hidden"],
2 : self.hStyles["bolditalic"], 2 : self.hStyles["bolditalic"],
3 : self.hStyles["hidden"], 3 : self.hStyles["hidden"],