Merge pull request #87 from xjzi/master

Don't wrap simple titles in <p>
This commit is contained in:
Niklas Fasching 2022-08-22 18:14:20 +02:00 committed by GitHub
commit 351c47cdc9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View file

@ -100,8 +100,18 @@ 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 {
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...) 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))
} }
if w.document.GetOption("toc") != "nil" { if w.document.GetOption("toc") != "nil" {

View file

@ -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>