HTML export: Update footnote numbering to start with 1

I went with 0 based numbering because it was easier but after looking at the
results 0 based numbering looks bad to me... let's start with 1 like everyone
else as it's just a few more lines of code.
This commit is contained in:
Niklas Fasching 2019-07-07 21:25:42 +02:00
parent d154403f06
commit 777899c803
3 changed files with 23 additions and 21 deletions

View file

@ -151,6 +151,7 @@ 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 {
id := i + 1
if definition == nil { if definition == nil {
name := "" name := ""
for k, v := range w.footnotes.mapping { for k, v := range w.footnotes.mapping {
@ -158,11 +159,11 @@ func (w *HTMLWriter) WriteFootnotes(d *Document) {
name = k name = k
} }
} }
w.log.Printf("Missing footnote definition for [fn:%s] (#%d)", name, i) w.log.Printf("Missing footnote definition for [fn:%s] (#%d)", name, id)
continue 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>`, id, id, id) + "\n")
w.WriteString(`<div class="footnote-body">` + "\n") w.WriteString(`<div class="footnote-body">` + "\n")
WriteNodes(w, definition.Children...) WriteNodes(w, definition.Children...)
w.WriteString("</div>\n</div>\n") w.WriteString("</div>\n</div>\n")
@ -262,7 +263,8 @@ func (w *HTMLWriter) WriteFootnoteLink(l FootnoteLink) {
if !w.document.GetOption("f") { if !w.document.GetOption("f") {
return return
} }
id := w.footnotes.add(l) i := w.footnotes.add(l)
id := i + 1
w.WriteString(fmt.Sprintf(`<sup class="footnote-reference"><a id="footnote-reference-%d" href="#footnote-%d">%d</a></sup>`, id, id, id)) w.WriteString(fmt.Sprintf(`<sup class="footnote-reference"><a id="footnote-reference-%d" href="#footnote-%d">%d</a></sup>`, id, id, id))
} }

View file

@ -12,33 +12,33 @@ Using some footnotes
<ul> <ul>
<li> <li>
<p> <p>
normal footnote reference <sup class="footnote-reference"><a id="footnote-reference-0" href="#footnote-0">0</a></sup> <sup class="footnote-reference"><a id="footnote-reference-1" href="#footnote-1">1</a></sup> <sup class="footnote-reference"><a id="footnote-reference-2" href="#footnote-2">2</a></sup> (footnote names can be anything in the format <code class="verbatim">[\w-]</code>) normal footnote reference <sup class="footnote-reference"><a id="footnote-reference-1" href="#footnote-1">1</a></sup> <sup class="footnote-reference"><a id="footnote-reference-2" href="#footnote-2">2</a></sup> <sup class="footnote-reference"><a id="footnote-reference-3" href="#footnote-3">3</a></sup> (footnote names can be anything in the format <code class="verbatim">[\w-]</code>)
</p> </p>
</li> </li>
<li> <li>
<p> <p>
further references to the same footnote should not <sup class="footnote-reference"><a id="footnote-reference-0" href="#footnote-0">0</a></sup> render duplicates in the footnote list further references to the same footnote should not <sup class="footnote-reference"><a id="footnote-reference-1" href="#footnote-1">1</a></sup> render duplicates in the footnote list
</p> </p>
</li> </li>
<li> <li>
<p> <p>
inline footnotes are also supported via <sup class="footnote-reference"><a id="footnote-reference-3" href="#footnote-3">3</a></sup>. inline footnotes are also supported via <sup class="footnote-reference"><a id="footnote-reference-4" href="#footnote-4">4</a></sup>.
</p> </p>
</li> </li>
<li> <li>
<p> <p>
anonymous inline footnotes are also supported via <sup class="footnote-reference"><a id="footnote-reference-4" href="#footnote-4">4</a></sup>. anonymous inline footnotes are also supported via <sup class="footnote-reference"><a id="footnote-reference-5" href="#footnote-5">5</a></sup>.
</p> </p>
</li> </li>
<li> <li>
<p> <p>
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. <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-6" href="#footnote-6">6</a></sup>
</p> </p>
</li> </li>
<li> <li>
<p> <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> footnotes that reference a non-existant definition are rendered but log a warning <sup class="footnote-reference"><a id="footnote-reference-7" href="#footnote-7">7</a></sup>
</p> </p>
</li> </li>
</ul> </ul>
@ -46,16 +46,16 @@ footnotes that reference a non-existant definition are rendered but log a warnin
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-7" href="#footnote-7">7</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-8" href="#footnote-8">8</a></sup>
</p> </p>
<p> <p>
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! this is not part of <sup class="footnote-reference"><a id="footnote-reference-8" href="#footnote-8">8</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">
<div class="footnote-definitions"> <div class="footnote-definitions">
<div class="footnote-definition"> <div class="footnote-definition">
<sup id="footnote-0"><a href="#footnote-reference-0">0</a></sup> <sup id="footnote-1"><a href="#footnote-reference-1">1</a></sup>
<div class="footnote-body"> <div class="footnote-body">
<p> <p>
<a href="https://www.example.com">https://www.example.com</a> <a href="https://www.example.com">https://www.example.com</a>
@ -110,7 +110,7 @@ and tables
</div> </div>
</div> </div>
<div class="footnote-definition"> <div class="footnote-definition">
<sup id="footnote-1"><a href="#footnote-reference-1">1</a></sup> <sup id="footnote-2"><a href="#footnote-reference-2">2</a></sup>
<div class="footnote-body"> <div class="footnote-body">
<p> <p>
Footnotes break after two consecutive empty lines - just like paragraphs - see <a href="https://orgmode.org/worg/dev/org-syntax.html.">https://orgmode.org/worg/dev/org-syntax.html.</a> Footnotes break after two consecutive empty lines - just like paragraphs - see <a href="https://orgmode.org/worg/dev/org-syntax.html.">https://orgmode.org/worg/dev/org-syntax.html.</a>
@ -119,7 +119,7 @@ This shouldn&#39;t happen when the definition line and the line after that are e
</div> </div>
</div> </div>
<div class="footnote-definition"> <div class="footnote-definition">
<sup id="footnote-2"><a href="#footnote-reference-2">2</a></sup> <sup id="footnote-3"><a href="#footnote-reference-3">3</a></sup>
<div class="footnote-body"> <div class="footnote-body">
<p> <p>
yolo yolo
@ -127,7 +127,7 @@ yolo
</div> </div>
</div> </div>
<div class="footnote-definition"> <div class="footnote-definition">
<sup id="footnote-3"><a href="#footnote-reference-3">3</a></sup> <sup id="footnote-4"><a href="#footnote-reference-4">4</a></sup>
<div class="footnote-body"> <div class="footnote-body">
<p> <p>
the inline footnote definition the inline footnote definition
@ -135,7 +135,7 @@ the inline footnote definition
</div> </div>
</div> </div>
<div class="footnote-definition"> <div class="footnote-definition">
<sup id="footnote-4"><a href="#footnote-reference-4">4</a></sup> <sup id="footnote-5"><a href="#footnote-reference-5">5</a></sup>
<div class="footnote-body"> <div class="footnote-body">
<p> <p>
the anonymous inline footnote definition the anonymous inline footnote definition
@ -143,7 +143,7 @@ the anonymous inline footnote definition
</div> </div>
</div> </div>
<div class="footnote-definition"> <div class="footnote-definition">
<sup id="footnote-5"><a href="#footnote-reference-5">5</a></sup> <sup id="footnote-6"><a href="#footnote-reference-6">6</a></sup>
<div class="footnote-body"> <div class="footnote-body">
<p> <p>
so this definition will not be at the end of this section in the exported document. so this definition will not be at the end of this section in the exported document.
@ -152,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-7"><a href="#footnote-reference-7">7</a></sup> <sup id="footnote-8"><a href="#footnote-reference-8">8</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

@ -413,7 +413,7 @@ src/example/export blocks should not be converted!
<a href="https://github.com/chaseadamsio/goorgeous/issues/87">#87</a>: Markup in footnotes is rendered literally <a href="https://github.com/chaseadamsio/goorgeous/issues/87">#87</a>: Markup in footnotes is rendered literally
</h3> </h3>
<p> <p>
footnotes can contain <strong>markup</strong> - and other elements and stuff <sup class="footnote-reference"><a id="footnote-reference-0" href="#footnote-0">0</a></sup> <sup class="footnote-reference"><a id="footnote-reference-1" href="#footnote-1">1</a></sup> footnotes can contain <strong>markup</strong> - and other elements and stuff <sup class="footnote-reference"><a id="footnote-reference-1" href="#footnote-1">1</a></sup> <sup class="footnote-reference"><a id="footnote-reference-2" href="#footnote-2">2</a></sup>
</p> </p>
<h3 id="headline-23"> <h3 id="headline-23">
<span class="todo">DONE</span> <span class="todo">DONE</span>
@ -482,7 +482,7 @@ Footnotes
<hr class="footnotes-separatator"> <hr class="footnotes-separatator">
<div class="footnote-definitions"> <div class="footnote-definitions">
<div class="footnote-definition"> <div class="footnote-definition">
<sup id="footnote-0"><a href="#footnote-reference-0">0</a></sup> <sup id="footnote-1"><a href="#footnote-reference-1">1</a></sup>
<div class="footnote-body"> <div class="footnote-body">
<p> <p>
a footnote <em>with</em> <strong>markup</strong> a footnote <em>with</em> <strong>markup</strong>
@ -502,7 +502,7 @@ because that&#39;s possible
</div> </div>
</div> </div>
<div class="footnote-definition"> <div class="footnote-definition">
<sup id="footnote-1"><a href="#footnote-reference-1">1</a></sup> <sup id="footnote-2"><a href="#footnote-reference-2">2</a></sup>
<div class="footnote-body"> <div class="footnote-body">
<p> <p>
that also goes for <strong>inline</strong> footnote <em>definitions</em> that also goes for <strong>inline</strong> footnote <em>definitions</em>