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) {
w.document = d
w.log = d.Log
if title := d.Get("TITLE"); title != "" {
w.WriteString(fmt.Sprintf(`<h1 class="title">%s</h1>`+"\n", title))
}
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 != "" {
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(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...)
}

View file

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

View file

@ -4,9 +4,9 @@
</li>
</ul>
</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>
</h1>
</h2>
<div class="footnotes">
<hr class="footnotes-separatator">
<div class="footnote-definitions">

View file

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

125
org/testdata/misc.html vendored
View file

@ -1,3 +1,4 @@
<h1 class="title">Misc</h1>
<nav>
<ul>
<li><a href="#headline-1">issues from goorgeous (free test cases, yay!)</a>
@ -76,18 +77,18 @@
</li>
</ul>
</nav>
<h2 id="headline-1">
<h3 id="headline-1">
issues from goorgeous (free test cases, yay!)
</h2>
<h3 id="headline-2">
</h3>
<h4 id="headline-2">
<span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/19">#19</a>: Support #+HTML
</h3>
</h4>
<p style="border: 1px dotted grey">neato!</p>
<h3 id="headline-3">
<h4 id="headline-3">
<span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/29">#29:</a> Support verse block
</h3>
</h4>
<div class="verse-block">
<p>
This
@ -101,17 +102,17 @@ or even a <strong>totally</strong> <em>custom</em> kind of block
crazy ain&#39;t it?
</p>
</div>
<h3 id="headline-4">
<h4 id="headline-4">
<span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/30">#30</a>: Support #+SETUPFILE
</h3>
</h4>
<p>
see <code class="verbatim">./headlines.org</code>
</p>
<h3 id="headline-5">
<h4 id="headline-5">
<span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/31">#31</a>: Support #+INCLUDE
</h3>
</h4>
<p>
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
@ -207,10 +208,10 @@ deploy:
</pre>
</li>
</ul>
<h3 id="headline-6">
<h4 id="headline-6">
<span class="todo">DONE</span>
<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;">
<table>
<tbody>
@ -225,14 +226,14 @@ deploy:
</tbody>
</table>
</div>
<h3 id="headline-7">
<h4 id="headline-7">
<span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/41">#41</a>: Support Table Of Contents
</h3>
<h3 id="headline-8">
</h4>
<h4 id="headline-8">
<span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/46">#46</a>: Support for symbols like ndash and mdash
</h3>
</h4>
<ul>
<li>
<p>
@ -260,19 +261,19 @@ note that —— is replaced with 2 mdashes and …. becomes ellipsis+. and so o
</p>
</li>
</ul>
<h3 id="headline-9">
<h4 id="headline-9">
<span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/47">#47:</a> Consecutive <code>code</code> wrapped text gets joined
</h3>
</h4>
<p>
either <code>this</code> or <code>that</code> foo.
either <code>this</code>
or <code>that</code> foo.
</p>
<h3 id="headline-10">
<h4 id="headline-10">
<span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/50">#50</a>: LineBreaks in lists are preserved
</h3>
</h4>
<ul>
<li>
<p>
@ -304,24 +305,24 @@ foo
</p>
</li>
</ol>
<h3 id="headline-11">
<h4 id="headline-11">
<span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/68">#68</a>: Quote block with inline markup
</h3>
</h4>
<blockquote>
<p>
<a href="https://www.example.com"><em>this</em> <strong>is</strong> <span style="text-decoration: underline;">markup</span>!</a>
</p>
</blockquote>
<h3 id="headline-12">
<h4 id="headline-12">
<span class="todo">DONE</span>
<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;"/>
<h3 id="headline-13">
<h4 id="headline-13">
<span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/75">#75</a>: Not parsing nested lists correctly
</h3>
</h4>
<ul>
<li>
<p>
@ -336,14 +337,14 @@ sub bullet
</ul>
</li>
</ul>
<h3 id="headline-14">
<h4 id="headline-14">
<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
</h3>
<h3 id="headline-15">
</h4>
<h4 id="headline-15">
<span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/78">#78</a>: Emphasis at beginning of line
</h3>
</h4>
<p>
<em>italics</em>
</p>
@ -351,36 +352,36 @@ sub bullet
Text
<em>italics</em>
</p>
<h3 id="headline-16">
<h4 id="headline-16">
<span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/82">#82</a>: Crash on empty headline
</h3>
<h4 id="headline-17">
</h4>
<h5 id="headline-17">
</h5>
<p>
just a space as title…
</p>
<h3 id="headline-18">
<h4 id="headline-18">
<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
</h3>
<h4 id="headline-19">
Foo
</h4>
<h5 id="headline-19">
Foo
</h5>
<p>
Foo paragraph.
</p>
<h4 id="headline-20">
<h5 id="headline-20">
Bar
</h4>
</h5>
<p>
Bar paragraph
</p>
<h3 id="headline-21">
<h4 id="headline-21">
<span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/86">#86</a>: Multiple hyphens not converted to dashes
</h3>
</h4>
<p>
just like #46
</p>
@ -425,17 +426,17 @@ src/example/export blocks should not be converted!
</pre>
</li>
</ul>
<h3 id="headline-22">
<h4 id="headline-22">
<span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/87">#87</a>: Markup in footnotes is rendered literally
</h3>
</h4>
<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>
</p>
<h3 id="headline-23">
<h4 id="headline-23">
<span class="todo">DONE</span>
<a href="https://github.com/chaseadamsio/goorgeous/issues/92">#92</a>: src blocks only render in caps
</h3>
</h4>
<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)
</p>
@ -465,21 +466,21 @@ uname -a
</div>
</li>
</ul>
<h2 id="headline-24">
<h3 id="headline-24">
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>
<h4 id="headline-25">
<a href="https://github.com/gohugoio/hugo/issues/3874">#3874</a> exporting images in org mode
</h4>
<p>
Hello, I&#39;m writing hugo blogs using org-mode.
</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.
</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
</h3>
</h4>
<div class="src src-emacs-lisp">
<div class="highlight">
<pre>
@ -492,24 +493,24 @@ When inserting an image link like <img src="/home/amos/Pictures/Screenshots/img-
</pre>
</div>
</div>
<h2 id="headline-27">
<h3 id="headline-27">
misc fuzz / regression / edge case
</h2>
<h3 id="headline-28">
</h3>
<h4 id="headline-28">
index out of range in headline priority parsing
</h3>
<h4 id="headline-29">
[#B
</h4>
<h3 id="headline-30">
<h5 id="headline-29">
[#B
</h5>
<h4 id="headline-30">
index out of range in explicit line break parsing
</h3>
</h4>
<p>
0\\
</p>
<h1 id="headline-31">
<h2 id="headline-31">
Footnotes
</h1>
</h2>
<div class="footnotes">
<hr class="footnotes-separatator">
<div class="footnote-definitions">

View file

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

View file

@ -1,3 +1,4 @@
#+TITLE: Misc
** issues from goorgeous (free test cases, yay!)
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/19][#19]]: Support #+HTML
#+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="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>
</h1>
</h2>
<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.
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