From 8de852e3bb1c965fe3caf4be344067fcee737899 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 4 Sep 2010 14:38:08 +0200 Subject: literal blocks formatting and indent handling --- rst_context.lua | 20 +++++++++++++++++--- 1 file 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] -- cgit v1.2.3