From c65dee1df9006f2693514d98c15df5bac55481c3 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Mon, 15 Apr 2024 18:30:07 +0200 Subject: [PATCH] Skip footnote section if there are none --- novelwriter/core/tohtml.py | 25 +++++++++++++------------ novelwriter/core/tomd.py | 27 ++++++++++++++------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/novelwriter/core/tohtml.py b/novelwriter/core/tohtml.py index d513d4ea..07621512 100644 --- a/novelwriter/core/tohtml.py +++ b/novelwriter/core/tohtml.py @@ -303,20 +303,21 @@ class ToHtml(Tokenizer): def appendFootnotes(self) -> None: """Append the footnotes in the buffer.""" - tags = HTML4_TAGS if self._genMode == self.M_PREVIEW else HTML5_TAGS - footnotes = self._localLookup("Footnotes") + if self._footnotes: + tags = HTML4_TAGS if self._genMode == self.M_PREVIEW else HTML5_TAGS + footnotes = self._localLookup("Footnotes") - lines = [] - lines.append(f"

{footnotes}

\n") - lines.append("
    \n") - for index, content in self._footnotes.values(): - text = "

    ".join(self._formatText(t, f, tags) for t, f in content) - lines.append(f"

  1. {text}

  2. \n") - lines.append("
\n") + lines = [] + lines.append(f"

{footnotes}

\n") + lines.append("
    \n") + for index, content in self._footnotes.values(): + text = "

    ".join(self._formatText(t, f, tags) for t, f in content) + lines.append(f"

  1. {text}

  2. \n") + lines.append("
\n") - result = "".join(lines) - self._result += result - self._fullHTML.append(result) + result = "".join(lines) + self._result += result + self._fullHTML.append(result) return diff --git a/novelwriter/core/tomd.py b/novelwriter/core/tomd.py index e9e7dc65..567953ab 100644 --- a/novelwriter/core/tomd.py +++ b/novelwriter/core/tomd.py @@ -199,21 +199,22 @@ class ToMarkdown(Tokenizer): def appendFootnotes(self) -> None: """Append the footnotes in the buffer.""" - tags = STD_MD if self._genMode == self.M_STD else EXT_MD - footnotes = self._localLookup("Footnotes") + if self._footnotes: + tags = STD_MD if self._genMode == self.M_STD else EXT_MD + footnotes = self._localLookup("Footnotes") - lines = [] - lines.append(f"### {footnotes}\n\n") - for index, content in self._footnotes.values(): - marker = f"{index}. " - indent = "\n\n"+" "*len(marker) - text = indent.join(self._formatText(t, f, tags) for t, f in content) - lines.append(f"{marker}{text}\n") - lines.append("\n") + lines = [] + lines.append(f"### {footnotes}\n\n") + for index, content in self._footnotes.values(): + marker = f"{index}. " + indent = "\n\n"+" "*len(marker) + text = indent.join(self._formatText(t, f, tags) for t, f in content) + lines.append(f"{marker}{text}\n") + lines.append("\n") - result = "".join(lines) - self._result += result - self._fullMD.append(result) + result = "".join(lines) + self._result += result + self._fullMD.append(result) return