From af6b35cc43fb58d973463e48b3f930bd62053a8f Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sat, 14 Jun 2025 15:28:51 +0200 Subject: [PATCH] Improve handling of CSS styles, and add viewport meta tag (#2358) --- novelwriter/formats/tohtml.py | 88 ++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/novelwriter/formats/tohtml.py b/novelwriter/formats/tohtml.py index c7bf7b17..404c6d09 100644 --- a/novelwriter/formats/tohtml.py +++ b/novelwriter/formats/tohtml.py @@ -159,34 +159,33 @@ class ToHtml(Tokenizer): # If we don't have formatting, we can do a plain replace tText = tText.replace("<", "<").replace(">", ">") - # Styles + # Inline Styles aStyle = [] - if self._cssStyles: - if tStyle & BlockFmt.LEFT: - aStyle.append("text-align: left;") - elif tStyle & BlockFmt.RIGHT: - aStyle.append("text-align: right;") - elif tStyle & BlockFmt.CENTRE: - aStyle.append("text-align: center;") - elif tStyle & BlockFmt.JUSTIFY: - aStyle.append("text-align: justify;") + if tStyle & BlockFmt.LEFT: + aStyle.append("text-align: left;") + elif tStyle & BlockFmt.RIGHT: + aStyle.append("text-align: right;") + elif tStyle & BlockFmt.CENTRE: + aStyle.append("text-align: center;") + elif tStyle & BlockFmt.JUSTIFY: + aStyle.append("text-align: justify;") - if tStyle & BlockFmt.PBB: - aStyle.append("page-break-before: always;") - if tStyle & BlockFmt.PBA: - aStyle.append("page-break-after: always;") + if tStyle & BlockFmt.PBB: + aStyle.append("page-break-before: always;") + if tStyle & BlockFmt.PBA: + aStyle.append("page-break-after: always;") - if tStyle & BlockFmt.Z_BTM: - aStyle.append("margin-bottom: 0;") - if tStyle & BlockFmt.Z_TOP: - aStyle.append("margin-top: 0;") + if tStyle & BlockFmt.Z_BTM: + aStyle.append("margin-bottom: 0;") + if tStyle & BlockFmt.Z_TOP: + aStyle.append("margin-top: 0;") - if tStyle & BlockFmt.IND_L: - aStyle.append(f"margin-left: {self._blockIndent:.2f}em;") - if tStyle & BlockFmt.IND_R: - aStyle.append(f"margin-right: {self._blockIndent:.2f}em;") - if tStyle & BlockFmt.IND_T: - aStyle.append(f"text-indent: {self._firstWidth:.2f}em;") + if tStyle & BlockFmt.IND_L: + aStyle.append(f"margin-left: {self._blockIndent:.2f}em;") + if tStyle & BlockFmt.IND_R: + aStyle.append(f"margin-right: {self._blockIndent:.2f}em;") + if tStyle & BlockFmt.IND_T: + aStyle.append(f"text-indent: {self._firstWidth:.2f}em;") if aStyle: stVals = " ".join(aStyle) @@ -288,26 +287,25 @@ class ToHtml(Tokenizer): json.dump(data, fObj, indent=2) else: + html = [] + html.append("") + html.append("") + html.append("
") + html.append(f"