]> source.dussan.org Git - gitea.git/commitdiff
Update go-org to 0.1.9 (#9782)
authorDamien Cassou <damien@cassou.me>
Thu, 16 Jan 2020 08:27:41 +0000 (09:27 +0100)
committerAntoine GIRARD <sapk@users.noreply.github.com>
Thu, 16 Jan 2020 08:27:41 +0000 (09:27 +0100)
* Update go-org to 0.1.9

What I did to generate this commit:

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

* make vendor

go.mod
go.sum
vendor/github.com/niklasfasching/go-org/org/document.go
vendor/github.com/niklasfasching/go-org/org/html_writer.go
vendor/github.com/niklasfasching/go-org/org/list.go
vendor/github.com/niklasfasching/go-org/org/org_writer.go
vendor/github.com/niklasfasching/go-org/org/paragraph.go
vendor/modules.txt

diff --git a/go.mod b/go.mod
index 8af6890691a8dd65d038f96f6a704082f1cb4908..171a47036ba86dd1b58ab0517c5bed10f8b6cd85 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -70,7 +70,7 @@ require (
        github.com/microcosm-cc/bluemonday v0.0.0-20161012083705-f77f16ffc87a
        github.com/msteinert/pam v0.0.0-20151204160544-02ccfbfaf0cc
        github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5
-       github.com/niklasfasching/go-org v0.1.8
+       github.com/niklasfasching/go-org v0.1.9
        github.com/oliamb/cutter v0.2.2
        github.com/pkg/errors v0.8.1
        github.com/pquerna/otp v0.0.0-20160912161815-54653902c20e
diff --git a/go.sum b/go.sum
index b945bb7edbc8a84ddc8ba1cb9a062034a8b7c843..6363ce75b70c6fdb22dbfbbc1a58a07a1de72142 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -402,8 +402,8 @@ github.com/msteinert/pam v0.0.0-20151204160544-02ccfbfaf0cc/go.mod h1:np1wUFZ6ty
 github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
 github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 h1:BvoENQQU+fZ9uukda/RzCAL/191HHwJA5b13R6diVlY=
 github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
-github.com/niklasfasching/go-org v0.1.8 h1:Kjvs6lP+LIILHhc9zIJ4Gu90a/pVY483if2Qmu8v4Fg=
-github.com/niklasfasching/go-org v0.1.8/go.mod h1:AsLD6X7djzRIz4/RFZu8vwRL0VGjUvGZCCH1Nz0VdrU=
+github.com/niklasfasching/go-org v0.1.9 h1:Toz8WMIt+qJb52uYEk1YD/muLuOOmRt1CfkV+bKVMkI=
+github.com/niklasfasching/go-org v0.1.9/go.mod h1:AsLD6X7djzRIz4/RFZu8vwRL0VGjUvGZCCH1Nz0VdrU=
 github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
 github.com/oliamb/cutter v0.2.2 h1:Lfwkya0HHNU1YLnGv2hTkzHfasrSMkgv4Dn+5rmlk3k=
 github.com/oliamb/cutter v0.2.2/go.mod h1:4BenG2/4GuRBDbVm/OPahDVqbrOemzpPiG5mi1iryBU=
index a9697c465d68033f8fb91ae61d8c3cf331598766..3c60e5b54f9fb9586e8211a13340cf9e73eaf511 100644 (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).
index 916618c450ad720d0dbef1733f51201d74dc0ee4..d630db5ceb693e461978502f3cc706f15d33f089 100644 (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...)
 }
 
index 462e9fa75b31e00d9e7e8550a4ad6611dc8212c8..54f5b2d8de9a90f2dcf72223f83cdef56c71ca10 100644 (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}
        }
index 8855df901890719924231a0b86dbc54490c954f1..d5a33ff27f58821c15d68e2dc95bac1600f9c2c2 100644 (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 + " ::")
index 24f0554600e14185660da7e8b6408fe2fe4cb1b7..2c58eac5134ba6d5fb5c56c4d43c6f68c47e3ecc 100644 (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"))}
index 5f2d44e691fe6aff51d57dbde2a69d86a32f961a..2f36278d756110e19dd61d2828abd77ef7cfa0dc 100644 (file)
@@ -328,7 +328,7 @@ github.com/mschoch/smat
 github.com/msteinert/pam
 # github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5
 github.com/nfnt/resize
-# github.com/niklasfasching/go-org v0.1.8
+# github.com/niklasfasching/go-org v0.1.9
 github.com/niklasfasching/go-org/org
 # github.com/oliamb/cutter v0.2.2
 github.com/oliamb/cutter