org: Fix drawer & block

- drawer entries without value were printed as FOO rather than :FOO:
- account for differences between raw & non-raw block:
  raw blocks are not wrapped in a further element, just raw text & line breaks:
  -> the first line has to be indented manually
  non raw blocks do not end in a linebreak newline -> the END_BLOCK line has to
  be indented (rather they end with a manual newline from another element)
This commit is contained in:
Niklas Fasching 2018-12-19 12:21:25 +01:00
parent 5f7d28f504
commit 905648c34b
5 changed files with 50 additions and 12 deletions

View file

@ -37,7 +37,7 @@ func (d *Document) parseDrawer(i int, parentStop stopFn) (int, Node) {
i += consumed i += consumed
drawer.Children = append(drawer.Children, nodes...) drawer.Children = append(drawer.Children, nodes...)
if i < len(d.tokens) && d.tokens[i].kind == "beginDrawer" { 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) drawer.Children = append(drawer.Children, p)
i++ i++
} else { } else {

View file

@ -117,12 +117,11 @@ func (w *OrgWriter) writeHeadline(h Headline) {
tmp.writeNodes(h.Title...) tmp.writeNodes(h.Title...)
hString := tmp.String() hString := tmp.String()
if len(h.Tags) != 0 { if len(h.Tags) != 0 {
hString += " "
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) - len(hString); n > 0 {
w.WriteString(hString + strings.Repeat(" ", n) + tString) w.WriteString(hString + strings.Repeat(" ", n) + tString)
} else { } else {
w.WriteString(hString + tString) w.WriteString(hString + " " + tString)
} }
} else { } else {
w.WriteString(hString) w.WriteString(hString)
@ -142,8 +141,14 @@ func (w *OrgWriter) writeBlock(b Block) {
if len(b.Parameters) != 0 { if len(b.Parameters) != 0 {
w.WriteString(" " + strings.Join(b.Parameters, " ")) 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...) w.writeNodes(b.Children...)
if !isRawTextBlock(b.Name) {
w.WriteString(w.indent)
}
w.WriteString("#+END_" + b.Name + "\n") w.WriteString("#+END_" + b.Name + "\n")
} }
@ -178,7 +183,11 @@ func (w *OrgWriter) writeExample(e Example) {
} }
func (w *OrgWriter) writeKeyword(k Keyword) { 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) { func (w *OrgWriter) writeNodeWithMeta(n NodeWithMeta) {
@ -195,7 +204,7 @@ func (w *OrgWriter) writeNodeWithMeta(n NodeWithMeta) {
} }
func (w *OrgWriter) writeComment(c Comment) { 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...) } func (w *OrgWriter) writeList(l List) { w.writeNodes(l.Items...) }

View file

@ -28,7 +28,9 @@ empty lines!
it also has multiple parameters 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
</pre> </pre>
<pre class="example"> <pre class="example">
examples like this examples like this
@ -40,7 +42,7 @@ note that /inline/ *markup* ignored
Mongodb is <strong>webscale</strong>. (source: <a href="http://www.mongodb-is-web-scale.com/">mongodb-is-web-scale</a>) Mongodb is <strong>webscale</strong>. (source: <a href="http://www.mongodb-is-web-scale.com/">mongodb-is-web-scale</a>)
</p> </p>
<p> <p>
blocks can contain other elements like blocks like the quote block parse their content and can contain
</p> </p>
<ul> <ul>
<li> <li>
@ -82,6 +84,10 @@ paragraphs
</p> </p>
</li> </li>
</ul> </ul>
<p>
also whitespace is not significant
and superfluous whitespace (at the beginning of the line) is removed
</p>
</blockquote> </blockquote>
<script> <script>
console.log("Hello World!") console.log("Hello World!")
@ -95,6 +101,11 @@ blocks can contain unindented lines that would normally end a list item
<pre class="example"> <pre class="example">
this line is not indented - if it was outside of a block the list item would end this line is not indented - if it was outside of a block the list item would end
</pre> </pre>
<blockquote>
<p>
this line is not indented - if it was outside of a block the list item would end
</p>
</blockquote>
<p> <p>
now we&#39;re outside the block again and the following unindented line will be outside of the list item now we&#39;re outside the block again and the following unindented line will be outside of the list item
</p> </p>

View file

@ -22,7 +22,9 @@ empty lines!
it also has multiple parameters 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
#+END_EXAMPLE #+END_EXAMPLE
: examples like this : examples like this
@ -32,7 +34,7 @@ note that /inline/ *markup* ignored
#+BEGIN_QUOTE #+BEGIN_QUOTE
Mongodb is *webscale*. (source: [[http://www.mongodb-is-web-scale.com/][mongodb-is-web-scale]]) Mongodb is *webscale*. (source: [[http://www.mongodb-is-web-scale.com/][mongodb-is-web-scale]])
blocks can contain other elements like blocks like the quote block parse their content and can contain
- lists - lists
- inline /markup/ - inline /markup/
- tables - tables
@ -41,6 +43,10 @@ blocks can contain other elements like
| baz | | baz |
- paragraphs - paragraphs
- ... - ...
also whitespace is not significant
and superfluous whitespace (at the beginning of the line) is removed
#+END_QUOTE #+END_QUOTE
#+BEGIN_EXPORT html #+BEGIN_EXPORT html
@ -54,6 +60,9 @@ console.log("Hello World!")
#+BEGIN_EXAMPLE #+BEGIN_EXAMPLE
this line is not indented - if it was outside of a block the list item would end this line is not indented - if it was outside of a block the list item would end
#+END_EXAMPLE #+END_EXAMPLE
#+BEGIN_QUOTE
this line is not indented - if it was outside of a block the list item would end
#+END_QUOTE
now we're outside the block again and the following unindented line will be outside of the list item now we're outside the block again and the following unindented line will be outside of the list item
this unindented line is outside of the list item this unindented line is outside of the list item
- list item 2 - list item 2

View file

@ -22,7 +22,9 @@ empty lines!
it also has multiple parameters 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
#+END_EXAMPLE #+END_EXAMPLE
: examples like this : examples like this
@ -32,7 +34,7 @@ note that /inline/ *markup* ignored
#+BEGIN_QUOTE #+BEGIN_QUOTE
Mongodb is *webscale*. (source: [[http://www.mongodb-is-web-scale.com/][mongodb-is-web-scale]]) Mongodb is *webscale*. (source: [[http://www.mongodb-is-web-scale.com/][mongodb-is-web-scale]])
blocks can contain other elements like blocks like the quote block parse their content and can contain
- lists - lists
- inline /markup/ - inline /markup/
- tables - tables
@ -41,6 +43,10 @@ blocks can contain other elements like
| baz | | baz |
- paragraphs - paragraphs
- ... - ...
also whitespace is not significant
and superfluous whitespace (at the beginning of the line) is removed
#+END_QUOTE #+END_QUOTE
#+BEGIN_EXPORT html #+BEGIN_EXPORT html
@ -54,6 +60,9 @@ console.log("Hello World!")
#+BEGIN_EXAMPLE #+BEGIN_EXAMPLE
this line is not indented - if it was outside of a block the list item would end this line is not indented - if it was outside of a block the list item would end
#+END_EXAMPLE #+END_EXAMPLE
#+BEGIN_QUOTE
this line is not indented - if it was outside of a block the list item would end
#+END_QUOTE
now we're outside the block again and the following unindented line will be outside of the list item now we're outside the block again and the following unindented line will be outside of the list item
this unindented line is outside of the list item this unindented line is outside of the list item
- list item 2 - list item 2