Update go-org to 0.1.9 (#9782)

* Update go-org to 0.1.9

What I did to generate this commit:

$ go get github.com/niklasfasching/go-org

* make vendor
This commit is contained in:
Damien Cassou 2020-01-16 09:27:41 +01:00 committed by Antoine GIRARD
parent 3ae5f8ef11
commit c6a32ddb47
8 changed files with 20 additions and 10 deletions

View file

@ -35,6 +35,7 @@ type Document struct {
*Configuration
Path string // Path of the file containing the parse input - used to resolve relative paths during parsing (e.g. INCLUDE).
tokens []token
baseLvl int
Nodes []Node
NamedNodes map[string]Node
Outline Outline // Outline is a Table Of Contents for the document and contains all sections (headline + content).

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

@ -81,12 +81,15 @@ func (d *Document) parseList(i int, parentStop stopFn) (int, Node) {
func (d *Document) parseListItem(l List, i int, parentStop stopFn) (int, Node) {
start, nodes, bullet := i, []Node{}, d.tokens[i].matches[2]
minIndent, dterm, content, status := d.tokens[i].lvl+len(bullet), "", d.tokens[i].content, ""
originalBaseLvl := d.baseLvl
d.baseLvl = minIndent + 1
if m := listItemStatusRegexp.FindStringSubmatch(content); m != nil {
status, content = m[1], content[len("[ ] "):]
}
if l.Kind == "descriptive" {
if m := descriptiveListItemRegexp.FindStringIndex(content); m != nil {
dterm, content = content[:m[0]], content[m[1]:]
d.baseLvl = strings.Index(d.tokens[i].matches[0], " ::") + 4
}
}
@ -103,6 +106,7 @@ func (d *Document) parseListItem(l List, i int, parentStop stopFn) (int, Node) {
i += consumed
nodes = append(nodes, node)
}
d.baseLvl = originalBaseLvl
if l.Kind == "descriptive" {
return i - start, DescriptiveListItem{bullet, status, d.parseInline(dterm), nodes}
}

View file

@ -196,11 +196,12 @@ func (w *OrgWriter) WriteListItem(li ListItem) {
}
func (w *OrgWriter) WriteDescriptiveListItem(di DescriptiveListItem) {
indent := w.indent + strings.Repeat(" ", len(di.Bullet)+1)
w.WriteString(w.indent + di.Bullet)
if di.Status != "" {
w.WriteString(fmt.Sprintf(" [%s]", di.Status))
indent = indent + strings.Repeat(" ", len(di.Status)+3)
}
indent := w.indent + strings.Repeat(" ", len(di.Bullet)+1)
if len(di.Term) != 0 {
term := w.WriteNodesAsString(di.Term...)
w.WriteString(" " + term + " ::")

View file

@ -1,6 +1,7 @@
package org
import (
"math"
"regexp"
"strings"
)
@ -27,12 +28,12 @@ func lexHorizontalRule(line string) (token, bool) {
func (d *Document) parseParagraph(i int, parentStop stopFn) (int, Node) {
lines, start := []string{d.tokens[i].content}, i
i++
stop := func(d *Document, i int) bool {
return parentStop(d, i) || d.tokens[i].kind != "text" || d.tokens[i].content == ""
}
for ; !stop(d, i); i++ {
lines = append(lines, d.tokens[i].content)
for i += 1; !stop(d, i); i++ {
lvl := math.Max(float64(d.tokens[i].lvl-d.baseLvl), 0)
lines = append(lines, strings.Repeat(" ", int(lvl))+d.tokens[i].content)
}
consumed := i - start
return consumed, Paragraph{d.parseInline(strings.Join(lines, "\n"))}