summaryrefslogtreecommitdiff
path: root/rst_parser.lua
diff options
context:
space:
mode:
Diffstat (limited to 'rst_parser.lua')
-rw-r--r--rst_parser.lua34
1 files changed, 19 insertions, 15 deletions
diff --git a/rst_parser.lua b/rst_parser.lua
index 7162597..1adffb9 100644
--- a/rst_parser.lua
+++ b/rst_parser.lua
@@ -836,7 +836,6 @@ local parser = P{
-- the next rule handles enumerations as well
bullet_list = V"bullet_init"
- --* ((V"blank_line" - V"end_block")^-1 * (V"bullet_list" + V"bullet_continue"))^0
* (V"blank_line"^-1 * (V"bullet_list" + V"bullet_continue" + V"comment"))^0
* V"bullet_stop"
* Cmt(Cc(nil), function (s, i)
@@ -848,7 +847,6 @@ local parser = P{
return true
end),
- --bullet_stop = V"blank_line" * Cs(Cc("")) / rst.stopitemize,
bullet_stop = V"end_block" / rst.stopitemize,
bullet_init = Ct(C(V"bullet_first") * V"bullet_itemrest")
@@ -861,13 +859,13 @@ local parser = P{
local n_spaces = match(P" "^0, bullet)
warn("first",
t.depth,
- (t.depth == 0 and n_spaces == 1) or
+ (t.depth == 0 and n_spaces >= 1) or
(t.depth > 0 and n_spaces > 1),
bullet,
oldbullet,
helpers.list.conversion(bullet))
- if t.depth == 0 and n_spaces == 1 then -- first level
+ if t.depth == 0 and n_spaces >= 1 then -- first level
t.depth = 1 -- “push”
t.bullets[1] = bullet
t.lastbullet = bullet
@@ -910,16 +908,11 @@ local parser = P{
return true
elseif conversion(t.lastbullet) == conversion(bullet) then -- same type
local autoconv = conversion(bullet) == "auto"
- --local successor = helpers.list.successor(bullet, t.lastbullet)
local greater = helpers.list.greater (bullet, t.lastbullet)
t.lastbullet = bullet
- --return autoconv or successor or greater
return autoconv or successor or greater
end
- --return t.bullets[t.depth] == bullet
end),
- -- ^^^^^
- -- otherwise returns the value of V"bullet_indent", not sure why …
bullet_continue = Ct(C(V"bullet_cont") * V"bullet_itemrest")
/rst.bullet_item
@@ -927,10 +920,8 @@ local parser = P{
bullet_itemrest = C(V"bullet_rest" -- first line
* ((V"bullet_match" * V"bullet_rest")^0 -- any successive lines
- --* (V"eol"
* (V"blank_line"
* (V"bullet_match" * (V"bullet_rest" - V"bullet_indent"))^1)^0))
- --/ rst.bullet_item,
,
-- ^^^^^^^^^^^^^
-- otherwise matches bullet_first
@@ -940,7 +931,7 @@ local parser = P{
bullet_next = V"space"^1
,
- bullet_match = #Cmt(V"bullet_next", function (s, i, this)
+ bullet_match = Cmt(V"bullet_next", function (s, i, this)
local t = state
warn("match",
t.depth,
@@ -1076,9 +1067,10 @@ local parser = P{
--------------------------------------------------------------------------------
paragraph = Ct(V"par_first"
- * V"par_other"^0)
+ * V"par_other"^0) / rst.paragraph
* V"end_block"
- / rst.paragraph,
+ * V"reset_depth"
+ ,
par_first = V"par_setindent" * C((1 - V"literal_block_shorthand" - V"eol")^1) * V"eol",
@@ -1139,6 +1131,17 @@ local parser = P{
/ rst.included_literal_block
,
+ -- This is needed because lpeg.Cmt() patterns are evaluated even
+ -- if they are part of a larger pattern that doesn’t match. The
+ -- result is that they confuse the nesting.
+ -- Resetting the current nesting depth at every end of block
+ -- should be safe because this pattern always matches last.
+ reset_depth = Cmt(Cc("nothing") / "", function (s,i, something)
+ state.depth = 0
+ return true
+ end)
+ ,
+
--------------------------------------------------------------------------------
-- Comments
--------------------------------------------------------------------------------
@@ -1300,7 +1303,7 @@ local parser = P{
,
-- diverse markup character sets
- delimiters = P"‐" + P"‑" + P"‒" + P"–" + V"emdash" + V"space", -- inline markup
+ delimiters = P"‐" + P"‑" + P"‒" + P"–" + V"emdash" + V"space", -- inline markup
adornment_char = S[[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]] + P[[\\]], -- headings
bullet_char = S"*+-" + P"•" + P"‣" + P"⁃", -- bullet lists
argument_char = V"double_dash" * V"dash" * V"slash", -- option lists
@@ -1357,6 +1360,7 @@ local function get_setups ()
\sethyphenatedurlafter {:=/-}
\doifundefined{startparagraph}{% -->mkii
+ \enableregime[utf]
\let\startparagraph\relax
\let\stopparagraph\endgraf
}