Beispiel #1
0
    def doAutoReplace(self):
        Tokenizer.doAutoReplace(self)

        repDict = {
            "\t": "    ",
            nwUnicode.U_NBSP: " ",
        }
        xRep = re.compile("|".join([re.escape(k) for k in repDict.keys()]),
                          flags=re.DOTALL)
        self.theText = xRep.sub(lambda x: repDict[x.group(0)], self.theText)

        return
Beispiel #2
0
    def doAutoReplace(self):
        Tokenizer.doAutoReplace(self)

        if self.forPreview:
            tabFmt = " "*8
        else:
            tabFmt = " "

        repDict = {
            "<"  : "&lt;",
            ">"  : "&gt;",
            "&"  : "&amp;",
            "\t" : tabFmt,
            nwUnicode.U_ENDASH : nwUnicode.H_ENDASH,
            nwUnicode.U_EMDASH : nwUnicode.H_EMDASH,
            nwUnicode.U_HELLIP : nwUnicode.H_HELLIP,
            nwUnicode.U_NBSP   : nwUnicode.H_NBSP,
        }
        xRep = re.compile("|".join([re.escape(k) for k in repDict.keys()]), flags=re.DOTALL)
        self.theText = xRep.sub(lambda x: repDict[x.group(0)], self.theText)

        return
Beispiel #3
0
class ConcatFile(TextFile):
    def __init__(self, theProject, theParent):
        TextFile.__init__(self, theProject, theParent)
        self.theConv = Tokenizer(self.theProject, self.theParent)
        return

    def addText(self, tHandle):

        logger.verbose("Parsing content of item '%s'" % tHandle)

        if not self.checkInclude(tHandle):
            return False

        self.theConv.setText(tHandle)

        theResult = self.theConv.theText

        if theResult is not None and self.outFile is not None:
            self.outFile.write(theResult.rstrip())
            self.outFile.write("\n\n")

        return True

    ##
    #  Internal Functions
    ##

    def _doOpenFile(self, filePath):
        try:
            self.outFile = open(filePath, mode="wt+", encoding="utf8")
        except Exception as e:
            self.makeAlert(["Failed to open file.", str(e)], nwAlert.ERROR)
            return False
        return True

    def _doCloseFile(self):
        if self.outFile is not None:
            self.outFile.close()
        return True
Beispiel #4
0
 def __init__(self, theProject, theParent):
     Tokenizer.__init__(self, theProject, theParent)
     return
Beispiel #5
0
 def __init__(self, theProject, theParent):
     Tokenizer.__init__(self, theProject, theParent)
     self.forPreview = False
     return
Beispiel #6
0
 def __init__(self, theProject, theParent):
     TextFile.__init__(self, theProject, theParent)
     self.theConv = Tokenizer(self.theProject, self.theParent)
     return
Beispiel #7
0
 def __init__(self, theProject, theParent):
     Tokenizer.__init__(self, theProject, theParent)
     self.texCodecFail = False
     return