Implemented the auto-replace code in the doc viewer.
This commit is contained in:
+16
-2
@@ -11,6 +11,7 @@
|
||||
"""
|
||||
|
||||
import logging
|
||||
import re
|
||||
import nw
|
||||
|
||||
from nw.convert.tokenizer import Tokenizer
|
||||
@@ -24,6 +25,19 @@ class ToHtml(Tokenizer):
|
||||
|
||||
return
|
||||
|
||||
def doAutoReplace(self):
|
||||
Tokenizer.doAutoReplace(self)
|
||||
|
||||
theDict = {
|
||||
"<" : "<",
|
||||
">" : ">",
|
||||
"&" : "&",
|
||||
}
|
||||
xRep = re.compile("|".join([re.escape(k) for k in theDict.keys()]), flags=re.DOTALL)
|
||||
self.theText = xRep.sub(lambda x: theDict[x.group(0)], self.theText)
|
||||
|
||||
return
|
||||
|
||||
def doConvert(self):
|
||||
|
||||
htmlTags = {
|
||||
@@ -31,8 +45,8 @@ class ToHtml(Tokenizer):
|
||||
self.FMT_B_E : "</strong>",
|
||||
self.FMT_I_B : "<em>",
|
||||
self.FMT_I_E : "</em>",
|
||||
self.FMT_U_B : "<mark>",
|
||||
self.FMT_U_E : "</mark>",
|
||||
self.FMT_U_B : "<u>",
|
||||
self.FMT_U_E : "</u>",
|
||||
}
|
||||
|
||||
self.theResult = ""
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"""
|
||||
|
||||
import logging
|
||||
import re
|
||||
import nw
|
||||
|
||||
from operator import itemgetter
|
||||
@@ -57,6 +58,15 @@ class Tokenizer():
|
||||
|
||||
return
|
||||
|
||||
def doAutoReplace(self):
|
||||
if len(self.theProject.autoReplace) > 0:
|
||||
theDict = {}
|
||||
for aKey, aVal in self.theProject.autoReplace.items():
|
||||
theDict["<%s>" % aKey] = aVal
|
||||
xRep = re.compile("|".join([re.escape(k) for k in theDict.keys()]), flags=re.DOTALL)
|
||||
self.theText = xRep.sub(lambda x: theDict[x.group(0)], self.theText)
|
||||
return
|
||||
|
||||
def tokenizeText(self):
|
||||
"""Scan the text for either lines starting with specific characters that indicate headers,
|
||||
comments, commands etc, or just contains plain text. in the case of plain text, apply the
|
||||
|
||||
Reference in New Issue
Block a user