Skip to content

Commit

Permalink
Export WriteNodesAsString on writer interface
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasfasching committed Oct 30, 2019
1 parent 4292628 commit 3c380c8
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 40 deletions.
4 changes: 2 additions & 2 deletions org/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
2 changes: 1 addition & 1 deletion org/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions org/drawer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
2 changes: 1 addition & 1 deletion org/footnote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
2 changes: 1 addition & 1 deletion org/headline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
14 changes: 7 additions & 7 deletions org/html_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (w *HTMLWriter) emptyClone() *HTMLWriter {
return &wcopy
}

func (w *HTMLWriter) nodesAsString(nodes ...Node) string {
func (w *HTMLWriter) WriteNodesAsString(nodes ...Node) string {
tmp := w.emptyClone()
WriteNodes(tmp, nodes...)
return tmp.String()
Expand Down Expand Up @@ -109,7 +109,7 @@ func (w *HTMLWriter) WriteBlock(b Block) {
WriteNodes(exportWriter, b.Children...)
content = strings.TrimRightFunc(exportWriter.String(), unicode.IsSpace)
} else {
content = w.nodesAsString(b.Children...)
content = w.WriteNodesAsString(b.Children...)
}
switch name := b.Name; {
case name == "SRC":
Expand Down Expand Up @@ -194,7 +194,7 @@ func (w *HTMLWriter) writeSection(section *Section) {
// NOTE: To satisfy hugo ExtractTOC() check we cannot use `<li>\n` here. Doesn't really matter, just a note.
w.WriteString("<li>")
h := section.Headline
title := cleanHeadlineTitleForHTMLAnchorRegexp.ReplaceAllString(w.nodesAsString(h.Title...), "")
title := cleanHeadlineTitleForHTMLAnchorRegexp.ReplaceAllString(w.WriteNodesAsString(h.Title...), "")
w.WriteString(fmt.Sprintf("<a href=\"#%s\">%s</a>\n", h.ID(), title))
if len(section.Children) != 0 {
w.WriteString("<ul>\n")
Expand Down Expand Up @@ -306,7 +306,7 @@ func (w *HTMLWriter) WriteRegularLink(l RegularLink) {
}
description := url
if l.Description != nil {
description = w.nodesAsString(l.Description...)
description = w.WriteNodesAsString(l.Description...)
}
switch l.Kind() {
case "image":
Expand Down Expand Up @@ -384,10 +384,10 @@ func (w *HTMLWriter) WriteHorizontalRule(h HorizontalRule) {
}

func (w *HTMLWriter) WriteNodeWithMeta(n NodeWithMeta) {
out := w.nodesAsString(n.Node)
out := w.WriteNodesAsString(n.Node)
if p, ok := n.Node.(Paragraph); ok {
if len(p.Children) == 1 && isImageOrVideoLink(p.Children[0]) {
out = w.nodesAsString(p.Children[0])
out = w.WriteNodesAsString(p.Children[0])
}
}
for _, attributes := range n.Meta.HTMLAttributes {
Expand All @@ -399,7 +399,7 @@ func (w *HTMLWriter) WriteNodeWithMeta(n NodeWithMeta) {
if i != 0 {
caption += " "
}
caption += w.nodesAsString(ns...)
caption += w.WriteNodesAsString(ns...)
}
out = fmt.Sprintf("<figure>\n%s<figcaption>\n%s\n</figcaption>\n</figure>\n", out, caption)
}
Expand Down
18 changes: 9 additions & 9 deletions org/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,12 @@ func (l RegularLink) Kind() string {
return "regular"
}

func (n Text) String() string { return orgWriter.nodesAsString(n) }
func (n LineBreak) String() string { return orgWriter.nodesAsString(n) }
func (n ExplicitLineBreak) String() string { return orgWriter.nodesAsString(n) }
func (n StatisticToken) String() string { return orgWriter.nodesAsString(n) }
func (n Emphasis) String() string { return orgWriter.nodesAsString(n) }
func (n LatexFragment) String() string { return orgWriter.nodesAsString(n) }
func (n FootnoteLink) String() string { return orgWriter.nodesAsString(n) }
func (n RegularLink) String() string { return orgWriter.nodesAsString(n) }
func (n Timestamp) String() string { return orgWriter.nodesAsString(n) }
func (n Text) String() string { return orgWriter.WriteNodesAsString(n) }
func (n LineBreak) String() string { return orgWriter.WriteNodesAsString(n) }
func (n ExplicitLineBreak) String() string { return orgWriter.WriteNodesAsString(n) }
func (n StatisticToken) String() string { return orgWriter.WriteNodesAsString(n) }
func (n Emphasis) String() string { return orgWriter.WriteNodesAsString(n) }
func (n LatexFragment) String() string { return orgWriter.WriteNodesAsString(n) }
func (n FootnoteLink) String() string { return orgWriter.WriteNodesAsString(n) }
func (n RegularLink) String() string { return orgWriter.WriteNodesAsString(n) }
func (n Timestamp) String() string { return orgWriter.WriteNodesAsString(n) }
10 changes: 5 additions & 5 deletions org/keyword.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ func (d *Document) loadSetupFile(k Keyword) (int, Node) {
return 1, k
}

func (n Comment) String() string { return orgWriter.nodesAsString(n) }
func (n Keyword) String() string { return orgWriter.nodesAsString(n) }
func (n NodeWithMeta) String() string { return orgWriter.nodesAsString(n) }
func (n NodeWithName) String() string { return orgWriter.nodesAsString(n) }
func (n Include) String() string { return orgWriter.nodesAsString(n) }
func (n Comment) String() string { return orgWriter.WriteNodesAsString(n) }
func (n Keyword) String() string { return orgWriter.WriteNodesAsString(n) }
func (n NodeWithMeta) String() string { return orgWriter.WriteNodesAsString(n) }
func (n NodeWithName) String() string { return orgWriter.WriteNodesAsString(n) }
func (n Include) String() string { return orgWriter.WriteNodesAsString(n) }
6 changes: 3 additions & 3 deletions org/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ func (d *Document) parseListItem(l List, i int, parentStop stopFn) (int, Node) {
return i - start, ListItem{bullet, status, nodes}
}

func (n List) String() string { return orgWriter.nodesAsString(n) }
func (n ListItem) String() string { return orgWriter.nodesAsString(n) }
func (n DescriptiveListItem) String() string { return orgWriter.nodesAsString(n) }
func (n List) String() string { return orgWriter.WriteNodesAsString(n) }
func (n ListItem) String() string { return orgWriter.WriteNodesAsString(n) }
func (n DescriptiveListItem) String() string { return orgWriter.WriteNodesAsString(n) }
12 changes: 6 additions & 6 deletions org/org_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (w *OrgWriter) emptyClone() *OrgWriter {
return &wcopy
}

func (w *OrgWriter) nodesAsString(nodes ...Node) string {
func (w *OrgWriter) WriteNodesAsString(nodes ...Node) string {
tmp := w.emptyClone()
WriteNodes(tmp, nodes...)
return tmp.String()
Expand Down Expand Up @@ -123,15 +123,15 @@ func (w *OrgWriter) WritePropertyDrawer(d PropertyDrawer) {

func (w *OrgWriter) WriteFootnoteDefinition(f FootnoteDefinition) {
w.WriteString(fmt.Sprintf("[fn:%s]", f.Name))
content := w.nodesAsString(f.Children...)
content := w.WriteNodesAsString(f.Children...)
if content != "" && !unicode.IsSpace(rune(content[0])) {
w.WriteString(" ")
}
w.WriteString(content)
}

func (w *OrgWriter) WriteParagraph(p Paragraph) {
content := w.nodesAsString(p.Children...)
content := w.WriteNodesAsString(p.Children...)
if len(content) > 0 && content[0] != '\n' {
w.WriteString(w.indent)
}
Expand All @@ -141,7 +141,7 @@ func (w *OrgWriter) WriteParagraph(p Paragraph) {
func (w *OrgWriter) WriteExample(e Example) {
for _, n := range e.Children {
w.WriteString(w.indent + ":")
if content := w.nodesAsString(n); content != "" {
if content := w.WriteNodesAsString(n); content != "" {
w.WriteString(" " + content)
}
w.WriteString("\n")
Expand Down Expand Up @@ -207,7 +207,7 @@ func (w *OrgWriter) WriteDescriptiveListItem(di DescriptiveListItem) {
}
indent := w.indent + strings.Repeat(" ", len(di.Bullet)+1)
if len(di.Term) != 0 {
term := w.nodesAsString(di.Term...)
term := w.WriteNodesAsString(di.Term...)
w.WriteString(" " + term + " ::")
indent = indent + strings.Repeat(" ", len(term)+4)
}
Expand Down Expand Up @@ -239,7 +239,7 @@ func (w *OrgWriter) WriteTable(t Table) {
w.WriteString(`|`)
for _, column := range row.Columns {
w.WriteString(` `)
content := w.nodesAsString(column.Children...)
content := w.WriteNodesAsString(column.Children...)
if content == "" {
content = " "
}
Expand Down
4 changes: 2 additions & 2 deletions org/paragraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ func (d *Document) parseHorizontalRule(i int, parentStop stopFn) (int, Node) {
return 1, HorizontalRule{}
}

func (n Paragraph) String() string { return orgWriter.nodesAsString(n) }
func (n HorizontalRule) String() string { return orgWriter.nodesAsString(n) }
func (n Paragraph) String() string { return orgWriter.WriteNodesAsString(n) }
func (n HorizontalRule) String() string { return orgWriter.WriteNodesAsString(n) }
2 changes: 1 addition & 1 deletion org/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ func isSpecialRow(rawColumns []string) bool {
return isAlignRow
}

func (n Table) String() string { return orgWriter.nodesAsString(n) }
func (n Table) String() string { return orgWriter.WriteNodesAsString(n) }
1 change: 1 addition & 0 deletions org/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Writer interface {
String() string // String is called at the very end to retrieve the final output.

WriterWithExtensions() Writer
WriteNodesAsString(...Node) string

WriteKeyword(Keyword)
WriteInclude(Include)
Expand Down

0 comments on commit 3c380c8

Please sign in to comment.