|
|
@ -43,39 +43,33 @@ func (w *OrgWriter) WriterWithExtensions() Writer { |
|
|
|
func (w *OrgWriter) Before(d *Document) {} |
|
|
|
func (w *OrgWriter) Before(d *Document) {} |
|
|
|
func (w *OrgWriter) After(d *Document) {} |
|
|
|
func (w *OrgWriter) After(d *Document) {} |
|
|
|
|
|
|
|
|
|
|
|
func (w *OrgWriter) emptyClone() *OrgWriter { |
|
|
|
func (w *OrgWriter) WriteNodesAsString(nodes ...Node) string { |
|
|
|
wcopy := *w |
|
|
|
builder := w.Builder |
|
|
|
wcopy.Builder = strings.Builder{} |
|
|
|
w.Builder = strings.Builder{} |
|
|
|
return &wcopy |
|
|
|
WriteNodes(w, nodes...) |
|
|
|
} |
|
|
|
out := w.String() |
|
|
|
|
|
|
|
w.Builder = builder |
|
|
|
func (w *OrgWriter) nodesAsString(nodes ...Node) string { |
|
|
|
return out |
|
|
|
tmp := w.emptyClone() |
|
|
|
|
|
|
|
WriteNodes(tmp, nodes...) |
|
|
|
|
|
|
|
return tmp.String() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (w *OrgWriter) WriteHeadline(h Headline) { |
|
|
|
func (w *OrgWriter) WriteHeadline(h Headline) { |
|
|
|
tmp := w.emptyClone() |
|
|
|
start := w.Len() |
|
|
|
tmp.WriteString(strings.Repeat("*", h.Lvl)) |
|
|
|
w.WriteString(strings.Repeat("*", h.Lvl)) |
|
|
|
if h.Status != "" { |
|
|
|
if h.Status != "" { |
|
|
|
tmp.WriteString(" " + h.Status) |
|
|
|
w.WriteString(" " + h.Status) |
|
|
|
} |
|
|
|
} |
|
|
|
if h.Priority != "" { |
|
|
|
if h.Priority != "" { |
|
|
|
tmp.WriteString(" [#" + h.Priority + "]") |
|
|
|
w.WriteString(" [#" + h.Priority + "]") |
|
|
|
} |
|
|
|
} |
|
|
|
tmp.WriteString(" ") |
|
|
|
w.WriteString(" ") |
|
|
|
WriteNodes(tmp, h.Title...) |
|
|
|
WriteNodes(w, h.Title...) |
|
|
|
hString := tmp.String() |
|
|
|
|
|
|
|
if len(h.Tags) != 0 { |
|
|
|
if len(h.Tags) != 0 { |
|
|
|
tString := ":" + strings.Join(h.Tags, ":") + ":" |
|
|
|
tString := ":" + strings.Join(h.Tags, ":") + ":" |
|
|
|
if n := w.TagsColumn - len(tString) - len(hString); n > 0 { |
|
|
|
if n := w.TagsColumn - len(tString) - (w.Len() - start); n > 0 { |
|
|
|
w.WriteString(hString + strings.Repeat(" ", n) + tString) |
|
|
|
w.WriteString(strings.Repeat(" ", n) + tString) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
w.WriteString(hString + " " + tString) |
|
|
|
w.WriteString(" " + tString) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
w.WriteString(hString) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
w.WriteString("\n") |
|
|
|
w.WriteString("\n") |
|
|
|
if len(h.Children) != 0 { |
|
|
|
if len(h.Children) != 0 { |
|
|
@ -123,7 +117,7 @@ func (w *OrgWriter) WritePropertyDrawer(d PropertyDrawer) { |
|
|
|
|
|
|
|
|
|
|
|
func (w *OrgWriter) WriteFootnoteDefinition(f FootnoteDefinition) { |
|
|
|
func (w *OrgWriter) WriteFootnoteDefinition(f FootnoteDefinition) { |
|
|
|
w.WriteString(fmt.Sprintf("[fn:%s]", f.Name)) |
|
|
|
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])) { |
|
|
|
if content != "" && !unicode.IsSpace(rune(content[0])) { |
|
|
|
w.WriteString(" ") |
|
|
|
w.WriteString(" ") |
|
|
|
} |
|
|
|
} |
|
|
@ -131,7 +125,7 @@ func (w *OrgWriter) WriteFootnoteDefinition(f FootnoteDefinition) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (w *OrgWriter) WriteParagraph(p Paragraph) { |
|
|
|
func (w *OrgWriter) WriteParagraph(p Paragraph) { |
|
|
|
content := w.nodesAsString(p.Children...) |
|
|
|
content := w.WriteNodesAsString(p.Children...) |
|
|
|
if len(content) > 0 && content[0] != '\n' { |
|
|
|
if len(content) > 0 && content[0] != '\n' { |
|
|
|
w.WriteString(w.indent) |
|
|
|
w.WriteString(w.indent) |
|
|
|
} |
|
|
|
} |
|
|
@ -141,7 +135,7 @@ func (w *OrgWriter) WriteParagraph(p Paragraph) { |
|
|
|
func (w *OrgWriter) WriteExample(e Example) { |
|
|
|
func (w *OrgWriter) WriteExample(e Example) { |
|
|
|
for _, n := range e.Children { |
|
|
|
for _, n := range e.Children { |
|
|
|
w.WriteString(w.indent + ":") |
|
|
|
w.WriteString(w.indent + ":") |
|
|
|
if content := w.nodesAsString(n); content != "" { |
|
|
|
if content := w.WriteNodesAsString(n); content != "" { |
|
|
|
w.WriteString(" " + content) |
|
|
|
w.WriteString(" " + content) |
|
|
|
} |
|
|
|
} |
|
|
|
w.WriteString("\n") |
|
|
|
w.WriteString("\n") |
|
|
@ -185,10 +179,11 @@ func (w *OrgWriter) WriteComment(c Comment) { |
|
|
|
func (w *OrgWriter) WriteList(l List) { WriteNodes(w, l.Items...) } |
|
|
|
func (w *OrgWriter) WriteList(l List) { WriteNodes(w, l.Items...) } |
|
|
|
|
|
|
|
|
|
|
|
func (w *OrgWriter) WriteListItem(li ListItem) { |
|
|
|
func (w *OrgWriter) WriteListItem(li ListItem) { |
|
|
|
liWriter := w.emptyClone() |
|
|
|
originalBuilder, originalIndent := w.Builder, w.indent |
|
|
|
liWriter.indent = w.indent + strings.Repeat(" ", len(li.Bullet)+1) |
|
|
|
w.Builder, w.indent = strings.Builder{}, w.indent+strings.Repeat(" ", len(li.Bullet)+1) |
|
|
|
WriteNodes(liWriter, li.Children...) |
|
|
|
WriteNodes(w, li.Children...) |
|
|
|
content := strings.TrimPrefix(liWriter.String(), liWriter.indent) |
|
|
|
content := strings.TrimPrefix(w.String(), w.indent) |
|
|
|
|
|
|
|
w.Builder, w.indent = originalBuilder, originalIndent |
|
|
|
w.WriteString(w.indent + li.Bullet) |
|
|
|
w.WriteString(w.indent + li.Bullet) |
|
|
|
if li.Status != "" { |
|
|
|
if li.Status != "" { |
|
|
|
w.WriteString(fmt.Sprintf(" [%s]", li.Status)) |
|
|
|
w.WriteString(fmt.Sprintf(" [%s]", li.Status)) |
|
|
@ -207,14 +202,15 @@ func (w *OrgWriter) WriteDescriptiveListItem(di DescriptiveListItem) { |
|
|
|
} |
|
|
|
} |
|
|
|
indent := w.indent + strings.Repeat(" ", len(di.Bullet)+1) |
|
|
|
indent := w.indent + strings.Repeat(" ", len(di.Bullet)+1) |
|
|
|
if len(di.Term) != 0 { |
|
|
|
if len(di.Term) != 0 { |
|
|
|
term := w.nodesAsString(di.Term...) |
|
|
|
term := w.WriteNodesAsString(di.Term...) |
|
|
|
w.WriteString(" " + term + " ::") |
|
|
|
w.WriteString(" " + term + " ::") |
|
|
|
indent = indent + strings.Repeat(" ", len(term)+4) |
|
|
|
indent = indent + strings.Repeat(" ", len(term)+4) |
|
|
|
} |
|
|
|
} |
|
|
|
diWriter := w.emptyClone() |
|
|
|
originalBuilder, originalIndent := w.Builder, w.indent |
|
|
|
diWriter.indent = indent |
|
|
|
w.Builder, w.indent = strings.Builder{}, indent |
|
|
|
WriteNodes(diWriter, di.Details...) |
|
|
|
WriteNodes(w, di.Details...) |
|
|
|
details := strings.TrimPrefix(diWriter.String(), diWriter.indent) |
|
|
|
details := strings.TrimPrefix(w.String(), w.indent) |
|
|
|
|
|
|
|
w.Builder, w.indent = originalBuilder, originalIndent |
|
|
|
if len(details) > 0 && details[0] == '\n' { |
|
|
|
if len(details) > 0 && details[0] == '\n' { |
|
|
|
w.WriteString(details) |
|
|
|
w.WriteString(details) |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -239,7 +235,7 @@ func (w *OrgWriter) WriteTable(t Table) { |
|
|
|
w.WriteString(`|`) |
|
|
|
w.WriteString(`|`) |
|
|
|
for _, column := range row.Columns { |
|
|
|
for _, column := range row.Columns { |
|
|
|
w.WriteString(` `) |
|
|
|
w.WriteString(` `) |
|
|
|
content := w.nodesAsString(column.Children...) |
|
|
|
content := w.WriteNodesAsString(column.Children...) |
|
|
|
if content == "" { |
|
|
|
if content == "" { |
|
|
|
content = " " |
|
|
|
content = " " |
|
|
|
} |
|
|
|
} |
|
|
@ -326,9 +322,6 @@ func (w *OrgWriter) WriteRegularLink(l RegularLink) { |
|
|
|
} else if l.Description == nil { |
|
|
|
} else if l.Description == nil { |
|
|
|
w.WriteString(fmt.Sprintf("[[%s]]", l.URL)) |
|
|
|
w.WriteString(fmt.Sprintf("[[%s]]", l.URL)) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
descriptionWriter := w.emptyClone() |
|
|
|
w.WriteString(fmt.Sprintf("[[%s][%s]]", l.URL, w.WriteNodesAsString(l.Description...))) |
|
|
|
WriteNodes(descriptionWriter, l.Description...) |
|
|
|
|
|
|
|
description := descriptionWriter.String() |
|
|
|
|
|
|
|
w.WriteString(fmt.Sprintf("[[%s][%s]]", l.URL, description)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|