From 724cf6c23e81c4239de6bb43ec44d8a80aeab309 Mon Sep 17 00:00:00 2001
From: Niklas Fasching
Date: Wed, 19 Dec 2018 17:40:47 +0100
Subject: [PATCH] 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
---
README.org | 3 ---
org/list.go | 8 ++++----
org/testdata/lists.html | 11 +++++++++++
org/testdata/lists.org | 7 +++++++
org/testdata/lists.pretty_org | 7 +++++++
5 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/README.org b/README.org
index 0d123fe..ebb9d70 100644
--- a/README.org
+++ b/README.org
@@ -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
diff --git a/org/list.go b/org/list.go
index e4265dc..63f89b4 100644
--- a/org/list.go
+++ b/org/list.go
@@ -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
}
diff --git a/org/testdata/lists.html b/org/testdata/lists.html
index 4970e90..9729362 100644
--- a/org/testdata/lists.html
+++ b/org/testdata/lists.html
@@ -6,6 +6,12 @@ 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
@@ -36,6 +42,11 @@ ordered sublist item 3
ordered sublist item 2
+
+
+list item with empty first and second line - see above
+
+
diff --git a/org/testdata/lists.org b/org/testdata/lists.org
index 46a515b..b8983f1 100644
--- a/org/testdata/lists.org
+++ b/org/testdata/lists.org
@@ -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
diff --git a/org/testdata/lists.pretty_org b/org/testdata/lists.pretty_org
index 46a515b..b8983f1 100644
--- a/org/testdata/lists.pretty_org
+++ b/org/testdata/lists.pretty_org
@@ -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