diff --git a/org/block.go b/org/block.go index 0e7a526..78ad9a7 100644 --- a/org/block.go +++ b/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/org/document.go b/org/document.go index e43eb62..a9697c4 100644 --- a/org/document.go +++ b/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/org/drawer.go b/org/drawer.go index 8bb9974..eee590d 100644 --- a/org/drawer.go +++ b/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/org/footnote.go b/org/footnote.go index 660e244..e860421 100644 --- a/org/footnote.go +++ b/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/org/headline.go b/org/headline.go index 23b986f..749d1ff 100644 --- a/org/headline.go +++ b/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/org/html_writer.go b/org/html_writer.go index 90a48c6..916618c 100644 --- a/org/html_writer.go +++ b/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("