Misc cleanup: SETUP_FILE -> SETUPFILE, empty example lines, ...

This commit is contained in:
Niklas Fasching 2018-12-20 15:39:49 +01:00
parent d1054063cf
commit bc9c496f97
11 changed files with 17 additions and 15 deletions

View file

@ -8,11 +8,11 @@ type Example struct {
Children []Node Children []Node
} }
var exampleLineRegexp = regexp.MustCompile(`^(\s*): (.*)`) var exampleLineRegexp = regexp.MustCompile(`^(\s*):(\s(.*)|\s*$)`)
func lexExample(line string) (token, bool) { func lexExample(line string) (token, bool) {
if m := exampleLineRegexp.FindStringSubmatch(line); m != nil { 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 return nilToken, false
} }

View file

@ -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] != '\\' { if start == 0 || input[start-1] == '\n' || start+1 >= len(input) || input[start+1] != '\\' {
return 0, nil return 0, nil
} }
for i := start + 2; ; i++ { for i := start + 2; unicode.IsSpace(rune(input[i])); i++ {
if i == len(input)-1 || input[i] == '\n' { if i >= len(input) || input[i] == '\n' {
return i + 1 - start, ExplicitLineBreak{} return i + 1 - start, ExplicitLineBreak{}
} }
if !unicode.IsSpace(rune(input[i])) {
break
}
} }
return 0, nil 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) { func (d *Document) parseRegularLink(input string, start int) (int, Node) {
input = input[start:] input = input[start:]
if len(input) < 3 || input[1] != '[' || input[2] == '[' { if len(input) < 3 || input[:2] != "[[" || input[2] == '[' {
return 0, nil return 0, nil
} }
end := strings.Index(input, "]]") end := strings.Index(input, "]]")

View file

@ -52,7 +52,7 @@ func (d *Document) parseComment(i int, stop stopFn) (int, Node) {
func (d *Document) parseKeyword(i int, stop stopFn) (int, Node) { func (d *Document) parseKeyword(i int, stop stopFn) (int, Node) {
k := parseKeyword(d.tokens[i]) k := parseKeyword(d.tokens[i])
switch k.Key { switch k.Key {
case "SETUP_FILE": case "SETUPFILE":
return d.loadSetupFile(k) return d.loadSetupFile(k)
case "INCLUDE": case "INCLUDE":
return d.newInclude(k) return d.newInclude(k)

View file

@ -191,8 +191,10 @@ 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 + ":")
w.writeNodes(n) if content := w.nodesAsString(n); content != "" {
w.WriteString(" " + content)
}
w.WriteString("\n") w.WriteString("\n")
} }
} }

View file

@ -35,6 +35,7 @@ src, example & export blocks treat their content as raw text
<pre class="example"> <pre class="example">
examples like this examples like this
are also supported are also supported
note that /inline/ *markup* ignored note that /inline/ *markup* ignored
</pre> </pre>
<blockquote> <blockquote>

View file

@ -29,6 +29,7 @@ src, example & export blocks treat their content as raw text
: examples like this : examples like this
: are also supported : are also supported
:
: note that /inline/ *markup* ignored : note that /inline/ *markup* ignored
#+BEGIN_QUOTE #+BEGIN_QUOTE

View file

@ -29,6 +29,7 @@ src, example & export blocks treat their content as raw text
: examples like this : examples like this
: are also supported : are also supported
:
: note that /inline/ *markup* ignored : note that /inline/ *markup* ignored
#+BEGIN_QUOTE #+BEGIN_QUOTE

View file

@ -1,4 +1,4 @@
#+SETUP_FILE: setup_file_org #+SETUPFILE: setup_file_org
* Simple Headline [1/2] * Simple Headline [1/2]
- [X] checked - [X] checked
- [ ] unchecked - [ ] unchecked

View file

@ -1,4 +1,4 @@
#+SETUP_FILE: setup_file_org #+SETUPFILE: setup_file_org
* Simple Headline [1/2] * Simple Headline [1/2]
- [X] checked - [X] checked
- [ ] unchecked - [ ] unchecked

View file

@ -26,7 +26,7 @@
and text with an empty line in between as well! and text with an empty line in between as well!
- unordered list item 4 - unordered list item 4
: with an example : with an example
: :
: that spans multiple lines : that spans multiple lines

View file

@ -43,7 +43,7 @@ src block
</p> </p>
<div class="highlight"> <div class="highlight">
<pre> <pre>
#+SETUP_FILE: setup_file_org #+SETUPFILE: setup_file_org
* Simple Headline [1/2] * Simple Headline [1/2]
- [X] checked - [X] checked
- [ ] unchecked - [ ] unchecked