From 5a25d34ba3a1dcbff185b768f7e80cd0ebc5d56a Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sat, 25 Jan 2025 15:05:11 +0100 Subject: [PATCH] Update HTML to work with new chapter headers --- novelwriter/formats/tohtml.py | 30 +++++++-------------------- tests/test_formats/test_fmt_tohtml.py | 14 ++++++------- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/novelwriter/formats/tohtml.py b/novelwriter/formats/tohtml.py index 51e746d0..3aae33be 100644 --- a/novelwriter/formats/tohtml.py +++ b/novelwriter/formats/tohtml.py @@ -130,20 +130,6 @@ class ToHtml(Tokenizer): def doConvert(self) -> None: """Convert the list of text tokens into an HTML document.""" - if self._isNovel: - # For story files, we bump the titles one level up - h1Cl = " class='title'" - h1 = "h1" - h2 = "h1" - h3 = "h2" - h4 = "h3" - else: - h1Cl = "" - h1 = "h1" - h2 = "h2" - h3 = "h3" - h4 = "h4" - lines = [] for tType, tMeta, tText, tFmt, tStyle in self._blocks: @@ -213,25 +199,25 @@ class ToHtml(Tokenizer): if tType == BlockTyp.TEXT: lines.append(f"
{self._formatText(tText, tFmt)}
\n") - elif tType == BlockTyp.TITLE: + elif tType in (BlockTyp.TITLE, BlockTyp.PART): tHead = tText.replace("\n", "{tText}
\n") diff --git a/tests/test_formats/test_fmt_tohtml.py b/tests/test_formats/test_fmt_tohtml.py index 0e2ad9df..aaba1c95 100644 --- a/tests/test_formats/test_fmt_tohtml.py +++ b/tests/test_formats/test_fmt_tohtml.py @@ -410,7 +410,7 @@ def testFmtToHtml_ConvertDirect(mockGUI): # Unnumbered html._blocks = [ - (BlockTyp.HEAD2, tMeta, "Prologue", [], BlockFmt.PBB), + (BlockTyp.CHAPTER, tMeta, "Prologue", [], BlockFmt.PBB), ] html.doConvert() assert html._pages[-1] == ( @@ -443,7 +443,7 @@ def testFmtToHtml_ConvertDirect(mockGUI): # Align Left html.setStyles(False) html._blocks = [ - (BlockTyp.HEAD1, tMeta, "A Title", [], BlockFmt.LEFT), + (BlockTyp.PART, tMeta, "A Title", [], BlockFmt.LEFT), ] html.doConvert() assert html._pages[-1] == ( @@ -454,7 +454,7 @@ def testFmtToHtml_ConvertDirect(mockGUI): # Align Left html._blocks = [ - (BlockTyp.HEAD1, tMeta, "A Title", [], BlockFmt.LEFT), + (BlockTyp.PART, tMeta, "A Title", [], BlockFmt.LEFT), ] html.doConvert() assert html._pages[-1] == ( @@ -463,7 +463,7 @@ def testFmtToHtml_ConvertDirect(mockGUI): # Align Right html._blocks = [ - (BlockTyp.HEAD1, tMeta, "A Title", [], BlockFmt.RIGHT), + (BlockTyp.PART, tMeta, "A Title", [], BlockFmt.RIGHT), ] html.doConvert() assert html._pages[-1] == ( @@ -472,7 +472,7 @@ def testFmtToHtml_ConvertDirect(mockGUI): # Align Centre html._blocks = [ - (BlockTyp.HEAD1, tMeta, "A Title", [], BlockFmt.CENTRE), + (BlockTyp.PART, tMeta, "A Title", [], BlockFmt.CENTRE), ] html.doConvert() assert html._pages[-1] == ( @@ -481,7 +481,7 @@ def testFmtToHtml_ConvertDirect(mockGUI): # Align Justify html._blocks = [ - (BlockTyp.HEAD1, tMeta, "A Title", [], BlockFmt.JUSTIFY), + (BlockTyp.PART, tMeta, "A Title", [], BlockFmt.JUSTIFY), ] html.doConvert() assert html._pages[-1] == ( @@ -493,7 +493,7 @@ def testFmtToHtml_ConvertDirect(mockGUI): # Page Break Always html._blocks = [ - (BlockTyp.HEAD1, tMeta, "A Title", [], BlockFmt.PBB | BlockFmt.PBA), + (BlockTyp.PART, tMeta, "A Title", [], BlockFmt.PBB | BlockFmt.PBA), ] html.doConvert() assert html._pages[-1] == (