Support list items with empty first line

also dismiss implementing ordered list bullet overrides for now, e.g.
1. [@10] foo

add it once someone needs it - for now it seems like needless complexity
This commit is contained in:
Niklas Fasching 2018-12-19 17:40:47 +01:00
parent 4e536f44bd
commit 724cf6c23e
5 changed files with 29 additions and 7 deletions

View file

@ -7,9 +7,6 @@ Take a look at [[https://niklasfasching.github.io/go-org/][github pages]] for so
- more keywords: https://orgmode.org/manual/In_002dbuffer-settings.html
- headlines
- unique ids: see [[https://github.com/kaushalmodi/ox-hugo/blob/8472cf2d8667754c9da3728255634e8001a1da6d/ox-hugo.el#L1785-L1850][ox-hugo]] for auto generation
- improve list parsing
- handle list items with empty first line
- handle ordered list overrides [@10]
** links
https://orgmode.org/manual/External-links.html
https://orgmode.org/manual/Internal-links.html

View file

@ -25,16 +25,16 @@ type DescriptiveListItem struct {
Details []Node
}
var unorderedListRegexp = regexp.MustCompile(`^(\s*)([+*-])\s(.*)`)
var orderedListRegexp = regexp.MustCompile(`^(\s*)(([0-9]+|[a-zA-Z])[.)])\s+(.*)`)
var unorderedListRegexp = regexp.MustCompile(`^(\s*)([+*-])(\s+(.*)|\s*$)`)
var orderedListRegexp = regexp.MustCompile(`^(\s*)(([0-9]+|[a-zA-Z])[.)])(\s+(.*)|\s*$)`)
var descriptiveListItemRegexp = regexp.MustCompile(`\s::(\s|$)`)
var listItemStatusRegexp = regexp.MustCompile(`\[( |X|-)\]\s`)
func lexList(line string) (token, bool) {
if m := unorderedListRegexp.FindStringSubmatch(line); m != nil {
return token{"unorderedList", len(m[1]), m[3], m}, true
return token{"unorderedList", len(m[1]), m[4], m}, true
} else if m := orderedListRegexp.FindStringSubmatch(line); m != nil {
return token{"orderedList", len(m[1]), m[4], m}, true
return token{"orderedList", len(m[1]), m[5], m}, true
}
return nilToken, false
}

View file

@ -6,6 +6,12 @@ unordered list item 1
</li>
<li>
<p>
list item with empty first and second line <br>
normally an empty line breaks the list item - but we make an exception for the first line and don&#39;t count it towards that limit
</p>
</li>
<li>
<p>
unordered list item 2 - with <code>inline</code> <em>markup</em>
</p>
<ol>
@ -36,6 +42,11 @@ ordered sublist item 3
ordered sublist item 2
</p>
</li>
<li>
<p>
list item with empty first and second line - see above
</p>
</li>
</ol>
</li>
<li class="checked">

View file

@ -1,10 +1,17 @@
- [ ] unordered list item 1
-
list item with empty first and second line \\
normally an empty line breaks the list item - but we make an exception for the first line and don't count it towards that limit
- unordered list item 2 - with ~inline~ /markup/
1. [-] ordered sublist item 1
a) [X] ordered sublist item 1
b) [ ] ordered sublist item 2
c) [X] ordered sublist item 3
2. ordered sublist item 2
3.
list item with empty first and second line - see above
- [X] unordered list item 3 - and a [[https://example.com][link]]
and some lines of text
1. and another subitem

View file

@ -1,10 +1,17 @@
- [ ] unordered list item 1
-
list item with empty first and second line \\
normally an empty line breaks the list item - but we make an exception for the first line and don't count it towards that limit
- unordered list item 2 - with ~inline~ /markup/
1. [-] ordered sublist item 1
a) [X] ordered sublist item 1
b) [ ] ordered sublist item 2
c) [X] ordered sublist item 3
2. ordered sublist item 2
3.
list item with empty first and second line - see above
- [X] unordered list item 3 - and a [[https://example.com][link]]
and some lines of text
1. and another subitem