diff options
-rw-r--r-- | rst_context.lua | 17 | ||||
-rw-r--r-- | rst_helpers.lua | 2 | ||||
-rw-r--r-- | rst_parser.lua | 34 |
3 files changed, 32 insertions, 21 deletions
diff --git a/rst_context.lua b/rst_context.lua index 9010bb8..00a8881 100644 --- a/rst_context.lua +++ b/rst_context.lua @@ -479,7 +479,8 @@ function rst_context.paragraph (data) if not data then return "" elseif type(data) == "table" then - str = #data > 1 and helpers.string.wrapat(inline_parser:match(table.concat(data, " ")), 65) or inline_parser:match(data[1]) + str = #data > 1 and helpers.string.wrapat(inline_parser:match(table.concat(data, " ")), 65) + or inline_parser:match(data[1]) else str = data end @@ -1144,6 +1145,8 @@ end function optional_setups.references () local refs = rst_context.collected_references local crefs = rst_context.context_references + local arefs = rst_context.anonymous_set + local function resolve_indirect (r) if r and r:match(".*_$") then -- pointing elsewhere local look_me_up = r:match("^`?([^`]*)`?_$") @@ -1169,7 +1172,6 @@ function optional_setups.references () ]] local references = {} local ref_keys = {} - local arefs = rst_context.anonymous_set for ref, target in next, refs do ref_keys[#ref_keys+1] = [[__target_]] .. rst_context.whitespace_to_underscore(ref) target = resolve_indirect(target) @@ -1590,13 +1592,18 @@ function optional_setups.caution () \usemodule[lettrine] -\setbox0=\hbox{\symbol[dbend]\hbox to 1em{}} +\setbox0=\hbox{\symbol[dbend]} \newskip\RSTbendskip \RSTbendskip=\wd0 +\advance\RSTbendskip by 1em % These two lines should add +\advance\RSTbendskip by 1pt % 13.4pt in mkiv and 13.14983pt in mkii + % to make the indent equal to the indent + % of the “danger” directive. + % (2*(width)dbend + (kern)1pt + 1em \def\startRSTcaution{% \startparagraph -\dontleavehmode\lettrine[Lines=2,Raise=.5,Findent=\RSTbendskip,Nindent=0pt]{\symbol[dbend]}{}% +\dontleavehmode\lettrine[Lines=2,Raise=.6,Findent=\RSTbendskip,Nindent=0pt]{\symbol[dbend]}{}% } \let\stopRSTcaution\stopparagraph @@ -1619,7 +1626,7 @@ function optional_setups.danger () \def\startRSTdanger{% \startparagraph -\lettrine[Lines=2,Raise=.5,Findent=1em,Nindent=0pt]{\symbol[dbend]\kern 1pt\symbol[dbend]}{}% +\lettrine[Lines=2,Raise=.6,Findent=1em,Nindent=0pt]{\symbol[dbend]\kern 1pt\symbol[dbend]}{}% } \let\stopRSTdanger\stopparagraph diff --git a/rst_helpers.lua b/rst_helpers.lua index d70e247..ade8b23 100644 --- a/rst_helpers.lua +++ b/rst_helpers.lua @@ -462,7 +462,7 @@ do max_three = { curr } end - curr = rnums[str:sub(n,n)] + curr = rnums[str:sub(n,n)] or 1 n = n + 1 succ = str:sub(n,n) 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 } |