Add support for indented paragraphs in exports
This commit is contained in:
@@ -78,6 +78,9 @@ class ToHtml(Tokenizer):
|
|||||||
html entities replacement.
|
html entities replacement.
|
||||||
"""
|
"""
|
||||||
# Control characters must always be replaced
|
# Control characters must always be replaced
|
||||||
|
# This affects alignment and indenting code, so the Tokenizer
|
||||||
|
# must take this into account when parsing for markup using
|
||||||
|
# angle brackets.
|
||||||
self._trMap = str.maketrans({
|
self._trMap = str.maketrans({
|
||||||
"<" : "<",
|
"<" : "<",
|
||||||
">" : ">",
|
">" : ">",
|
||||||
@@ -181,6 +184,11 @@ class ToHtml(Tokenizer):
|
|||||||
if tStyle & self.A_Z_TOPMRG:
|
if tStyle & self.A_Z_TOPMRG:
|
||||||
aStyle.append("margin-top: 0;")
|
aStyle.append("margin-top: 0;")
|
||||||
|
|
||||||
|
if tStyle & self.A_IND_L:
|
||||||
|
aStyle.append("margin-left: %dpx;" % self.mainConf.tabWidth)
|
||||||
|
if tStyle & self.A_IND_R:
|
||||||
|
aStyle.append("margin-right: %dpx;" % self.mainConf.tabWidth)
|
||||||
|
|
||||||
if len(aStyle) > 0:
|
if len(aStyle) > 0:
|
||||||
hStyle = " style='%s'" % (" ".join(aStyle))
|
hStyle = " style='%s'" % (" ".join(aStyle))
|
||||||
else:
|
else:
|
||||||
|
|||||||
+18
-11
@@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import nw
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@@ -82,6 +83,7 @@ class Tokenizer():
|
|||||||
|
|
||||||
self.theProject = theProject
|
self.theProject = theProject
|
||||||
self.theParent = theProject.theParent
|
self.theParent = theProject.theParent
|
||||||
|
self.mainConf = nw.CONFIG
|
||||||
|
|
||||||
# Data Variables
|
# Data Variables
|
||||||
self.theText = "" # The raw text to be tokenized
|
self.theText = "" # The raw text to be tokenized
|
||||||
@@ -97,14 +99,15 @@ class Tokenizer():
|
|||||||
self.textFont = "Serif" # Output text font
|
self.textFont = "Serif" # Output text font
|
||||||
self.textSize = 11 # Output text size
|
self.textSize = 11 # Output text size
|
||||||
self.textFixed = False # Fixed width text
|
self.textFixed = False # Fixed width text
|
||||||
self.lineHeight = 1.15 # Line height
|
self.lineHeight = 1.15 # Line height in units of em
|
||||||
|
self.blockIndent = 4.00 # Block indent in units of em
|
||||||
self.doJustify = False # Justify text
|
self.doJustify = False # Justify text
|
||||||
self.doBodyText = True # Include body text
|
self.doBodyText = True # Include body text
|
||||||
self.doSynopsis = False # Also process synopsis comments
|
self.doSynopsis = False # Also process synopsis comments
|
||||||
self.doComments = False # Also process comments
|
self.doComments = False # Also process comments
|
||||||
self.doKeywords = False # Also process keywords like tags and references
|
self.doKeywords = False # Also process keywords like tags and references
|
||||||
|
|
||||||
## Title Margins
|
## Margins
|
||||||
self.marginTitle = (1.000, 0.500)
|
self.marginTitle = (1.000, 0.500)
|
||||||
self.marginHead1 = (1.000, 0.500)
|
self.marginHead1 = (1.000, 0.500)
|
||||||
self.marginHead2 = (0.834, 0.500)
|
self.marginHead2 = (0.834, 0.500)
|
||||||
@@ -188,7 +191,11 @@ class Tokenizer():
|
|||||||
return
|
return
|
||||||
|
|
||||||
def setLineHeight(self, lineHeight):
|
def setLineHeight(self, lineHeight):
|
||||||
self.lineHeight = float(lineHeight)
|
self.lineHeight = min(max(float(lineHeight), 0.5), 5.0)
|
||||||
|
return
|
||||||
|
|
||||||
|
def setBlockIndent(self, blockIndent):
|
||||||
|
self.blockIndent = min(max(float(blockIndent), 0.0), 10.0)
|
||||||
return
|
return
|
||||||
|
|
||||||
def setJustify(self, doJustify):
|
def setJustify(self, doJustify):
|
||||||
@@ -451,29 +458,29 @@ class Tokenizer():
|
|||||||
indRight = False
|
indRight = False
|
||||||
if aLine.startswith(">>"):
|
if aLine.startswith(">>"):
|
||||||
tagRight = True
|
tagRight = True
|
||||||
aLine = aLine[2:].lstrip()
|
aLine = aLine[2:].lstrip(" ")
|
||||||
elif aLine.startswith(">>"):
|
elif aLine.startswith(">>"):
|
||||||
tagRight = True
|
tagRight = True
|
||||||
aLine = aLine[8:].lstrip()
|
aLine = aLine[8:].lstrip(" ")
|
||||||
elif aLine.startswith(">"):
|
elif aLine.startswith(">"):
|
||||||
indLeft = True
|
indLeft = True
|
||||||
aLine = aLine[1:].lstrip()
|
aLine = aLine[1:].lstrip(" ")
|
||||||
elif aLine.startswith(">"):
|
elif aLine.startswith(">"):
|
||||||
indLeft = True
|
indLeft = True
|
||||||
aLine = aLine[4:].lstrip()
|
aLine = aLine[4:].lstrip(" ")
|
||||||
|
|
||||||
if aLine.endswith("<<"):
|
if aLine.endswith("<<"):
|
||||||
tagLeft = True
|
tagLeft = True
|
||||||
aLine = aLine[:-2].rstrip()
|
aLine = aLine[:-2].rstrip(" ")
|
||||||
elif aLine.endswith("<<"):
|
elif aLine.endswith("<<"):
|
||||||
tagLeft = True
|
tagLeft = True
|
||||||
aLine = aLine[:-8].rstrip()
|
aLine = aLine[:-8].rstrip(" ")
|
||||||
elif aLine.endswith("<"):
|
elif aLine.endswith("<"):
|
||||||
indRight = True
|
indRight = True
|
||||||
aLine = aLine[:-1].rstrip()
|
aLine = aLine[:-1].rstrip(" ")
|
||||||
elif aLine.endswith("<"):
|
elif aLine.endswith("<"):
|
||||||
indRight = True
|
indRight = True
|
||||||
aLine = aLine[:-4].rstrip()
|
aLine = aLine[:-4].rstrip(" ")
|
||||||
|
|
||||||
textAlign = defAlign
|
textAlign = defAlign
|
||||||
if tagLeft and tagRight:
|
if tagLeft and tagRight:
|
||||||
|
|||||||
+36
-19
@@ -99,19 +99,20 @@ class ToOdt(Tokenizer):
|
|||||||
self.headerText = ""
|
self.headerText = ""
|
||||||
|
|
||||||
# Internal
|
# Internal
|
||||||
self._fontFamily = "'Liberation Sans'"
|
self._fontFamily = "'Liberation Sans'"
|
||||||
self._fontPitch = "variable"
|
self._fontPitch = "variable"
|
||||||
self._fSizeTitle = "30pt"
|
self._fSizeTitle = "30pt"
|
||||||
self._fSizeHead1 = "24pt"
|
self._fSizeHead1 = "24pt"
|
||||||
self._fSizeHead2 = "20pt"
|
self._fSizeHead2 = "20pt"
|
||||||
self._fSizeHead3 = "16pt"
|
self._fSizeHead3 = "16pt"
|
||||||
self._fSizeHead4 = "14pt"
|
self._fSizeHead4 = "14pt"
|
||||||
self._fSizeHead = "14pt"
|
self._fSizeHead = "14pt"
|
||||||
self._fSizeText = "12pt"
|
self._fSizeText = "12pt"
|
||||||
self._lineHeight = "115%"
|
self._lineHeight = "115%"
|
||||||
self._textAlign = "left"
|
self._blockIndent = "1.693cm"
|
||||||
self._dLanguage = "en"
|
self._textAlign = "left"
|
||||||
self._dCountry = "GB"
|
self._dLanguage = "en"
|
||||||
|
self._dCountry = "GB"
|
||||||
|
|
||||||
## Text Margings in Units of em
|
## Text Margings in Units of em
|
||||||
self._mTopTitle = "0.423cm"
|
self._mTopTitle = "0.423cm"
|
||||||
@@ -222,8 +223,9 @@ class ToOdt(Tokenizer):
|
|||||||
self._colMetaTx = "#813709"
|
self._colMetaTx = "#813709"
|
||||||
self._opaMetaTx = "100%"
|
self._opaMetaTx = "100%"
|
||||||
|
|
||||||
self._lineHeight = f"{round(100 * self.lineHeight):d}%"
|
self._lineHeight = f"{round(100 * self.lineHeight):d}%"
|
||||||
self._textAlign = "justify" if self.doJustify else "left"
|
self._blockIndent = self._emToCm(self.blockIndent)
|
||||||
|
self._textAlign = "justify" if self.doJustify else "left"
|
||||||
|
|
||||||
# Document Header
|
# Document Header
|
||||||
# ===============
|
# ===============
|
||||||
@@ -356,6 +358,11 @@ class ToOdt(Tokenizer):
|
|||||||
if tStyle & self.A_Z_TOPMRG:
|
if tStyle & self.A_Z_TOPMRG:
|
||||||
oStyle.setMarginTop("0.000cm")
|
oStyle.setMarginTop("0.000cm")
|
||||||
|
|
||||||
|
if tStyle & self.A_IND_L:
|
||||||
|
oStyle.setMarginLeft(self._blockIndent)
|
||||||
|
if tStyle & self.A_IND_R:
|
||||||
|
oStyle.setMarginRight(self._blockIndent)
|
||||||
|
|
||||||
# Process Text Types
|
# Process Text Types
|
||||||
if tType == self.T_EMPTY:
|
if tType == self.T_EMPTY:
|
||||||
if len(thisPar) > 1 and parStyle is not None:
|
if len(thisPar) > 1 and parStyle is not None:
|
||||||
@@ -515,7 +522,7 @@ class ToOdt(Tokenizer):
|
|||||||
def _formatKeywords(self, tText):
|
def _formatKeywords(self, tText):
|
||||||
"""Apply formatting to keywords.
|
"""Apply formatting to keywords.
|
||||||
"""
|
"""
|
||||||
isValid, theBits, thePos = self.theParent.theIndex.scanThis("@"+tText)
|
isValid, theBits, _ = self.theParent.theIndex.scanThis("@"+tText)
|
||||||
if not isValid or not theBits:
|
if not isValid or not theBits:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@@ -1008,6 +1015,8 @@ class ODTParagraphStyle():
|
|||||||
self._pAttr = {
|
self._pAttr = {
|
||||||
"margin-top": ["fo", None],
|
"margin-top": ["fo", None],
|
||||||
"margin-bottom": ["fo", None],
|
"margin-bottom": ["fo", None],
|
||||||
|
"margin-left": ["fo", None],
|
||||||
|
"margin-right": ["fo", None],
|
||||||
"line-height": ["fo", None],
|
"line-height": ["fo", None],
|
||||||
"text-align": ["fo", None],
|
"text-align": ["fo", None],
|
||||||
"break-before": ["fo", None],
|
"break-before": ["fo", None],
|
||||||
@@ -1064,6 +1073,14 @@ class ODTParagraphStyle():
|
|||||||
self._pAttr["margin-bottom"][1] = str(theValue)
|
self._pAttr["margin-bottom"][1] = str(theValue)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def setMarginLeft(self, theValue):
|
||||||
|
self._pAttr["margin-left"][1] = str(theValue)
|
||||||
|
return
|
||||||
|
|
||||||
|
def setMarginRight(self, theValue):
|
||||||
|
self._pAttr["margin-right"][1] = str(theValue)
|
||||||
|
return
|
||||||
|
|
||||||
def setLineHeight(self, theValue):
|
def setLineHeight(self, theValue):
|
||||||
self._pAttr["line-height"][1] = str(theValue)
|
self._pAttr["line-height"][1] = str(theValue)
|
||||||
return
|
return
|
||||||
@@ -1142,13 +1159,13 @@ class ODTParagraphStyle():
|
|||||||
"""Check if there are new settings in refStyle that differ from
|
"""Check if there are new settings in refStyle that differ from
|
||||||
those in the current object.
|
those in the current object.
|
||||||
"""
|
"""
|
||||||
for aName, (aNm, aVal) in refStyle._mAttr.items():
|
for aName, (_, aVal) in refStyle._mAttr.items():
|
||||||
if aVal is not None and aVal != self._mAttr[aName][1]:
|
if aVal is not None and aVal != self._mAttr[aName][1]:
|
||||||
return True
|
return True
|
||||||
for aName, (aNm, aVal) in refStyle._pAttr.items():
|
for aName, (_, aVal) in refStyle._pAttr.items():
|
||||||
if aVal is not None and aVal != self._pAttr[aName][1]:
|
if aVal is not None and aVal != self._pAttr[aName][1]:
|
||||||
return True
|
return True
|
||||||
for aName, (aNm, aVal) in refStyle._tAttr.items():
|
for aName, (_, aVal) in refStyle._tAttr.items():
|
||||||
if aVal is not None and aVal != self._tAttr[aName][1]:
|
if aVal is not None and aVal != self._tAttr[aName][1]:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user