diff --git a/go.mod b/go.mod index 02f0c46f22..87432f0689 100644 --- a/go.mod +++ b/go.mod @@ -72,7 +72,7 @@ require ( github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae // indirect 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.7 + github.com/niklasfasching/go-org v0.1.8 github.com/oliamb/cutter v0.2.2 github.com/philhofer/fwd v1.0.0 // indirect github.com/pkg/errors v0.8.1 @@ -101,7 +101,7 @@ require ( github.com/willf/bitset v0.0.0-20180426185212-8ce1146b8621 // indirect github.com/yohcop/openid-go v0.0.0-20160914080427-2c050d2dae53 golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad - golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271 + golang.org/x/net v0.0.0-20191101175033-0deb6923b6d9 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 golang.org/x/sys v0.0.0-20190910064555-bbd175535a8b golang.org/x/text v0.3.2 diff --git a/go.sum b/go.sum index 7445469d7e..ddc0b2e4eb 100644 --- a/go.sum +++ b/go.sum @@ -427,6 +427,8 @@ github.com/niklasfasching/go-org v0.1.6 h1:F521WcqRNl8OJumlgAnekZgERaTA2HpfOYYfV github.com/niklasfasching/go-org v0.1.6/go.mod h1:AsLD6X7djzRIz4/RFZu8vwRL0VGjUvGZCCH1Nz0VdrU= github.com/niklasfasching/go-org v0.1.7 h1:t3V+3XnS/7BhKv/7SlMUa8FvAiq577/a1T3D7mLIRXE= github.com/niklasfasching/go-org v0.1.7/go.mod h1:AsLD6X7djzRIz4/RFZu8vwRL0VGjUvGZCCH1Nz0VdrU= +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/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= @@ -658,6 +660,8 @@ golang.org/x/net v0.0.0-20190909003024-a7b16738d86b h1:XfVGCX+0T4WOStkaOsJRllbsi golang.org/x/net v0.0.0-20190909003024-a7b16738d86b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271 h1:N66aaryRB3Ax92gH0v3hp1QYZ3zWWCCUR/j8Ifh45Ss= golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191101175033-0deb6923b6d9 h1:DPz9iiH3YoKiKhX/ijjoZvT0VFwK2c6CWYWQ7Zyr8TU= +golang.org/x/net v0.0.0-20191101175033-0deb6923b6d9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 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-20190226205417-e64efc72b421 h1:Wo7BWFiOk0QRFMLYMqJGFMd9CgUAcGx7V+qEg/h5IBI= diff --git a/modules/markup/orgmode/orgmode.go b/modules/markup/orgmode/orgmode.go index 54188d2734..86222cc88e 100644 --- a/modules/markup/orgmode/orgmode.go +++ b/modules/markup/orgmode/orgmode.go @@ -8,7 +8,6 @@ import ( "bytes" "fmt" "html" - "strings" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" @@ -91,7 +90,7 @@ func (r *Renderer) WriteRegularLink(l org.RegularLink) { description := string(link) if l.Description != nil { - description = r.nodesAsString(l.Description...) + description = r.WriteNodesAsString(l.Description...) } switch l.Kind() { case "image": @@ -102,21 +101,3 @@ func (r *Renderer) WriteRegularLink(l org.RegularLink) { r.WriteString(fmt.Sprintf(`%s`, link, description, description)) } } - -func (r *Renderer) emptyClone() *Renderer { - wcopy := *(r.HTMLWriter) - wcopy.Builder = strings.Builder{} - - rcopy := *r - rcopy.HTMLWriter = &wcopy - - wcopy.ExtendingWriter = &rcopy - - return &rcopy -} - -func (r *Renderer) nodesAsString(nodes ...org.Node) string { - tmp := r.emptyClone() - org.WriteNodes(tmp, nodes...) - return tmp.String() -} diff --git a/vendor/github.com/niklasfasching/go-org/org/block.go b/vendor/github.com/niklasfasching/go-org/org/block.go index 0e7a526243..78ad9a7915 100644 --- a/vendor/github.com/niklasfasching/go-org/org/block.go +++ b/vendor/github.com/niklasfasching/go-org/org/block.go @@ -80,5 +80,5 @@ func trimIndentUpTo(max int) func(string) string { } } -func (n Example) String() string { return orgWriter.nodesAsString(n) } -func (n Block) String() string { return orgWriter.nodesAsString(n) } +func (n Example) String() string { return orgWriter.WriteNodesAsString(n) } +func (n Block) 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 e43eb626db..a9697c465d 100644 --- a/vendor/github.com/niklasfasching/go-org/org/document.go +++ b/vendor/github.com/niklasfasching/go-org/org/document.go @@ -90,7 +90,7 @@ func New() *Configuration { } // String returns the pretty printed Org mode string for the given nodes (see OrgWriter). -func String(nodes []Node) string { return orgWriter.nodesAsString(nodes...) } +func String(nodes []Node) string { return orgWriter.WriteNodesAsString(nodes...) } // Write is called after with an instance of the Writer interface to export a parsed Document into another format. func (d *Document) Write(w Writer) (out string, err error) { diff --git a/vendor/github.com/niklasfasching/go-org/org/drawer.go b/vendor/github.com/niklasfasching/go-org/org/drawer.go index 8bb9974380..eee590d8c4 100644 --- a/vendor/github.com/niklasfasching/go-org/org/drawer.go +++ b/vendor/github.com/niklasfasching/go-org/org/drawer.go @@ -93,5 +93,5 @@ func (d *PropertyDrawer) Get(key string) (string, bool) { return "", false } -func (n Drawer) String() string { return orgWriter.nodesAsString(n) } -func (n PropertyDrawer) String() string { return orgWriter.nodesAsString(n) } +func (n Drawer) String() string { return orgWriter.WriteNodesAsString(n) } +func (n PropertyDrawer) String() string { return orgWriter.WriteNodesAsString(n) } diff --git a/vendor/github.com/niklasfasching/go-org/org/footnote.go b/vendor/github.com/niklasfasching/go-org/org/footnote.go index 660e244386..e8604211e0 100644 --- a/vendor/github.com/niklasfasching/go-org/org/footnote.go +++ b/vendor/github.com/niklasfasching/go-org/org/footnote.go @@ -32,4 +32,4 @@ func (d *Document) parseFootnoteDefinition(i int, parentStop stopFn) (int, Node) return consumed, definition } -func (n FootnoteDefinition) String() string { return orgWriter.nodesAsString(n) } +func (n FootnoteDefinition) String() string { return orgWriter.WriteNodesAsString(n) } diff --git a/vendor/github.com/niklasfasching/go-org/org/headline.go b/vendor/github.com/niklasfasching/go-org/org/headline.go index 23b986fbc8..749d1ff005 100644 --- a/vendor/github.com/niklasfasching/go-org/org/headline.go +++ b/vendor/github.com/niklasfasching/go-org/org/headline.go @@ -98,4 +98,4 @@ func (parent *Section) add(current *Section) { } } -func (n Headline) String() string { return orgWriter.nodesAsString(n) } +func (n Headline) String() string { return orgWriter.WriteNodesAsString(n) } 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 90a48c6b4b..916618c450 100644 --- a/vendor/github.com/niklasfasching/go-org/org/html_writer.go +++ b/vendor/github.com/niklasfasching/go-org/org/html_writer.go @@ -69,16 +69,13 @@ func NewHTMLWriter() *HTMLWriter { } } -func (w *HTMLWriter) emptyClone() *HTMLWriter { - wcopy := *w - wcopy.Builder = strings.Builder{} - return &wcopy -} - -func (w *HTMLWriter) nodesAsString(nodes ...Node) string { - tmp := w.emptyClone() - WriteNodes(tmp, nodes...) - return tmp.String() +func (w *HTMLWriter) WriteNodesAsString(nodes ...Node) string { + original := w.Builder + w.Builder = strings.Builder{} + WriteNodes(w, nodes...) + out := w.String() + w.Builder = original + return out } func (w *HTMLWriter) WriterWithExtensions() Writer { @@ -104,12 +101,14 @@ func (w *HTMLWriter) WritePropertyDrawer(PropertyDrawer) {} func (w *HTMLWriter) WriteBlock(b Block) { content := "" if isRawTextBlock(b.Name) { - exportWriter := w.emptyClone() - exportWriter.htmlEscape = false - WriteNodes(exportWriter, b.Children...) - content = strings.TrimRightFunc(exportWriter.String(), unicode.IsSpace) + builder, htmlEscape := w.Builder, w.htmlEscape + w.Builder, w.htmlEscape = strings.Builder{}, false + WriteNodes(w, b.Children...) + out := w.String() + w.Builder, w.htmlEscape = builder, htmlEscape + content = strings.TrimRightFunc(out, unicode.IsSpace) } else { - content = w.nodesAsString(b.Children...) + content = w.WriteNodesAsString(b.Children...) } switch name := b.Name; { case name == "SRC": @@ -194,7 +193,7 @@ func (w *HTMLWriter) writeSection(section *Section) { // NOTE: To satisfy hugo ExtractTOC() check we cannot use `
  • \n` here. Doesn't really matter, just a note. w.WriteString("
  • ") h := section.Headline - title := cleanHeadlineTitleForHTMLAnchorRegexp.ReplaceAllString(w.nodesAsString(h.Title...), "") + title := cleanHeadlineTitleForHTMLAnchorRegexp.ReplaceAllString(w.WriteNodesAsString(h.Title...), "") w.WriteString(fmt.Sprintf("%s\n", h.ID(), title)) if len(section.Children) != 0 { w.WriteString("