Adding non-breaking space support for editor and html, latex export
This commit is contained in:
+13
-12
@@ -38,18 +38,19 @@ class HtmlFile(TextFile):
|
||||
self.outFile.write("<!DOCTYPE html>\n")
|
||||
self.outFile.write("<html>\n")
|
||||
self.outFile.write("<head>\n")
|
||||
self.outFile.write("<style>\n")
|
||||
self.outFile.write(" #page {\n")
|
||||
self.outFile.write(" margin: 40px auto;\n")
|
||||
self.outFile.write(" max-width: 769px;\n")
|
||||
self.outFile.write(" }\n")
|
||||
self.outFile.write(" .comment {\n")
|
||||
self.outFile.write(" background-color: #fbfabd;\n")
|
||||
self.outFile.write(" border: 1px solid #b4b000;\n")
|
||||
self.outFile.write(" margin: 10px 20px;\n")
|
||||
self.outFile.write(" padding: 6px;\n")
|
||||
self.outFile.write(" }\n")
|
||||
self.outFile.write("</style>\n")
|
||||
self.outFile.write(" <meta charset='utf-8'>\n")
|
||||
self.outFile.write(" <style>\n")
|
||||
self.outFile.write(" #page {\n")
|
||||
self.outFile.write(" margin: 40px auto;\n")
|
||||
self.outFile.write(" max-width: 769px;\n")
|
||||
self.outFile.write(" }\n")
|
||||
self.outFile.write(" .comment {\n")
|
||||
self.outFile.write(" background-color: #fbfabd;\n")
|
||||
self.outFile.write(" border: 1px solid #b4b000;\n")
|
||||
self.outFile.write(" margin: 10px 20px;\n")
|
||||
self.outFile.write(" padding: 6px;\n")
|
||||
self.outFile.write(" }\n")
|
||||
self.outFile.write(" </style>\n")
|
||||
self.outFile.write("</head>\n")
|
||||
self.outFile.write("<body>\n")
|
||||
self.outFile.write("<article id='page'>\n")
|
||||
|
||||
@@ -138,6 +138,7 @@ class TextFile():
|
||||
self.theConv.tokenizeText()
|
||||
self.theConv.doHeaders()
|
||||
self.theConv.doConvert()
|
||||
self.theConv.doPostProcessing()
|
||||
|
||||
if self.theConv.theResult is not None and self.outFile is not None:
|
||||
self.outFile.write(self.theConv.theResult)
|
||||
|
||||
@@ -15,6 +15,7 @@ import re
|
||||
import nw
|
||||
|
||||
from nw.convert.tokenizer import Tokenizer
|
||||
from nw.constants import nwUnicode
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -28,13 +29,13 @@ class ToHtml(Tokenizer):
|
||||
Tokenizer.doAutoReplace(self)
|
||||
|
||||
repDict = {
|
||||
"<" : "<",
|
||||
">" : ">",
|
||||
"&" : "&",
|
||||
"\u2013" : "&endash;",
|
||||
"\u2014" : "$emdash;",
|
||||
"\u2500" : "$emdash;",
|
||||
"\u2026" : "…",
|
||||
"<" : "<",
|
||||
">" : ">",
|
||||
"&" : "&",
|
||||
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)
|
||||
|
||||
@@ -16,6 +16,7 @@ import re
|
||||
import nw
|
||||
|
||||
from nw.convert.tokenizer import Tokenizer
|
||||
from nw.constants import nwUnicode
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -26,6 +27,20 @@ class ToLaTeX(Tokenizer):
|
||||
self.texCodecFail = False
|
||||
return
|
||||
|
||||
def doPostProcessing(self):
|
||||
"""The latexcodec misses dashes and non-breaking spaces, so we do those here.
|
||||
"""
|
||||
|
||||
repDict = {
|
||||
nwUnicode.U_ENDASH : "--",
|
||||
nwUnicode.U_EMDASH : "---",
|
||||
nwUnicode.U_NBSP : "~",
|
||||
}
|
||||
xRep = re.compile("|".join([re.escape(k) for k in repDict.keys()]), flags=re.DOTALL)
|
||||
self.theResult = xRep.sub(lambda x: repDict[x.group(0)], self.theResult)
|
||||
|
||||
return
|
||||
|
||||
def doConvert(self):
|
||||
|
||||
texTags = {
|
||||
|
||||
@@ -16,6 +16,7 @@ import re
|
||||
import nw
|
||||
|
||||
from nw.convert.tokenizer import Tokenizer
|
||||
from nw.constants import nwUnicode
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -25,6 +26,17 @@ class ToText(Tokenizer):
|
||||
Tokenizer.__init__(self, theProject, theParent)
|
||||
return
|
||||
|
||||
def doAutoReplace(self):
|
||||
Tokenizer.doAutoReplace(self)
|
||||
|
||||
repDict = {
|
||||
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
|
||||
|
||||
def doConvert(self):
|
||||
"""Converts the tokenized text into plain text.
|
||||
"""
|
||||
|
||||
@@ -149,6 +149,9 @@ class Tokenizer():
|
||||
self.theText = xRep.sub(lambda x: repDict[x.group(0)], self.theText)
|
||||
return
|
||||
|
||||
def doPostProcessing(self):
|
||||
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