HTML export: Improve handling of missing footnote definitions

This commit is contained in:
Niklas Fasching 2019-07-07 18:01:22 +02:00
parent 09c85c3e66
commit d154403f06
4 changed files with 20 additions and 3 deletions

View file

@ -151,6 +151,16 @@ func (w *HTMLWriter) WriteFootnotes(d *Document) {
w.WriteString(`<hr class="footnotes-separatator">` + "\n") w.WriteString(`<hr class="footnotes-separatator">` + "\n")
w.WriteString(`<div class="footnote-definitions">` + "\n") w.WriteString(`<div class="footnote-definitions">` + "\n")
for i, definition := range w.footnotes.list { for i, definition := range w.footnotes.list {
if definition == nil {
name := ""
for k, v := range w.footnotes.mapping {
if v == i {
name = k
}
}
w.log.Printf("Missing footnote definition for [fn:%s] (#%d)", name, i)
continue
}
w.WriteString(`<div class="footnote-definition">` + "\n") w.WriteString(`<div class="footnote-definition">` + "\n")
w.WriteString(fmt.Sprintf(`<sup id="footnote-%d"><a href="#footnote-reference-%d">%d</a></sup>`, i, i, i) + "\n") w.WriteString(fmt.Sprintf(`<sup id="footnote-%d"><a href="#footnote-reference-%d">%d</a></sup>`, i, i, i) + "\n")
w.WriteString(`<div class="footnote-body">` + "\n") w.WriteString(`<div class="footnote-body">` + "\n")

View file

@ -36,15 +36,20 @@ Footnote definitions are not printed where they appear.
Rather, they are gathered and exported at the end of the document in the footnote section. <sup class="footnote-reference"><a id="footnote-reference-5" href="#footnote-5">5</a></sup> Rather, they are gathered and exported at the end of the document in the footnote section. <sup class="footnote-reference"><a id="footnote-reference-5" href="#footnote-5">5</a></sup>
</p> </p>
</li> </li>
<li>
<p>
footnotes that reference a non-existant definition are rendered but log a warning <sup class="footnote-reference"><a id="footnote-reference-6" href="#footnote-6">6</a></sup>
</p>
</li>
</ul> </ul>
<h1 id="headline-2"> <h1 id="headline-2">
Footnotes Footnotes
</h1> </h1>
<p> <p>
Please note that the footnotes section is not automatically excluded from the export like in emacs. <sup class="footnote-reference"><a id="footnote-reference-6" href="#footnote-6">6</a></sup> Please note that the footnotes section is not automatically excluded from the export like in emacs. <sup class="footnote-reference"><a id="footnote-reference-7" href="#footnote-7">7</a></sup>
</p> </p>
<p> <p>
this is not part of <sup class="footnote-reference"><a id="footnote-reference-6" href="#footnote-6">6</a></sup> anymore as there are 2 blank lines in between! this is not part of <sup class="footnote-reference"><a id="footnote-reference-7" href="#footnote-7">7</a></sup> anymore as there are 2 blank lines in between!
</p> </p>
<div class="footnotes"> <div class="footnotes">
<hr class="footnotes-separatator"> <hr class="footnotes-separatator">
@ -147,7 +152,7 @@ Rather, it will be somewhere down below in the footnotes section.
</div> </div>
</div> </div>
<div class="footnote-definition"> <div class="footnote-definition">
<sup id="footnote-6"><a href="#footnote-reference-6">6</a></sup> <sup id="footnote-7"><a href="#footnote-reference-7">7</a></sup>
<div class="footnote-body"> <div class="footnote-body">
<p> <p>
There&#39;s multiple reasons for that. Among others, doing so requires i18n (to recognize the section) and silently There&#39;s multiple reasons for that. Among others, doing so requires i18n (to recognize the section) and silently

View file

@ -5,6 +5,7 @@
- anonymous inline footnotes are also supported via [fn::the anonymous inline footnote definition]. - anonymous inline footnotes are also supported via [fn::the anonymous inline footnote definition].
- Footnote definitions are not printed where they appear. - Footnote definitions are not printed where they appear.
Rather, they are gathered and exported at the end of the document in the footnote section. [fn:4] Rather, they are gathered and exported at the end of the document in the footnote section. [fn:4]
- footnotes that reference a non-existant definition are rendered but log a warning [fn:does-not-exist]
[fn:4] so this definition will not be at the end of this section in the exported document. [fn:4] so this definition will not be at the end of this section in the exported document.
Rather, it will be somewhere down below in the footnotes section. Rather, it will be somewhere down below in the footnotes section.

View file

@ -5,6 +5,7 @@
- anonymous inline footnotes are also supported via [fn::the anonymous inline footnote definition]. - anonymous inline footnotes are also supported via [fn::the anonymous inline footnote definition].
- Footnote definitions are not printed where they appear. - Footnote definitions are not printed where they appear.
Rather, they are gathered and exported at the end of the document in the footnote section. [fn:4] Rather, they are gathered and exported at the end of the document in the footnote section. [fn:4]
- footnotes that reference a non-existant definition are rendered but log a warning [fn:does-not-exist]
[fn:4] so this definition will not be at the end of this section in the exported document. [fn:4] so this definition will not be at the end of this section in the exported document.
Rather, it will be somewhere down below in the footnotes section. Rather, it will be somewhere down below in the footnotes section.