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
}
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
}

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] != '\\' {
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, "]]")

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) {
k := parseKeyword(d.tokens[i])
switch k.Key {
case "SETUP_FILE":
case "SETUPFILE":
return d.loadSetupFile(k)
case "INCLUDE":
return d.newInclude(k)

View file

@ -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")
}
}

View file

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

View file

@ -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

View file

@ -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

View file

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

View file

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

View file

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