Skip footnote section if there are none

This commit is contained in:
Veronica Berglyd Olsen
2024-04-15 18:30:07 +02:00
parent 92888338f4
commit c65dee1df9
2 changed files with 27 additions and 25 deletions
+13 -12
View File
@@ -303,20 +303,21 @@ class ToHtml(Tokenizer):
def appendFootnotes(self) -> None: def appendFootnotes(self) -> None:
"""Append the footnotes in the buffer.""" """Append the footnotes in the buffer."""
tags = HTML4_TAGS if self._genMode == self.M_PREVIEW else HTML5_TAGS if self._footnotes:
footnotes = self._localLookup("Footnotes") tags = HTML4_TAGS if self._genMode == self.M_PREVIEW else HTML5_TAGS
footnotes = self._localLookup("Footnotes")
lines = [] lines = []
lines.append(f"<h3>{footnotes}</h3>\n") lines.append(f"<h3>{footnotes}</h3>\n")
lines.append("<ol>\n") lines.append("<ol>\n")
for index, content in self._footnotes.values(): for index, content in self._footnotes.values():
text = "</p><p>".join(self._formatText(t, f, tags) for t, f in content) text = "</p><p>".join(self._formatText(t, f, tags) for t, f in content)
lines.append(f"<li id='footnote_{index}'><p>{text}</p></li>\n") lines.append(f"<li id='footnote_{index}'><p>{text}</p></li>\n")
lines.append("</ol>\n") lines.append("</ol>\n")
result = "".join(lines) result = "".join(lines)
self._result += result self._result += result
self._fullHTML.append(result) self._fullHTML.append(result)
return return
+14 -13
View File
@@ -199,21 +199,22 @@ class ToMarkdown(Tokenizer):
def appendFootnotes(self) -> None: def appendFootnotes(self) -> None:
"""Append the footnotes in the buffer.""" """Append the footnotes in the buffer."""
tags = STD_MD if self._genMode == self.M_STD else EXT_MD if self._footnotes:
footnotes = self._localLookup("Footnotes") tags = STD_MD if self._genMode == self.M_STD else EXT_MD
footnotes = self._localLookup("Footnotes")
lines = [] lines = []
lines.append(f"### {footnotes}\n\n") lines.append(f"### {footnotes}\n\n")
for index, content in self._footnotes.values(): for index, content in self._footnotes.values():
marker = f"{index}. " marker = f"{index}. "
indent = "\n\n"+" "*len(marker) indent = "\n\n"+" "*len(marker)
text = indent.join(self._formatText(t, f, tags) for t, f in content) text = indent.join(self._formatText(t, f, tags) for t, f in content)
lines.append(f"{marker}{text}\n") lines.append(f"{marker}{text}\n")
lines.append("\n") lines.append("\n")
result = "".join(lines) result = "".join(lines)
self._result += result self._result += result
self._fullMD.append(result) self._fullMD.append(result)
return return