diff --git a/org/drawer.go b/org/drawer.go index bf2b7ae..7010ce8 100644 --- a/org/drawer.go +++ b/org/drawer.go @@ -37,7 +37,7 @@ func (d *Document) parseDrawer(i int, parentStop stopFn) (int, Node) { i += consumed drawer.Children = append(drawer.Children, nodes...) if i < len(d.tokens) && d.tokens[i].kind == "beginDrawer" { - p := Paragraph{[]Node{Text{d.tokens[i].content, false}}} + p := Paragraph{[]Node{Text{":" + d.tokens[i].content + ":", false}}} drawer.Children = append(drawer.Children, p) i++ } else { diff --git a/org/org.go b/org/org.go index 070eedc..0e32898 100644 --- a/org/org.go +++ b/org/org.go @@ -117,12 +117,11 @@ func (w *OrgWriter) writeHeadline(h Headline) { tmp.writeNodes(h.Title...) hString := tmp.String() if len(h.Tags) != 0 { - hString += " " tString := ":" + strings.Join(h.Tags, ":") + ":" if n := w.TagsColumn - len(tString) - len(hString); n > 0 { w.WriteString(hString + strings.Repeat(" ", n) + tString) } else { - w.WriteString(hString + tString) + w.WriteString(hString + " " + tString) } } else { w.WriteString(hString) @@ -142,8 +141,14 @@ func (w *OrgWriter) writeBlock(b Block) { if len(b.Parameters) != 0 { w.WriteString(" " + strings.Join(b.Parameters, " ")) } - w.WriteString("\n" + w.indent) + w.WriteString("\n") + if isRawTextBlock(b.Name) { + w.WriteString(w.indent) + } w.writeNodes(b.Children...) + if !isRawTextBlock(b.Name) { + w.WriteString(w.indent) + } w.WriteString("#+END_" + b.Name + "\n") } @@ -178,7 +183,11 @@ func (w *OrgWriter) writeExample(e Example) { } func (w *OrgWriter) writeKeyword(k Keyword) { - w.WriteString(w.indent + fmt.Sprintf("#+%s: %s\n", k.Key, k.Value)) + w.WriteString(w.indent + "#+" + k.Key + ":") + if k.Value != "" { + w.WriteString(" " + k.Value) + } + w.WriteString("\n") } func (w *OrgWriter) writeNodeWithMeta(n NodeWithMeta) { @@ -195,7 +204,7 @@ func (w *OrgWriter) writeNodeWithMeta(n NodeWithMeta) { } func (w *OrgWriter) writeComment(c Comment) { - w.WriteString(w.indent + "#" + c.Content) + w.WriteString(w.indent + "#" + c.Content + "\n") } func (w *OrgWriter) writeList(l List) { w.writeNodes(l.Items...) } diff --git a/org/testdata/blocks.html b/org/testdata/blocks.html index a5d7a23..d4001e8 100644 --- a/org/testdata/blocks.html +++ b/org/testdata/blocks.html @@ -28,7 +28,9 @@ empty lines! it also has multiple parameters -note that /inline/ *markup* ignored +src, example & export blocks treat their content as raw text +/inline/ *markup* is ignored + and whitespace is honored and not removed
examples like this @@ -40,7 +42,7 @@ note that /inline/ *markup* ignored Mongodb is webscale. (source: mongodb-is-web-scale)-blocks can contain other elements like +blocks like the quote block parse their content and can contain
+also whitespace is not significant +and superfluous whitespace (at the beginning of the line) is removed +