# -*- coding: utf-8 -*- """novelWriter HTML Text Converter novelWriter – HTML Text Converter =================================== Extends the Tokenizer class to write HTML File History: Created: 2019-05-07 [0.0.1] """ import logging import nw from nw.convert.tokenizer import Tokenizer logger = logging.getLogger(__name__) class ToHtml(Tokenizer): def __init__(self, theProject, theParent): Tokenizer.__init__(self, theProject, theParent) return def doConvert(self): htmlTags = { self.FMT_B_B : "", self.FMT_B_E : "", self.FMT_I_B : "", self.FMT_I_E : "", self.FMT_U_B : "", self.FMT_U_E : "", } self.theResult = "" thisPar = [] for tType, tText, tFormat in self.theTokens: if tType == "empty": if len(thisPar) > 0: self.theResult += "

%s

\n" % " ".join(thisPar) thisPar = [] elif tType == "header1": self.theResult += "

%s

\n" % tText elif tType == "header2": self.theResult += "

%s

\n" % tText elif tType == "header3": self.theResult += "

%s

\n" % tText elif tType == "header4": self.theResult += "

%s

\n" % tText elif tType == "text": tTemp = tText for xPos, xLen, xFmt in reversed(tFormat): tTemp = tTemp[:xPos]+htmlTags[xFmt]+tTemp[xPos+xLen:] thisPar.append(tTemp) # print(self.theResult) return # END Class ToHtml