Skip to content

Commit

Permalink
Add some comments and add text indent to HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed May 27, 2024
1 parent aa02c0f commit 770cccd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
10 changes: 5 additions & 5 deletions novelwriter/core/tohtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
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
Expand Down Expand Up @@ -184,7 +183,6 @@ def doConvert(self) -> None:

if tStyle & self.A_PBB:
aStyle.append("page-break-before: always;")

if tStyle & self.A_PBA:
aStyle.append("page-break-after: always;")

Expand All @@ -194,11 +192,13 @@ def doConvert(self) -> None:
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:
Expand Down
16 changes: 16 additions & 0 deletions novelwriter/core/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,9 @@ def tokenizeText(self) -> None:
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:
Expand All @@ -872,16 +875,27 @@ def tokenizeText(self) -> None:
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:
Expand All @@ -891,6 +905,8 @@ def tokenizeText(self) -> None:
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

Expand Down
2 changes: 2 additions & 0 deletions novelwriter/core/toodt.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ def doConvert(self) -> None:

# 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:
Expand Down

0 comments on commit 770cccd

Please sign in to comment.