From 311fc80cac4b39f772e7b75176fce455d33a6630 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 12 Sep 2010 22:06:53 +0200 Subject: handling of escaped spaces in string.strip --- rst_context.lua | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'rst_context.lua') 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") -- cgit v1.2.3