# -*- 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 re 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 doAutoReplace(self): Tokenizer.doAutoReplace(self) repDict = { "<" : "<", ">" : ">", "&" : "&", "\u2013" : "&endash;", "\u2014" : "$emdash;", "\u2500" : "$emdash;", "\u2026" : "…", } 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 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, tAlign in self.theTokens: aStyle = [] if tAlign == self.A_CENTRE: aStyle.append("text-align: center;") if len(aStyle) > 0: hStyle = " style='%s'" % (" ".join(aStyle)) else: hStyle = "" if tType == self.T_EMPTY: if len(thisPar) > 0: self.theResult += "
%s
\n" % (hStyle," ".join(thisPar)) thisPar = [] elif tType == self.T_HEAD1: self.theResult += "%s\n" % tText # print(self.theResult) return # END Class ToHtml