diff options
-rw-r--r-- | rst_context.lua | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/rst_context.lua b/rst_context.lua index 528ecdf..3bcbbc5 100644 --- a/rst_context.lua +++ b/rst_context.lua @@ -392,9 +392,23 @@ function rst_context.option_item (tab) end function rst_context.literal_block (str) - local stop = P"\n"^0 * -P(1) -- remove trailing blank lines - local rstrip = C((1 - stop)^1) * stop - str = rstrip:match(str) + local indent = P" "^1 + local stripme = indent:match(str) - 1 + + local strip = P{ + [1] = "strip", + strip = Cs(V"line"^1), + eol = P"\n", + restofline = (1 - V"eol")^0, + stop = Cs(V"eol" * P" "^0) * -P(1) / "", -- remove trailing blank lines + line = Cs(V"restofline" * (V"stop" + V"eol")) / function (line) + return #line > stripme and line:sub(stripme) or line + end, + } + + str = strip:match(str) + --strip:print() -- grammar consists of 45 rules only; wheras a plain + -- pattern has 60+ return [[ \\starttyping[lines=hyphenated] |