Don't wrap simple titles in <p>
Before this commit, if an org document was titled "Title here", the first line of HTML output would be as follows: <h1 class="title"><p>Title here\n</p></h1> This commit changes the HTML writer to instead output the following: <h1 class="title">Title Here</h1> I conversatively modified the code, so there might be more cases where elements should be omitted from the title.
This commit is contained in:
parent
9a9c046a14
commit
81cb0c3735
2 changed files with 12 additions and 3 deletions
|
@ -100,7 +100,17 @@ func (w *HTMLWriter) Before(d *Document) {
|
||||||
if title := d.Get("TITLE"); title != "" && w.document.GetOption("title") != "nil" {
|
if title := d.Get("TITLE"); title != "" && w.document.GetOption("title") != "nil" {
|
||||||
titleDocument := d.Parse(strings.NewReader(title), d.Path)
|
titleDocument := d.Parse(strings.NewReader(title), d.Path)
|
||||||
if titleDocument.Error == nil {
|
if titleDocument.Error == nil {
|
||||||
title = w.WriteNodesAsString(titleDocument.Nodes...)
|
simpleTitle := false
|
||||||
|
if len(titleDocument.Nodes) == 1 {
|
||||||
|
switch p := titleDocument.Nodes[0].(type) {
|
||||||
|
case Paragraph:
|
||||||
|
simpleTitle = true
|
||||||
|
title = w.WriteNodesAsString(p.Children...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !simpleTitle {
|
||||||
|
title = w.WriteNodesAsString(titleDocument.Nodes...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
w.WriteString(fmt.Sprintf(`<h1 class="title">%s</h1>`+"\n", title))
|
w.WriteString(fmt.Sprintf(`<h1 class="title">%s</h1>`+"\n", title))
|
||||||
}
|
}
|
||||||
|
|
3
org/testdata/misc.html
vendored
3
org/testdata/misc.html
vendored
|
@ -1,5 +1,4 @@
|
||||||
<h1 class="title"><p>Misc title <b>with an inline html export</b></p>
|
<h1 class="title">Misc title <b>with an inline html export</b></h1>
|
||||||
</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>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue