Add support for headline CUSTOM_ID property & linking

this introduces the PropertyDrawer node to make it easier to access the
properties associated to a headline - normal drawers don't parse their content
into kv pairs
This commit is contained in:
Niklas Fasching 2018-12-19 13:25:12 +01:00
parent ec895cbe83
commit aa42998dbc
8 changed files with 79 additions and 14 deletions

View file

@ -63,6 +63,8 @@ func (w *OrgWriter) writeNodes(ns ...Node) {
w.writeBlock(n)
case Drawer:
w.writeDrawer(n)
case PropertyDrawer:
w.writePropertyDrawer(n)
case FootnoteDefinition:
w.writeFootnoteDefinition(n)
@ -132,7 +134,7 @@ func (w *OrgWriter) writeHeadline(h Headline) {
w.WriteString(w.indent)
}
if h.Properties != nil {
w.writeNodes(h.Properties)
w.writeNodes(*h.Properties)
}
w.writeNodes(h.Children...)
}
@ -159,6 +161,18 @@ func (w *OrgWriter) writeDrawer(d Drawer) {
w.WriteString(w.indent + ":END:\n")
}
func (w *OrgWriter) writePropertyDrawer(d PropertyDrawer) {
w.WriteString(":PROPERTIES:\n")
for _, kvPair := range d.Properties {
k, v := kvPair[0], kvPair[1]
if v != "" {
v = " " + v
}
w.WriteString(fmt.Sprintf(":%s:%s\n", k, v))
}
w.WriteString(":END:\n")
}
func (w *OrgWriter) writeFootnoteDefinition(f FootnoteDefinition) {
w.WriteString(fmt.Sprintf("[fn:%s]", f.Name))
if !(len(f.Children) >= 1 && isEmptyLineParagraph(f.Children[0])) {