diff --git a/go.mod b/go.mod index ab5c376c6..0b1aac7ca 100644 --- a/go.mod +++ b/go.mod @@ -27,6 +27,7 @@ require ( github.com/cznic/strutil v0.0.0-20181122101858-275e90344537 // indirect github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc github.com/dgrijalva/jwt-go v3.2.0+incompatible + github.com/dlclark/regexp2 v1.2.1 // indirect github.com/dustin/go-humanize v1.0.0 github.com/editorconfig/editorconfig-core-go/v2 v2.1.1 github.com/emirpasic/gods v1.12.0 @@ -73,7 +74,7 @@ require ( github.com/mitchellh/go-homedir v1.1.0 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.9 + github.com/niklasfasching/go-org v1.3.2 github.com/oliamb/cutter v0.2.2 github.com/olivere/elastic/v7 v7.0.9 github.com/pkg/errors v0.9.1 @@ -99,7 +100,7 @@ require ( github.com/yuin/goldmark-highlighting v0.0.0-20200307114337-60d527fdb691 github.com/yuin/goldmark-meta v0.0.0-20191126180153-f0638e958b60 golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a - golang.org/x/net v0.0.0-20200707034311-ab3426394381 + golang.org/x/net v0.0.0-20200904194848-62affa334b73 golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae golang.org/x/text v0.3.3 diff --git a/go.sum b/go.sum index 08a1d20ff..bfa81019c 100644 --- a/go.sum +++ b/go.sum @@ -194,6 +194,8 @@ github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8 github.com/dlclark/regexp2 v1.1.6/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= github.com/dlclark/regexp2 v1.2.0 h1:8sAhBGEM0dRWogWqWyQeIJnxjWO6oIjl8FKqREDsGfk= github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= +github.com/dlclark/regexp2 v1.2.1 h1:Ff/S0snjr1oZHUNOkvA/gP6KUaMg5vDDl3Qnhjnwgm8= +github.com/dlclark/regexp2 v1.2.1/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q= @@ -705,8 +707,8 @@ github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 h1:BvoENQQU+fZ9uukda/R github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -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/niklasfasching/go-org v1.3.2 h1:ZKTSd+GdJYkoZl1pBXLR/k7DRiRXnmB96TRiHmHdzwI= +github.com/niklasfasching/go-org v1.3.2/go.mod h1:AsLD6X7djzRIz4/RFZu8vwRL0VGjUvGZCCH1Nz0VdrU= github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E= github.com/nwaples/rardecode v1.0.0 h1:r7vGuS5akxOnR4JQSkko62RJ1ReCMXxQRPtxsiFMBOs= github.com/nwaples/rardecode v1.0.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0= @@ -1010,6 +1012,8 @@ golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200904194848-62affa334b73 h1:MXfv8rhZWmFeqX3GNZRsd6vOLoaCHjYEX3qkRo3YBUA= +golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/oauth2 v0.0.0-20180620175406-ef147856a6dd/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= diff --git a/modules/markup/orgmode/orgmode_test.go b/modules/markup/orgmode/orgmode_test.go index 40323912b..020a3f592 100644 --- a/modules/markup/orgmode/orgmode_test.go +++ b/modules/markup/orgmode/orgmode_test.go @@ -27,12 +27,12 @@ func TestRender_StandardLinks(t *testing.T) { assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) } - googleRendered := "
" + googleRendered := "" test("[[https://google.com/]]", googleRendered) lnk := util.URLJoin(AppSubURL, "WikiPage") test("[[WikiPage][WikiPage]]", - "\nWikiPage\n
") + "") } func TestRender_Images(t *testing.T) { @@ -48,5 +48,5 @@ func TestRender_Images(t *testing.T) { result := util.URLJoin(AppSubURL, url) test("[[file:"+url+"]]", - "\n\n
") + "") } diff --git a/vendor/github.com/dlclark/regexp2/.travis.yml b/vendor/github.com/dlclark/regexp2/.travis.yml index a24aededa..2aa5ea1ee 100644 --- a/vendor/github.com/dlclark/regexp2/.travis.yml +++ b/vendor/github.com/dlclark/regexp2/.travis.yml @@ -1,5 +1,5 @@ language: go go: - - 1.5 + - 1.9 - tip \ No newline at end of file diff --git a/vendor/github.com/dlclark/regexp2/regexp.go b/vendor/github.com/dlclark/regexp2/regexp.go index 709e03425..7c7b01d87 100644 --- a/vendor/github.com/dlclark/regexp2/regexp.go +++ b/vendor/github.com/dlclark/regexp2/regexp.go @@ -235,17 +235,14 @@ func (re *Regexp) getRunesAndStart(s string, startAt int) ([]rune, int) { ret[i] = r i++ } + if startAt == len(s) { + runeIdx = i + } return ret[:i], runeIdx } func getRunes(s string) []rune { - ret := make([]rune, len(s)) - i := 0 - for _, r := range s { - ret[i] = r - i++ - } - return ret[:i] + return []rune(s) } // MatchRunes return true if the runes matches the regex diff --git a/vendor/github.com/dlclark/regexp2/syntax/parser.go b/vendor/github.com/dlclark/regexp2/syntax/parser.go index f13f779cf..be88e2eed 100644 --- a/vendor/github.com/dlclark/regexp2/syntax/parser.go +++ b/vendor/github.com/dlclark/regexp2/syntax/parser.go @@ -1250,10 +1250,10 @@ func (p *parser) scanBasicBackslash(scanOnly bool) (*regexNode, error) { return nil, nil } - if p.useOptionE() || p.isCaptureSlot(capnum) { + if p.isCaptureSlot(capnum) { return newRegexNodeM(ntRef, p.options, capnum), nil } - if capnum <= 9 { + if capnum <= 9 && !p.useOptionE() { return nil, p.getErr(ErrUndefinedBackRef, capnum) } @@ -1808,11 +1808,11 @@ func (p *parser) scanOctal() rune { i := 0 d := int(p.rightChar(0) - '0') for c > 0 && d <= 7 { - i *= 8 - i += d - if p.useOptionE() && i >= 0x20 { + if i >= 0x20 && p.useOptionE() { break } + i *= 8 + i += d c-- p.moveRight(1) diff --git a/vendor/github.com/niklasfasching/go-org/org/block.go b/vendor/github.com/niklasfasching/go-org/org/block.go index 78ad9a791..11b135fdf 100644 --- a/vendor/github.com/niklasfasching/go-org/org/block.go +++ b/vendor/github.com/niklasfasching/go-org/org/block.go @@ -10,6 +10,11 @@ type Block struct { Name string Parameters []string Children []Node + Result Node +} + +type Result struct { + Node Node } type Example struct { @@ -19,6 +24,8 @@ type Example struct { var exampleLineRegexp = regexp.MustCompile(`^(\s*):(\s(.*)|\s*$)`) var beginBlockRegexp = regexp.MustCompile(`(?i)^(\s*)#\+BEGIN_(\w+)(.*)`) var endBlockRegexp = regexp.MustCompile(`(?i)^(\s*)#\+END_(\w+)`) +var resultRegexp = regexp.MustCompile(`(?i)^(\s*)#\+RESULTS:`) +var exampleBlockEscapeRegexp = regexp.MustCompile(`(^|\n)([ \t]*),([ \t]*)(\*|,\*|#\+|,#\+)`) func lexBlock(line string) (token, bool) { if m := beginBlockRegexp.FindStringSubmatch(line); m != nil { @@ -29,6 +36,13 @@ func lexBlock(line string) (token, bool) { return nilToken, false } +func lexResult(line string) (token, bool) { + if m := resultRegexp.FindStringSubmatch(line); m != nil { + return token{"result", len(m[1]), "", m}, true + } + return nilToken, false +} + func lexExample(line string) (token, bool) { if m := exampleLineRegexp.FindStringSubmatch(line); m != nil { return token{"example", len(m[1]), m[3], m}, true @@ -45,22 +59,41 @@ func (d *Document) parseBlock(i int, parentStop stopFn) (int, Node) { stop := func(d *Document, i int) bool { return i >= len(d.tokens) || (d.tokens[i].kind == "endBlock" && d.tokens[i].content == name) } - block, i := Block{name, parameters, nil}, i+1 + block, i := Block{name, parameters, nil, nil}, i+1 if isRawTextBlock(name) { rawText := "" for ; !stop(d, i); i++ { rawText += trim(d.tokens[i].matches[0]) + "\n" } + if name == "EXAMPLE" || (name == "SRC" && len(parameters) >= 1 && parameters[0] == "org") { + rawText = exampleBlockEscapeRegexp.ReplaceAllString(rawText, "$1$2$3$4") + } block.Children = d.parseRawInline(rawText) } else { consumed, nodes := d.parseMany(i, stop) block.Children = nodes i += consumed } - if i < len(d.tokens) && d.tokens[i].kind == "endBlock" && d.tokens[i].content == name { - return i + 1 - start, block + if i >= len(d.tokens) || d.tokens[i].kind != "endBlock" || d.tokens[i].content != name { + return 0, nil } - return 0, nil + if name == "SRC" { + consumed, result := d.parseSrcBlockResult(i+1, parentStop) + block.Result = result + i += consumed + } + return i + 1 - start, block +} + +func (d *Document) parseSrcBlockResult(i int, parentStop stopFn) (int, Node) { + start := i + for ; !parentStop(d, i) && d.tokens[i].kind == "text" && d.tokens[i].content == ""; i++ { + } + if parentStop(d, i) || d.tokens[i].kind != "result" { + return 0, nil + } + consumed, result := d.parseResult(i, parentStop) + return (i - start) + consumed, result } func (d *Document) parseExample(i int, parentStop stopFn) (int, Node) { @@ -71,6 +104,14 @@ func (d *Document) parseExample(i int, parentStop stopFn) (int, Node) { return i - start, example } +func (d *Document) parseResult(i int, parentStop stopFn) (int, Node) { + if i+1 >= len(d.tokens) { + return 0, nil + } + consumed, node := d.parseOne(i+1, parentStop) + return consumed + 1, Result{node} +} + func trimIndentUpTo(max int) func(string) string { return func(line string) string { i := 0 @@ -80,5 +121,17 @@ func trimIndentUpTo(max int) func(string) string { } } +func (b Block) ParameterMap() map[string]string { + if len(b.Parameters) == 0 { + return nil + } + m := map[string]string{":lang": b.Parameters[0]} + for i := 1; i+1 < len(b.Parameters); i += 2 { + m[b.Parameters[i]] = b.Parameters[i+1] + } + return m +} + func (n Example) String() string { return orgWriter.WriteNodesAsString(n) } func (n Block) String() string { return orgWriter.WriteNodesAsString(n) } +func (n Result) String() string { return orgWriter.WriteNodesAsString(n) } diff --git a/vendor/github.com/niklasfasching/go-org/org/document.go b/vendor/github.com/niklasfasching/go-org/org/document.go index 3c60e5b54..0f016c115 100644 --- a/vendor/github.com/niklasfasching/go-org/org/document.go +++ b/vendor/github.com/niklasfasching/go-org/org/document.go @@ -36,6 +36,8 @@ type Document struct { Path string // Path of the file containing the parse input - used to resolve relative paths during parsing (e.g. INCLUDE). tokens []token baseLvl int + Macros map[string]string + Links map[string]string Nodes []Node NamedNodes map[string]Node Outline Outline // Outline is a Table Of Contents for the document and contains all sections (headline + content). @@ -63,6 +65,7 @@ var lexFns = []lexFn{ lexHeadline, lexDrawer, lexBlock, + lexResult, lexList, lexTable, lexHorizontalRule, @@ -83,7 +86,7 @@ func New() *Configuration { DefaultSettings: map[string]string{ "TODO": "TODO | DONE", "EXCLUDE_TAGS": "noexport", - "OPTIONS": "toc:t <:t e:t f:t pri:t todo:t tags:t", + "OPTIONS": "toc:t <:t e:t f:t pri:t todo:t tags:t title:t", }, Log: log.New(os.Stderr, "go-org: ", 0), ReadFile: ioutil.ReadFile, @@ -120,6 +123,8 @@ func (c *Configuration) Parse(input io.Reader, path string) (d *Document) { Outline: Outline{outlineSection, outlineSection, 0}, BufferSettings: map[string]string{}, NamedNodes: map[string]Node{}, + Links: map[string]string{}, + Macros: map[string]string{}, Path: path, } defer func() { @@ -169,12 +174,13 @@ func (d *Document) Get(key string) string { // - < (export timestamps) // - e (export org entities) // - f (export footnotes) -// - toc (export table of content) +// - title (export title) +// - toc (export table of content. an int limits the included org headline lvl) // - todo (export headline todo status) // - pri (export headline priority) // - tags (export headline tags) // see https://orgmode.org/manual/Export-settings.html for more information -func (d *Document) GetOption(key string) bool { +func (d *Document) GetOption(key string) string { get := func(settings map[string]string) string { for _, field := range strings.Fields(settings["OPTIONS"]) { if strings.HasPrefix(field, key+":") { @@ -187,15 +193,11 @@ func (d *Document) GetOption(key string) bool { if value == "" { value = get(d.DefaultSettings) } - switch value { - case "t": - return true - case "nil": - return false - default: - d.Log.Printf("Bad value for export option %s (%s)", key, value) - return false + if value == "" { + value = "nil" + d.Log.Printf("Missing value for export option %s", key) } + return value } func (d *Document) parseOne(i int, stop stopFn) (consumed int, node Node) { @@ -206,6 +208,8 @@ func (d *Document) parseOne(i int, stop stopFn) (consumed int, node Node) { consumed, node = d.parseTable(i, stop) case "beginBlock": consumed, node = d.parseBlock(i, stop) + case "result": + consumed, node = d.parseResult(i, stop) case "beginDrawer": consumed, node = d.parseDrawer(i, stop) case "text": diff --git a/vendor/github.com/niklasfasching/go-org/org/headline.go b/vendor/github.com/niklasfasching/go-org/org/headline.go index 749d1ff00..7e0b8eb2a 100644 --- a/vendor/github.com/niklasfasching/go-org/org/headline.go +++ b/vendor/github.com/niklasfasching/go-org/org/headline.go @@ -35,14 +35,14 @@ var tagRegexp = regexp.MustCompile(`(.*?)\s+(:[A-Za-z0-9_@#%:]+:\s*$)`) func lexHeadline(line string) (token, bool) { if m := headlineRegexp.FindStringSubmatch(line); m != nil { - return token{"headline", len(m[1]), m[2], m}, true + return token{"headline", 0, m[2], m}, true } return nilToken, false } func (d *Document) parseHeadline(i int, parentStop stopFn) (int, Node) { t, headline := d.tokens[i], Headline{} - headline.Lvl = t.lvl + headline.Lvl = len(t.matches[1]) headline.Index = d.addHeadline(&headline) @@ -69,7 +69,7 @@ func (d *Document) parseHeadline(i int, parentStop stopFn) (int, Node) { headline.Title = d.parseInline(text) stop := func(d *Document, i int) bool { - return parentStop(d, i) || d.tokens[i].kind == "headline" && d.tokens[i].lvl <= headline.Lvl + return parentStop(d, i) || d.tokens[i].kind == "headline" && len(d.tokens[i].matches[1]) <= headline.Lvl } consumed, nodes := d.parseMany(i+1, stop) if len(nodes) > 0 { diff --git a/vendor/github.com/niklasfasching/go-org/org/html_writer.go b/vendor/github.com/niklasfasching/go-org/org/html_writer.go index d630db5ce..d66e6effb 100644 --- a/vendor/github.com/niklasfasching/go-org/org/html_writer.go +++ b/vendor/github.com/niklasfasching/go-org/org/html_writer.go @@ -5,6 +5,7 @@ import ( "html" "log" "regexp" + "strconv" "strings" "unicode" @@ -15,7 +16,7 @@ import ( // HTMLWriter exports an org document into a html document. type HTMLWriter struct { ExtendingWriter Writer - HighlightCodeBlock func(source, lang string) string + HighlightCodeBlock func(source, lang string, inline bool) string strings.Builder document *Document @@ -60,7 +61,10 @@ func NewHTMLWriter() *HTMLWriter { document: &Document{Configuration: defaultConfig}, log: defaultConfig.Log, htmlEscape: true, - HighlightCodeBlock: func(source, lang string) string { + HighlightCodeBlock: func(source, lang string, inline bool) string { + if inline { + return fmt.Sprintf("\n%s\n
\n\n%s\n
\n` + "\n" + content + "\n\n") - case name == "EXPORT" && len(b.Parameters) >= 1 && strings.ToLower(b.Parameters[0]) == "html": - w.WriteString(content + "\n") - case name == "QUOTE": + case "EXAMPLE": + w.WriteString(`
` + "\n" + html.EscapeString(content) + "\n\n") + case "EXPORT": + if len(b.Parameters) >= 1 && strings.ToLower(b.Parameters[0]) == "html" { + w.WriteString(content + "\n") + } + case "QUOTE": w.WriteString("
\n" + content + "\n") - case name == "CENTER": + case "CENTER": w.WriteString(`
") - if _, ok := p.Children[0].(LineBreak); !ok { - w.WriteString("\n") - } WriteNodes(w, p.Children...) - w.WriteString("\n
\n") + w.WriteString("\n") } func (w *HTMLWriter) WriteExample(e Example) { @@ -414,23 +473,31 @@ func (w *HTMLWriter) WriteNodeWithName(n NodeWithName) { func (w *HTMLWriter) WriteTable(t Table) { w.WriteString("