From bc9c496f9704e07c2956c68845dcb8f8b5200e13 Mon Sep 17 00:00:00 2001
From: Niklas Fasching
Date: Thu, 20 Dec 2018 15:39:49 +0100
Subject: [PATCH] Misc cleanup: SETUP_FILE -> SETUPFILE, empty example lines,
...
---
org/example.go | 4 ++--
org/inline.go | 9 +++------
org/keyword.go | 2 +-
org/org.go | 6 ++++--
org/testdata/blocks.html | 1 +
org/testdata/blocks.org | 1 +
org/testdata/blocks.pretty_org | 1 +
org/testdata/headlines.org | 2 +-
org/testdata/headlines.pretty_org | 2 +-
org/testdata/lists.pretty_org | 2 +-
org/testdata/misc.html | 2 +-
11 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/org/example.go b/org/example.go
index 9e737cb..988751d 100644
--- a/org/example.go
+++ b/org/example.go
@@ -8,11 +8,11 @@ type Example struct {
Children []Node
}
-var exampleLineRegexp = regexp.MustCompile(`^(\s*): (.*)`)
+var exampleLineRegexp = regexp.MustCompile(`^(\s*):(\s(.*)|\s*$)`)
func lexExample(line string) (token, bool) {
if m := exampleLineRegexp.FindStringSubmatch(line); m != nil {
- return token{"example", len(m[1]), m[2], m}, true
+ return token{"example", len(m[1]), m[3], m}, true
}
return nilToken, false
}
diff --git a/org/inline.go b/org/inline.go
index fcab00d..b02c1a3 100644
--- a/org/inline.go
+++ b/org/inline.go
@@ -118,13 +118,10 @@ func (d *Document) parseExplicitLineBreak(input string, start int) (int, Node) {
if start == 0 || input[start-1] == '\n' || start+1 >= len(input) || input[start+1] != '\\' {
return 0, nil
}
- for i := start + 2; ; i++ {
- if i == len(input)-1 || input[i] == '\n' {
+ for i := start + 2; unicode.IsSpace(rune(input[i])); i++ {
+ if i >= len(input) || input[i] == '\n' {
return i + 1 - start, ExplicitLineBreak{}
}
- if !unicode.IsSpace(rune(input[i])) {
- break
- }
}
return 0, nil
}
@@ -202,7 +199,7 @@ func (d *Document) parseAutoLink(input string, start int) (int, int, Node) {
func (d *Document) parseRegularLink(input string, start int) (int, Node) {
input = input[start:]
- if len(input) < 3 || input[1] != '[' || input[2] == '[' {
+ if len(input) < 3 || input[:2] != "[[" || input[2] == '[' {
return 0, nil
}
end := strings.Index(input, "]]")
diff --git a/org/keyword.go b/org/keyword.go
index 512f33d..06450c7 100644
--- a/org/keyword.go
+++ b/org/keyword.go
@@ -52,7 +52,7 @@ func (d *Document) parseComment(i int, stop stopFn) (int, Node) {
func (d *Document) parseKeyword(i int, stop stopFn) (int, Node) {
k := parseKeyword(d.tokens[i])
switch k.Key {
- case "SETUP_FILE":
+ case "SETUPFILE":
return d.loadSetupFile(k)
case "INCLUDE":
return d.newInclude(k)
diff --git a/org/org.go b/org/org.go
index 2c49c9e..13f198d 100644
--- a/org/org.go
+++ b/org/org.go
@@ -191,8 +191,10 @@ func (w *OrgWriter) writeParagraph(p Paragraph) {
func (w *OrgWriter) writeExample(e Example) {
for _, n := range e.Children {
- w.WriteString(w.indent + ":" + " ")
- w.writeNodes(n)
+ w.WriteString(w.indent + ":")
+ if content := w.nodesAsString(n); content != "" {
+ w.WriteString(" " + content)
+ }
w.WriteString("\n")
}
}
diff --git a/org/testdata/blocks.html b/org/testdata/blocks.html
index d4001e8..ed270fe 100644
--- a/org/testdata/blocks.html
+++ b/org/testdata/blocks.html
@@ -35,6 +35,7 @@ src, example & export blocks treat their content as raw text
examples like this
are also supported
+
note that /inline/ *markup* ignored
diff --git a/org/testdata/blocks.org b/org/testdata/blocks.org
index 5113453..e9e9624 100644
--- a/org/testdata/blocks.org
+++ b/org/testdata/blocks.org
@@ -29,6 +29,7 @@ src, example & export blocks treat their content as raw text
: examples like this
: are also supported
+:
: note that /inline/ *markup* ignored
#+BEGIN_QUOTE
diff --git a/org/testdata/blocks.pretty_org b/org/testdata/blocks.pretty_org
index 957f276..40fc8cc 100644
--- a/org/testdata/blocks.pretty_org
+++ b/org/testdata/blocks.pretty_org
@@ -29,6 +29,7 @@ src, example & export blocks treat their content as raw text
: examples like this
: are also supported
+:
: note that /inline/ *markup* ignored
#+BEGIN_QUOTE
diff --git a/org/testdata/headlines.org b/org/testdata/headlines.org
index f498598..3e82dc5 100644
--- a/org/testdata/headlines.org
+++ b/org/testdata/headlines.org
@@ -1,4 +1,4 @@
-#+SETUP_FILE: setup_file_org
+#+SETUPFILE: setup_file_org
* Simple Headline [1/2]
- [X] checked
- [ ] unchecked
diff --git a/org/testdata/headlines.pretty_org b/org/testdata/headlines.pretty_org
index c9adde0..65a34f7 100644
--- a/org/testdata/headlines.pretty_org
+++ b/org/testdata/headlines.pretty_org
@@ -1,4 +1,4 @@
-#+SETUP_FILE: setup_file_org
+#+SETUPFILE: setup_file_org
* Simple Headline [1/2]
- [X] checked
- [ ] unchecked
diff --git a/org/testdata/lists.pretty_org b/org/testdata/lists.pretty_org
index b8983f1..72c757a 100644
--- a/org/testdata/lists.pretty_org
+++ b/org/testdata/lists.pretty_org
@@ -26,7 +26,7 @@
and text with an empty line in between as well!
- unordered list item 4
: with an example
- :
+ :
: that spans multiple lines
diff --git a/org/testdata/misc.html b/org/testdata/misc.html
index fb40dd4..35be67c 100644
--- a/org/testdata/misc.html
+++ b/org/testdata/misc.html
@@ -43,7 +43,7 @@ src block
-#+SETUP_FILE: setup_file_org
+#+SETUPFILE: setup_file_org
* Simple Headline [1/2]
- [X] checked
- [ ] unchecked