HTML export: Export #+TITLE as h1 and offset other headlines accordingly

emacs exports #+TITLE as <h1> and all other headlines accordingly as
`lvl + 1` - we'll go with that.
This commit is contained in:
Niklas Fasching 2019-12-22 13:58:19 +01:00
parent b61e49eb85
commit 614307a8f5
8 changed files with 90 additions and 84 deletions

View file

@ -88,6 +88,9 @@ func (w *HTMLWriter) WriterWithExtensions() Writer {
func (w *HTMLWriter) Before(d *Document) { func (w *HTMLWriter) Before(d *Document) {
w.document = d w.document = d
w.log = d.Log w.log = d.Log
if title := d.Get("TITLE"); title != "" {
w.WriteString(fmt.Sprintf(`<h1 class="title">%s</h1>`+"\n", title))
}
w.WriteOutline(d) w.WriteOutline(d)
} }
@ -214,7 +217,7 @@ func (w *HTMLWriter) WriteHeadline(h Headline) {
} }
} }
w.WriteString(fmt.Sprintf(`<h%d id="%s">`, h.Lvl, h.ID()) + "\n") w.WriteString(fmt.Sprintf(`<h%d id="%s">`, h.Lvl+1, h.ID()) + "\n")
if w.document.GetOption("todo") && h.Status != "" { if w.document.GetOption("todo") && h.Status != "" {
w.WriteString(fmt.Sprintf(`<span class="todo">%s</span>`, h.Status) + "\n") w.WriteString(fmt.Sprintf(`<span class="todo">%s</span>`, h.Status) + "\n")
} }
@ -231,7 +234,7 @@ func (w *HTMLWriter) WriteHeadline(h Headline) {
w.WriteString("&#xa0;&#xa0;&#xa0;") w.WriteString("&#xa0;&#xa0;&#xa0;")
w.WriteString(fmt.Sprintf(`<span class="tags">%s</span>`, strings.Join(tags, "&#xa0;"))) w.WriteString(fmt.Sprintf(`<span class="tags">%s</span>`, strings.Join(tags, "&#xa0;")))
} }
w.WriteString(fmt.Sprintf("\n</h%d>\n", h.Lvl)) w.WriteString(fmt.Sprintf("\n</h%d>\n", h.Lvl+1))
WriteNodes(w, h.Children...) WriteNodes(w, h.Children...)
} }

View file

@ -6,9 +6,9 @@
</li> </li>
</ul> </ul>
</nav> </nav>
<h1 id="headline-1"> <h2 id="headline-1">
Using some footnotes Using some footnotes
</h1> </h2>
<ul> <ul>
<li> <li>
<p> <p>
@ -42,9 +42,9 @@ footnotes that reference a non-existant definition are rendered but log a warnin
</p> </p>
</li> </li>
</ul> </ul>
<h1 id="headline-2"> <h2 id="headline-2">
Footnotes Footnotes
</h1> </h2>
<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-8" href="#footnote-8">8</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>

View file

@ -4,9 +4,9 @@
</li> </li>
</ul> </ul>
</nav> </nav>
<h1 id="headline-1"> <h2 id="headline-1">
Title <sup class="footnote-reference"><a id="footnote-reference-1" href="#footnote-1">1</a></sup> Title <sup class="footnote-reference"><a id="footnote-reference-1" href="#footnote-1">1</a></sup>
</h1> </h2>
<div class="footnotes"> <div class="footnotes">
<hr class="footnotes-separatator"> <hr class="footnotes-separatator">
<div class="footnote-definitions"> <div class="footnote-definitions">

View file

@ -16,9 +16,9 @@
</li> </li>
</ul> </ul>
</nav> </nav>
<h1 id="headline-1"> <h2 id="headline-1">
Simple Headline <code class="statistic">[1/2]</code> Simple Headline <code class="statistic">[1/2]</code>
</h1> </h2>
<ul> <ul>
<li class="checked"> <li class="checked">
<p> <p>
@ -38,22 +38,22 @@ not just where they are actually meant to be - even here &gt; <code class="stati
</p> </p>
</li> </li>
</ul> </ul>
<h1 id="headline-2"> <h2 id="headline-2">
<span class="todo">TODO</span> <span class="todo">TODO</span>
<span class="priority">[B]</span> <span class="priority">[B]</span>
Headline with todo status &amp; priority Headline with todo status &amp; priority
</h1> </h2>
<h1 id="this-will-be-the-id-of-the-headline"> <h2 id="this-will-be-the-id-of-the-headline">
<span class="todo">DONE</span> <span class="todo">DONE</span>
Headline with TODO status Headline with TODO status
</h1> </h2>
<p> <p>
we can link to headlines that define a custom_id: <a href="#this-will-be-the-id-of-the-headline">#this-will-be-the-id-of-the-headline</a> we can link to headlines that define a custom_id: <a href="#this-will-be-the-id-of-the-headline">#this-will-be-the-id-of-the-headline</a>
</p> </p>
<h1 id="headline-4"> <h2 id="headline-4">
<span class="priority">[A]</span> <span class="priority">[A]</span>
Headline with tags &amp; priority&#xa0;&#xa0;&#xa0;<span class="tags"><span>foo</span>&#xa0;<span>bar</span></span> Headline with tags &amp; priority&#xa0;&#xa0;&#xa0;<span class="tags"><span>foo</span>&#xa0;<span>bar</span></span>
</h1> </h2>
<p> <p>
Still outside the drawer Still outside the drawer
</p> </p>
@ -63,10 +63,10 @@ This is inside the drawer
<p> <p>
Still outside the drawer Still outside the drawer
</p> </p>
<h1 id="headline-5"> <h2 id="headline-5">
<span class="todo">CUSTOM</span> <span class="todo">CUSTOM</span>
headline with custom status headline with custom status
</h1> </h2>
<p> <p>
it&#39;s possible to use <code class="verbatim">#+SETUPFILE</code> - in this case the setup file contains the following it&#39;s possible to use <code class="verbatim">#+SETUPFILE</code> - in this case the setup file contains the following
</p> </p>
@ -78,9 +78,9 @@ it&#39;s possible to use <code class="verbatim">#+SETUPFILE</code> - in this cas
</pre> </pre>
</div> </div>
</div> </div>
<h1 id="headline-7"> <h2 id="headline-7">
malformed property drawer malformed property drawer
</h1> </h2>
<p> <p>
:PROPERTIES: :PROPERTIES:
not a property not a property

125
org/testdata/misc.html vendored
View file

@ -1,3 +1,4 @@
<h1 class="title">Misc</h1>
<nav> <nav>
<ul> <ul>
<li><a href="#headline-1">issues from goorgeous (free test cases, yay!)</a> <li><a href="#headline-1">issues from goorgeous (free test cases, yay!)</a>
@ -76,18 +77,18 @@
</li> </li>
</ul> </ul>
</nav> </nav>
<h2 id="headline-1"> <h3 id="headline-1">
issues from goorgeous (free test cases, yay!) issues from goorgeous (free test cases, yay!)
</h2> </h3>
<h3 id="headline-2"> <h4 id="headline-2">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/19">#19</a>: Support #+HTML <a href="https://github.com/chaseadamsio/goorgeous/issues/19">#19</a>: Support #+HTML
</h3> </h4>
<p style="border: 1px dotted grey">neato!</p> <p style="border: 1px dotted grey">neato!</p>
<h3 id="headline-3"> <h4 id="headline-3">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/29">#29:</a> Support verse block <a href="https://github.com/chaseadamsio/goorgeous/issues/29">#29:</a> Support verse block
</h3> </h4>
<div class="verse-block"> <div class="verse-block">
<p> <p>
This This
@ -101,17 +102,17 @@ or even a <strong>totally</strong> <em>custom</em> kind of block
crazy ain&#39;t it? crazy ain&#39;t it?
</p> </p>
</div> </div>
<h3 id="headline-4"> <h4 id="headline-4">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/30">#30</a>: Support #+SETUPFILE <a href="https://github.com/chaseadamsio/goorgeous/issues/30">#30</a>: Support #+SETUPFILE
</h3> </h4>
<p> <p>
see <code class="verbatim">./headlines.org</code> see <code class="verbatim">./headlines.org</code>
</p> </p>
<h3 id="headline-5"> <h4 id="headline-5">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/31">#31</a>: Support #+INCLUDE <a href="https://github.com/chaseadamsio/goorgeous/issues/31">#31</a>: Support #+INCLUDE
</h3> </h4>
<p> <p>
Note that only src/example/export block inclusion is supported for now. Note that only src/example/export block inclusion is supported for now.
There&#39;s quite a lot more to include (see the <a href="https://orgmode.org/manual/Include-files.html">org manual for include files</a>) but I There&#39;s quite a lot more to include (see the <a href="https://orgmode.org/manual/Include-files.html">org manual for include files</a>) but I
@ -207,10 +208,10 @@ deploy:
</pre> </pre>
</li> </li>
</ul> </ul>
<h3 id="headline-6"> <h4 id="headline-6">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/33">#33</a>: Wrong output when mixing html with Org mode <a href="https://github.com/chaseadamsio/goorgeous/issues/33">#33</a>: Wrong output when mixing html with Org mode
</h3> </h4>
<div class="outline-2" id="meta" style="color: green;"> <div class="outline-2" id="meta" style="color: green;">
<table> <table>
<tbody> <tbody>
@ -225,14 +226,14 @@ deploy:
</tbody> </tbody>
</table> </table>
</div> </div>
<h3 id="headline-7"> <h4 id="headline-7">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/41">#41</a>: Support Table Of Contents <a href="https://github.com/chaseadamsio/goorgeous/issues/41">#41</a>: Support Table Of Contents
</h3> </h4>
<h3 id="headline-8"> <h4 id="headline-8">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/46">#46</a>: Support for symbols like ndash and mdash <a href="https://github.com/chaseadamsio/goorgeous/issues/46">#46</a>: Support for symbols like ndash and mdash
</h3> </h4>
<ul> <ul>
<li> <li>
<p> <p>
@ -260,19 +261,19 @@ note that —— is replaced with 2 mdashes and …. becomes ellipsis+. and so o
</p> </p>
</li> </li>
</ul> </ul>
<h3 id="headline-9"> <h4 id="headline-9">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/47">#47:</a> Consecutive <code>code</code> wrapped text gets joined <a href="https://github.com/chaseadamsio/goorgeous/issues/47">#47:</a> Consecutive <code>code</code> wrapped text gets joined
</h3> </h4>
<p> <p>
either <code>this</code> or <code>that</code> foo. either <code>this</code> or <code>that</code> foo.
either <code>this</code> either <code>this</code>
or <code>that</code> foo. or <code>that</code> foo.
</p> </p>
<h3 id="headline-10"> <h4 id="headline-10">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/50">#50</a>: LineBreaks in lists are preserved <a href="https://github.com/chaseadamsio/goorgeous/issues/50">#50</a>: LineBreaks in lists are preserved
</h3> </h4>
<ul> <ul>
<li> <li>
<p> <p>
@ -304,24 +305,24 @@ foo
</p> </p>
</li> </li>
</ol> </ol>
<h3 id="headline-11"> <h4 id="headline-11">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/68">#68</a>: Quote block with inline markup <a href="https://github.com/chaseadamsio/goorgeous/issues/68">#68</a>: Quote block with inline markup
</h3> </h4>
<blockquote> <blockquote>
<p> <p>
<a href="https://www.example.com"><em>this</em> <strong>is</strong> <span style="text-decoration: underline;">markup</span>!</a> <a href="https://www.example.com"><em>this</em> <strong>is</strong> <span style="text-decoration: underline;">markup</span>!</a>
</p> </p>
</blockquote> </blockquote>
<h3 id="headline-12"> <h4 id="headline-12">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/72">#72</a>: Support for #+ATTR_HTML <a href="https://github.com/chaseadamsio/goorgeous/issues/72">#72</a>: Support for #+ATTR_HTML
</h3> </h4>
<img src="https://golang.org/doc/gopher/pkg.png" alt="Go is fine though." title="https://golang.org/doc/gopher/pkg.png" id="gopher-image" width="300" style="border:2px solid black;"/> <img src="https://golang.org/doc/gopher/pkg.png" alt="Go is fine though." title="https://golang.org/doc/gopher/pkg.png" id="gopher-image" width="300" style="border:2px solid black;"/>
<h3 id="headline-13"> <h4 id="headline-13">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/75">#75</a>: Not parsing nested lists correctly <a href="https://github.com/chaseadamsio/goorgeous/issues/75">#75</a>: Not parsing nested lists correctly
</h3> </h4>
<ul> <ul>
<li> <li>
<p> <p>
@ -336,14 +337,14 @@ sub bullet
</ul> </ul>
</li> </li>
</ul> </ul>
<h3 id="headline-14"> <h4 id="headline-14">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/77">#77</a>: Recognize <code class="verbatim">code</code>— as code plus dash <a href="https://github.com/chaseadamsio/goorgeous/issues/77">#77</a>: Recognize <code class="verbatim">code</code>— as code plus dash
</h3> </h4>
<h3 id="headline-15"> <h4 id="headline-15">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/78">#78</a>: Emphasis at beginning of line <a href="https://github.com/chaseadamsio/goorgeous/issues/78">#78</a>: Emphasis at beginning of line
</h3> </h4>
<p> <p>
<em>italics</em> <em>italics</em>
</p> </p>
@ -351,36 +352,36 @@ sub bullet
Text Text
<em>italics</em> <em>italics</em>
</p> </p>
<h3 id="headline-16"> <h4 id="headline-16">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/82">#82</a>: Crash on empty headline <a href="https://github.com/chaseadamsio/goorgeous/issues/82">#82</a>: Crash on empty headline
</h3>
<h4 id="headline-17">
</h4> </h4>
<h5 id="headline-17">
</h5>
<p> <p>
just a space as title… just a space as title…
</p> </p>
<h3 id="headline-18"> <h4 id="headline-18">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/84">#84</a>: Paragraphs that are not followed by an empty line are not parsed correctly <a href="https://github.com/chaseadamsio/goorgeous/issues/84">#84</a>: Paragraphs that are not followed by an empty line are not parsed correctly
</h3>
<h4 id="headline-19">
Foo
</h4> </h4>
<h5 id="headline-19">
Foo
</h5>
<p> <p>
Foo paragraph. Foo paragraph.
</p> </p>
<h4 id="headline-20"> <h5 id="headline-20">
Bar Bar
</h4> </h5>
<p> <p>
Bar paragraph Bar paragraph
</p> </p>
<h3 id="headline-21"> <h4 id="headline-21">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/86">#86</a>: Multiple hyphens not converted to dashes <a href="https://github.com/chaseadamsio/goorgeous/issues/86">#86</a>: Multiple hyphens not converted to dashes
</h3> </h4>
<p> <p>
just like #46 just like #46
</p> </p>
@ -425,17 +426,17 @@ src/example/export blocks should not be converted!
</pre> </pre>
</li> </li>
</ul> </ul>
<h3 id="headline-22"> <h4 id="headline-22">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<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> </h4>
<p> <p>
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> 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"> <h4 id="headline-23">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/92">#92</a>: src blocks only render in caps <a href="https://github.com/chaseadamsio/goorgeous/issues/92">#92</a>: src blocks only render in caps
</h3> </h4>
<p> <p>
The behaviour of Org mode <code class="verbatim">&lt;s TAB</code> changed and it now inserts lowercased src blocks (go-org already handled this one) The behaviour of Org mode <code class="verbatim">&lt;s TAB</code> changed and it now inserts lowercased src blocks (go-org already handled this one)
</p> </p>
@ -465,21 +466,21 @@ uname -a
</div> </div>
</li> </li>
</ul> </ul>
<h2 id="headline-24"> <h3 id="headline-24">
issues (wrongly) filed with hugo issues (wrongly) filed with hugo
</h2>
<h3 id="headline-25">
<a href="https://github.com/gohugoio/hugo/issues/3874">#3874</a> exporting images in org mode
</h3> </h3>
<h4 id="headline-25">
<a href="https://github.com/gohugoio/hugo/issues/3874">#3874</a> exporting images in org mode
</h4>
<p> <p>
Hello, I&#39;m writing hugo blogs using org-mode. Hello, I&#39;m writing hugo blogs using org-mode.
</p> </p>
<p> <p>
When inserting an image link like <img src="/home/amos/Pictures/Screenshots/img-2017-09-11-165647.png" alt="/home/amos/Pictures/Screenshots/img-2017-09-11-165647.png" title="/home/amos/Pictures/Screenshots/img-2017-09-11-165647.png" />, hugo doesn&#39;t export the image. When inserting an image link like <img src="/home/amos/Pictures/Screenshots/img-2017-09-11-165647.png" alt="/home/amos/Pictures/Screenshots/img-2017-09-11-165647.png" title="/home/amos/Pictures/Screenshots/img-2017-09-11-165647.png" />, hugo doesn&#39;t export the image.
</p> </p>
<h3 id="headline-26"> <h4 id="headline-26">
<a href="https://github.com/gohugoio/hugo/issues/4006">#4006</a> source code blocks in org not rendered correctly <a href="https://github.com/gohugoio/hugo/issues/4006">#4006</a> source code blocks in org not rendered correctly
</h3> </h4>
<div class="src src-emacs-lisp"> <div class="src src-emacs-lisp">
<div class="highlight"> <div class="highlight">
<pre> <pre>
@ -492,24 +493,24 @@ When inserting an image link like <img src="/home/amos/Pictures/Screenshots/img-
</pre> </pre>
</div> </div>
</div> </div>
<h2 id="headline-27"> <h3 id="headline-27">
misc fuzz / regression / edge case misc fuzz / regression / edge case
</h2> </h3>
<h3 id="headline-28"> <h4 id="headline-28">
index out of range in headline priority parsing index out of range in headline priority parsing
</h3>
<h4 id="headline-29">
[#B
</h4> </h4>
<h3 id="headline-30"> <h5 id="headline-29">
[#B
</h5>
<h4 id="headline-30">
index out of range in explicit line break parsing index out of range in explicit line break parsing
</h3> </h4>
<p> <p>
0\\ 0\\
</p> </p>
<h1 id="headline-31"> <h2 id="headline-31">
Footnotes Footnotes
</h1> </h2>
<div class="footnotes"> <div class="footnotes">
<hr class="footnotes-separatator"> <hr class="footnotes-separatator">
<div class="footnote-definitions"> <div class="footnote-definitions">

View file

@ -1,3 +1,4 @@
#+TITLE: Misc
** issues from goorgeous (free test cases, yay!) ** issues from goorgeous (free test cases, yay!)
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/19][#19]]: Support #+HTML *** DONE [[https://github.com/chaseadamsio/goorgeous/issues/19][#19]]: Support #+HTML
#+HTML: <p style="border: 1px dotted grey">neato!</p> #+HTML: <p style="border: 1px dotted grey">neato!</p>

View file

@ -1,3 +1,4 @@
#+TITLE: Misc
** issues from goorgeous (free test cases, yay!) ** issues from goorgeous (free test cases, yay!)
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/19][#19]]: Support #+HTML *** DONE [[https://github.com/chaseadamsio/goorgeous/issues/19][#19]]: Support #+HTML
#+HTML: <p style="border: 1px dotted grey">neato!</p> #+HTML: <p style="border: 1px dotted grey">neato!</p>

View file

@ -1,8 +1,8 @@
<h1 id="headline-1"> <h2 id="headline-1">
<span class="todo">DONE</span> <span class="todo">DONE</span>
<span class="priority">[A]</span> <span class="priority">[A]</span>
<code class="verbatim">#+OPTIONS:</code> toggles supported by <code class="verbatim">go-org</code>&#xa0;&#xa0;&#xa0;<span class="tags"><span>tag1</span>&#xa0;<span>tag2</span></span> <code class="verbatim">#+OPTIONS:</code> toggles supported by <code class="verbatim">go-org</code>&#xa0;&#xa0;&#xa0;<span class="tags"><span>tag1</span>&#xa0;<span>tag2</span></span>
</h1> </h2>
<p> <p>
<code class="verbatim">go-org</code> supports multiple export toggles as described in the <a href="https://orgmode.org/manual/Export-settings.html">export settings</a> section of the Org mode manual. <code class="verbatim">go-org</code> supports multiple export toggles as described in the <a href="https://orgmode.org/manual/Export-settings.html">export settings</a> section of the Org mode manual.
By default (most of?) those toggles are enabled. This file starts with <code class="verbatim">#+OPTIONS: toc:nil f:nil e:nil</code> and thus By default (most of?) those toggles are enabled. This file starts with <code class="verbatim">#+OPTIONS: toc:nil f:nil e:nil</code> and thus