Add some comments and add text indent to HTML

This commit is contained in:
Veronica Berglyd Olsen
2024-05-27 21:08:09 +02:00
parent aa02c0f15d
commit 770cccda49
3 changed files with 23 additions and 5 deletions
+5 -5
View File
@@ -29,7 +29,6 @@ import logging
from pathlib import Path from pathlib import Path
from time import time from time import time
from novelwriter import CONFIG
from novelwriter.common import formatTimeStamp from novelwriter.common import formatTimeStamp
from novelwriter.constants import nwHeadFmt, nwHtmlUnicode, nwKeyWords, nwLabels from novelwriter.constants import nwHeadFmt, nwHtmlUnicode, nwKeyWords, nwLabels
from novelwriter.core.project import NWProject from novelwriter.core.project import NWProject
@@ -184,7 +183,6 @@ class ToHtml(Tokenizer):
if tStyle & self.A_PBB: if tStyle & self.A_PBB:
aStyle.append("page-break-before: always;") aStyle.append("page-break-before: always;")
if tStyle & self.A_PBA: if tStyle & self.A_PBA:
aStyle.append("page-break-after: always;") aStyle.append("page-break-after: always;")
@@ -194,11 +192,13 @@ class ToHtml(Tokenizer):
aStyle.append("margin-top: 0;") aStyle.append("margin-top: 0;")
if tStyle & self.A_IND_L: 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: 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) stVals = " ".join(aStyle)
hStyle = f" style='{stVals}'" hStyle = f" style='{stVals}'"
else: else:
+16
View File
@@ -852,6 +852,9 @@ class Tokenizer(ABC):
nToken = tokens[n+1] # Look ahead nToken = tokens[n+1] # Look ahead
if not self._indentFirst and cToken[0] in self.L_SKIP_INDENT: 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 pIndent = False
if cToken[0] == self.T_EMPTY: if cToken[0] == self.T_EMPTY:
@@ -872,16 +875,27 @@ class Tokenizer(ABC):
elif cToken[0] == self.T_TEXT: elif cToken[0] == self.T_TEXT:
# Combine lines from the same paragraph # Combine lines from the same paragraph
pLines.append(cToken) pLines.append(cToken)
if nToken[0] != self.T_TEXT: if nToken[0] != self.T_TEXT:
# Next token is not text, so we add the buffer to tokens
nLines = len(pLines) nLines = len(pLines)
cStyle = pLines[0][4] cStyle = pLines[0][4]
if self._firstIndent and pIndent and not cStyle & self.M_ALIGNED: 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 cStyle |= self.A_IND_T
if nLines == 1: if nLines == 1:
# The paragraph contains a single line, so we just
# save that directly to the token list
self._tokens.append(( self._tokens.append((
self.T_TEXT, pLines[0][1], pLines[0][2], pLines[0][3], cStyle self.T_TEXT, pLines[0][1], pLines[0][2], pLines[0][3], cStyle
)) ))
elif nLines > 1: 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 = "" tTxt = ""
tFmt: T_Formats = [] tFmt: T_Formats = []
for aToken in pLines: for aToken in pLines:
@@ -891,6 +905,8 @@ class Tokenizer(ABC):
self._tokens.append(( self._tokens.append((
self.T_TEXT, pLines[0][1], tTxt[:-1], tFmt, cStyle self.T_TEXT, pLines[0][1], tTxt[:-1], tFmt, cStyle
)) ))
# Reset buffer and make sure text indent is on for next pass
pLines = [] pLines = []
pIndent = True pIndent = True
+2
View File
@@ -469,6 +469,8 @@ class ToOdt(Tokenizer):
# Process Text Types # Process Text Types
if tType == self.T_TEXT: 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: if tStyle & self.A_IND_T:
self._addTextPar(xText, S_FIND, oStyle, tText, tFmt=tFormat) self._addTextPar(xText, S_FIND, oStyle, tText, tFmt=tFormat)
else: else: