Add some comments and add text indent to HTML
This commit is contained in:
@@ -29,7 +29,6 @@ import logging
|
||||
from pathlib import Path
|
||||
from time import time
|
||||
|
||||
from novelwriter import CONFIG
|
||||
from novelwriter.common import formatTimeStamp
|
||||
from novelwriter.constants import nwHeadFmt, nwHtmlUnicode, nwKeyWords, nwLabels
|
||||
from novelwriter.core.project import NWProject
|
||||
@@ -184,7 +183,6 @@ class ToHtml(Tokenizer):
|
||||
|
||||
if tStyle & self.A_PBB:
|
||||
aStyle.append("page-break-before: always;")
|
||||
|
||||
if tStyle & self.A_PBA:
|
||||
aStyle.append("page-break-after: always;")
|
||||
|
||||
@@ -194,11 +192,13 @@ class ToHtml(Tokenizer):
|
||||
aStyle.append("margin-top: 0;")
|
||||
|
||||
if tStyle & self.A_IND_L:
|
||||
aStyle.append(f"margin-left: {CONFIG.tabWidth:d}px;")
|
||||
aStyle.append(f"margin-left: {self._blockIndent:.2f}em;")
|
||||
if tStyle & self.A_IND_R:
|
||||
aStyle.append(f"margin-right: {CONFIG.tabWidth:d}px;")
|
||||
aStyle.append(f"margin-right: {self._blockIndent:.2f}em;")
|
||||
if tStyle & self.A_IND_T:
|
||||
aStyle.append(f"text-indent: {self._firstWidth:.2f}em;")
|
||||
|
||||
if len(aStyle) > 0:
|
||||
if aStyle:
|
||||
stVals = " ".join(aStyle)
|
||||
hStyle = f" style='{stVals}'"
|
||||
else:
|
||||
|
||||
@@ -852,6 +852,9 @@ class Tokenizer(ABC):
|
||||
nToken = tokens[n+1] # Look ahead
|
||||
|
||||
if not self._indentFirst and cToken[0] in self.L_SKIP_INDENT:
|
||||
# Unless the indentFirst flag is set, we set up the next
|
||||
# paragraph to not be indented if we see a block of a
|
||||
# specific type
|
||||
pIndent = False
|
||||
|
||||
if cToken[0] == self.T_EMPTY:
|
||||
@@ -872,16 +875,27 @@ class Tokenizer(ABC):
|
||||
elif cToken[0] == self.T_TEXT:
|
||||
# Combine lines from the same paragraph
|
||||
pLines.append(cToken)
|
||||
|
||||
if nToken[0] != self.T_TEXT:
|
||||
# Next token is not text, so we add the buffer to tokens
|
||||
nLines = len(pLines)
|
||||
cStyle = pLines[0][4]
|
||||
if self._firstIndent and pIndent and not cStyle & self.M_ALIGNED:
|
||||
# If paragraph indentation is enabled, not temporarily
|
||||
# turned off, and the block is not aligned, we add the
|
||||
# text indentation flag
|
||||
cStyle |= self.A_IND_T
|
||||
|
||||
if nLines == 1:
|
||||
# The paragraph contains a single line, so we just
|
||||
# save that directly to the token list
|
||||
self._tokens.append((
|
||||
self.T_TEXT, pLines[0][1], pLines[0][2], pLines[0][3], cStyle
|
||||
))
|
||||
elif nLines > 1:
|
||||
# The paragraph contains multiple lines, so we need to
|
||||
# join them according to the line break policy, and
|
||||
# recompute all the formatting markers
|
||||
tTxt = ""
|
||||
tFmt: T_Formats = []
|
||||
for aToken in pLines:
|
||||
@@ -891,6 +905,8 @@ class Tokenizer(ABC):
|
||||
self._tokens.append((
|
||||
self.T_TEXT, pLines[0][1], tTxt[:-1], tFmt, cStyle
|
||||
))
|
||||
|
||||
# Reset buffer and make sure text indent is on for next pass
|
||||
pLines = []
|
||||
pIndent = True
|
||||
|
||||
|
||||
@@ -469,6 +469,8 @@ class ToOdt(Tokenizer):
|
||||
|
||||
# Process Text Types
|
||||
if tType == self.T_TEXT:
|
||||
# Text indentation is processed here because there is a
|
||||
# dedicated pre-defined style for it
|
||||
if tStyle & self.A_IND_T:
|
||||
self._addTextPar(xText, S_FIND, oStyle, tText, tFmt=tFormat)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user