From 5fddfd395e95f970597d1db49684e1247c70d2ae Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sat, 25 Jan 2025 21:06:20 +0100 Subject: [PATCH] Update HTML output --- novelwriter/formats/tohtml.py | 33 ++++++++++++++----- .../mBuildDocBuild_HTML5_Lorem_Ipsum.htm | 12 +++---- .../mBuildDocBuild_HTML5_Lorem_Ipsum.json | 14 ++++---- tests/test_formats/test_fmt_tohtml.py | 2 -- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/novelwriter/formats/tohtml.py b/novelwriter/formats/tohtml.py index 9db18616..fb2c1ee5 100644 --- a/novelwriter/formats/tohtml.py +++ b/novelwriter/formats/tohtml.py @@ -30,7 +30,7 @@ from pathlib import Path from time import time from novelwriter.common import formatTimeStamp -from novelwriter.constants import nwHtmlUnicode +from novelwriter.constants import nwHtmlUnicode, nwStyles from novelwriter.core.project import NWProject from novelwriter.formats.shared import BlockFmt, BlockTyp, T_Formats, TextFmt, stripEscape from novelwriter.formats.tokenizer import Tokenizer @@ -296,9 +296,7 @@ class ToHtml(Tokenizer): "\n" "\n" "\n" - "
\n" "{body:s}\n" - "
\n" "\n" "\n" ).format( @@ -345,6 +343,12 @@ class ToHtml(Tokenizer): mtSP = self._marginSep[0] mbSP = self._marginSep[1] + fSz0 = nwStyles.H_SIZES[0] + fSz1 = nwStyles.H_SIZES[1] + fSz2 = nwStyles.H_SIZES[2] + fSz3 = nwStyles.H_SIZES[3] + fSz4 = nwStyles.H_SIZES[4] + font = self._textFont fFam = font.family() fSz = font.pointSize() @@ -365,12 +369,25 @@ class ToHtml(Tokenizer): styles.append(f"a {{color: {lColor};}}") styles.append(f"mark {{background: {mColor};}}") styles.append(f"h1, h2, h3, h4 {{color: {hColor}; page-break-after: avoid;}}") - styles.append(f"h1 {{margin-top: {mtH1:.2f}em; margin-bottom: {mbH1:.2f}em;}}") - styles.append(f"h2 {{margin-top: {mtH2:.2f}em; margin-bottom: {mbH2:.2f}em;}}") - styles.append(f"h3 {{margin-top: {mtH3:.2f}em; margin-bottom: {mbH3:.2f}em;}}") - styles.append(f"h4 {{margin-top: {mtH4:.2f}em; margin-bottom: {mbH4:.2f}em;}}") styles.append( - f".title {{font-size: 2.5em; margin-top: {mtH0:.2f}em; margin-bottom: {mbH0:.2f}em;}}" + f"h1 {{font-size: {fSz1:.2f}em; " + f"margin-top: {mtH1:.2f}em; margin-bottom: {mbH1:.2f}em;}}" + ) + styles.append( + f"h2 {{font-size: {fSz2:.2f}em; " + f"margin-top: {mtH2:.2f}em; margin-bottom: {mbH2:.2f}em;}}" + ) + styles.append( + f"h3 {{font-size: {fSz3:.2f}em; " + f"margin-top: {mtH3:.2f}em; margin-bottom: {mbH3:.2f}em;}}" + ) + styles.append( + f"h4 {{font-size: {fSz4:.2f}em; " + f"margin-top: {mtH4:.2f}em; margin-bottom: {mbH4:.2f}em;}}" + ) + styles.append( + f".title {{font-size: {fSz0:.2f}em; " + f"margin-top: {mtH0:.2f}em; margin-bottom: {mbH0:.2f}em;}}" ) styles.append( f".sep {{text-align: center; margin-top: {mtSP:.2f}em; margin-bottom: {mbSP:.2f}em;}}" diff --git a/tests/reference/mBuildDocBuild_HTML5_Lorem_Ipsum.htm b/tests/reference/mBuildDocBuild_HTML5_Lorem_Ipsum.htm index 8632ec97..f605b0fa 100644 --- a/tests/reference/mBuildDocBuild_HTML5_Lorem_Ipsum.htm +++ b/tests/reference/mBuildDocBuild_HTML5_Lorem_Ipsum.htm @@ -9,16 +9,15 @@ p {text-align: left; line-height: 150%; margin-top: 0.00em; margin-bottom: 0.60e a {color: #4271ae;} mark {background: #ffffa6;} h1, h2, h3, h4 {color: #4271ae; page-break-after: avoid;} -h1 {margin-top: 1.50em; margin-bottom: 0.60em;} -h2 {margin-top: 1.50em; margin-bottom: 0.60em;} -h3 {margin-top: 1.20em; margin-bottom: 0.60em;} -h4 {margin-top: 1.20em; margin-bottom: 0.60em;} -.title {font-size: 2.5em; margin-top: 1.50em; margin-bottom: 0.60em;} +h1 {font-size: 2.00em; margin-top: 1.50em; margin-bottom: 0.60em;} +h2 {font-size: 1.75em; margin-top: 1.50em; margin-bottom: 0.60em;} +h3 {font-size: 1.50em; margin-top: 1.20em; margin-bottom: 0.60em;} +h4 {font-size: 1.25em; margin-top: 1.20em; margin-bottom: 0.60em;} +.title {font-size: 2.50em; margin-top: 1.50em; margin-bottom: 0.60em;} .sep {text-align: center; margin-top: 1.20em; margin-bottom: 1.20em;} -

Lorem Ipsum

By lipsum.com

Word Count: 4,169

@@ -125,6 +124,5 @@ h4 {margin-top: 1.20em; margin-bottom: 0.60em;}
  1. Lorem ipsum is typically a corrupted version of De finibus bonorum et malorum, a 1st-century BC text by the Roman statesman and philosopher Cicero, with words altered, added, and removed to make it nonsensical and improper Latin. (Source: Wikipedia)

-
diff --git a/tests/reference/mBuildDocBuild_HTML5_Lorem_Ipsum.json b/tests/reference/mBuildDocBuild_HTML5_Lorem_Ipsum.json index 8ad0ccc8..7a4134ef 100644 --- a/tests/reference/mBuildDocBuild_HTML5_Lorem_Ipsum.json +++ b/tests/reference/mBuildDocBuild_HTML5_Lorem_Ipsum.json @@ -2,8 +2,8 @@ "meta": { "projectName": "Lorem Ipsum", "novelAuthor": "lipsum.com", - "buildTime": 1731526420, - "buildTimeStr": "2024-11-13 20:33:40" + "buildTime": 1737835371, + "buildTimeStr": "2025-01-25 21:02:51" }, "text": { "css": [ @@ -12,11 +12,11 @@ "a {color: #4271ae;}", "mark {background: #ffffa6;}", "h1, h2, h3, h4 {color: #4271ae; page-break-after: avoid;}", - "h1 {margin-top: 1.50em; margin-bottom: 0.60em;}", - "h2 {margin-top: 1.50em; margin-bottom: 0.60em;}", - "h3 {margin-top: 1.20em; margin-bottom: 0.60em;}", - "h4 {margin-top: 1.20em; margin-bottom: 0.60em;}", - ".title {font-size: 2.5em; margin-top: 1.50em; margin-bottom: 0.60em;}", + "h1 {font-size: 2.00em; margin-top: 1.50em; margin-bottom: 0.60em;}", + "h2 {font-size: 1.75em; margin-top: 1.50em; margin-bottom: 0.60em;}", + "h3 {font-size: 1.50em; margin-top: 1.20em; margin-bottom: 0.60em;}", + "h4 {font-size: 1.25em; margin-top: 1.20em; margin-bottom: 0.60em;}", + ".title {font-size: 2.50em; margin-top: 1.50em; margin-bottom: 0.60em;}", ".sep {text-align: center; margin-top: 1.20em; margin-bottom: 1.20em;}" ], "html": [ diff --git a/tests/test_formats/test_fmt_tohtml.py b/tests/test_formats/test_fmt_tohtml.py index 5ec08385..e00bb501 100644 --- a/tests/test_formats/test_fmt_tohtml.py +++ b/tests/test_formats/test_fmt_tohtml.py @@ -677,9 +677,7 @@ def testFmtToHtml_Save(mockGUI, fncPath): "\n" "\n" "\n" - "
\n" "{bodyText:s}\n" - "
\n" "\n" "\n" ).format(