summaryrefslogtreecommitdiff
path: root/rst_context.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-12 22:06:53 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-12 22:06:53 +0200
commit311fc80cac4b39f772e7b75176fce455d33a6630 (patch)
tree50623757a23318b8b4a141f6d03272c8a413b1e2 /rst_context.lua
parent77fcc38a9a906d6a44ab2eac971714bba1970115 (diff)
downloadcontext-rst-311fc80cac4b39f772e7b75176fce455d33a6630.tar.gz
handling of escaped spaces in string.strip
Diffstat (limited to 'rst_context.lua')
-rw-r--r--rst_context.lua29
1 files changed, 19 insertions, 10 deletions
diff --git a/rst_context.lua b/rst_context.lua
index 1f49bff..96e7f89 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -25,12 +25,14 @@ local dbg_write = help.dbg_writef
local C, Cb, Cc, Cg, Cmt, Cp, Cs, Ct, P, R, S, V, match = lpeg.C, lpeg.Cb, lpeg.Cc, lpeg.Cg, lpeg.Cmt, lpeg.Cp, lpeg.Cs, lpeg.Ct, lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.match
-if not context then -- standard context lpeg stripper from l-string.lua
+-- This one should ignore escaped spaces.
+do
local stripper = P{
[1] = "stripper",
- stripper = V"space"^0 * C((V"space"^0 * V"nospace"^1)^0),
+ stripper = V"space"^0 * C((V"space"^0 * (V"escaped" + V"nospace")^1)^0),
space = S(" \t\v\n"),
nospace = 1 - V"space",
+ escaped = P"\\" * V"space"
}
function string.strip(str)
return stripper:match(str) or ""
@@ -359,12 +361,17 @@ function rst_context.bullet_marker(str)
return "marker"
end
+-- This one should ignore escaped spaces.
do
- local space = lpeg.S(" \t\v\n")
- local nospace = 1 - space
- local stripper = space^0 * lpeg.C((space^0 * nospace^1)^0)
+ local stripper = P{
+ [1] = "stripper",
+ stripper = V"space"^0 * C((V"space"^0 * V"nospace"^1)^0),
+ space = S(" \t\v\n"),
+ escaped = P"\\" * V"space",
+ nospace = V"escaped" + (1 - V"space"),
+ }
function string.strip(str)
- return match(stripper,str) or ""
+ return stripper:match(str) or ""
end
end
@@ -745,10 +752,11 @@ function rst_context.simple_table(tab)
head = head .. [[\\bTR]]
for nc,cell in ipairs(row) do
dbg_write("%7s | ", cell.content)
+ local celltext = inline_parser:match(cell.content)
if cell.span then
- head = head .. string.format([=[\\bTH[nc=%s]%s\\eTH]=], cell.span.x, cell.content)
+ head = head .. string.format([=[\\bTH[nc=%s]%s\\eTH]=], cell.span.x, celltext)
else
- head = head .. [[\\bTH ]] .. cell.content .. [[\\eTH]]
+ head = head .. [[\\bTH ]] .. celltext .. [[\\eTH]]
end
end
dbg_write("\n")
@@ -784,10 +792,11 @@ function rst_context.simple_table(tab)
body = body .. [[\\bTR]]
for nc,cell in ipairs(row) do
dbg_write("%7s | ", cell.content)
+ local celltext = inline_parser:match(cell.content)
if cell.span then
- body = body .. string.format([=[\\bTC[nc=%s]%s\\eTC]=], cell.span.x, cell.content)
+ body = body .. string.format([=[\\bTC[nc=%s]%s\\eTC]=], cell.span.x, celltext)
else
- body = body .. [[\\bTC ]] .. cell.content .. [[\\eTC]]
+ body = body .. [[\\bTC ]] .. celltext .. [[\\eTC]]
end
end
dbg_write("\n")