summaryrefslogtreecommitdiff
path: root/rst_context.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-04 14:38:08 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-04 14:38:08 +0200
commit8de852e3bb1c965fe3caf4be344067fcee737899 (patch)
tree7b5dbea9dfebbf2f67b0b79dc25cc8321af986eb /rst_context.lua
parentd64ebfaca1adf349d7d0bd29c2dde84422ba3025 (diff)
downloadcontext-rst-8de852e3bb1c965fe3caf4be344067fcee737899.tar.gz
literal blocks formatting and indent handling
Diffstat (limited to 'rst_context.lua')
-rw-r--r--rst_context.lua20
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]