summaryrefslogtreecommitdiff
path: root/mod
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2011-05-04 15:48:19 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2011-05-04 15:48:19 +0200
commit4dc6e76f8cbd29c762d93b05a8b32541a16890da (patch)
tree9e0b4ad641eef6661b0b1ac210693b482759e036 /mod
parent55d22cc0ee03192a8f1a6642f546644048f24da3 (diff)
downloadcontext-rst-4dc6e76f8cbd29c762d93b05a8b32541a16890da.tar.gz
improved (“typ[e|ing]”-safe) escaper
Diffstat (limited to 'mod')
-rw-r--r--mod/tex/context/third/rst/rst_context.lua37
1 files changed, 26 insertions, 11 deletions
diff --git a/mod/tex/context/third/rst/rst_context.lua b/mod/tex/context/third/rst/rst_context.lua
index 8663039..846b507 100644
--- a/mod/tex/context/third/rst/rst_context.lua
+++ b/mod/tex/context/third/rst/rst_context.lua
@@ -325,18 +325,33 @@ function rst_context.substitution_reference (str, underscores)
return sub .. [[{\\RSTsubstitution]] .. str:gsub("%s", "") .. "}"
end
--- see catc-sym.tex
-local escape_me = {
- ["&"] = [[\letterampersand ]],
- ["$"] = [[\letterdollar ]],
- ["#"] = [[\letterhash ]],
- ["^"] = [[\letterhat ]],
- ["_"] = [[\letterunderscore ]],
-}
+do
+ -- see catc-sym.tex
+ local escape_me = {
+ ["&"] = [[\letterampersand ]],
+ ["$"] = [[\letterdollar ]],
+ ["#"] = [[\letterhash ]],
+ ["^"] = [[\letterhat ]],
+ ["_"] = [[\letterunderscore ]],
+ }
+
+ local chars
+ for chr, repl in next, escape_me do
+ chars = chars and chars + (P(chr) / repl) or P(chr) / repl
+ end
+
+ local p_escape = P{
+ [1] = Cs((V"skip" + chars + 1)^1),
+ skip1 = P"\\starttyping" * (1 - P"\\stoptyping")^1,
+ balanced = P"{" * (V"balanced" + (1 - P"}"))^0 * P"}",
+ skip2 = P"\\type" * V"balanced",
+ skip = V"skip1" + V"skip2",
+ }
-function rst_context.escape (str)
- str = str:gsub("\\(.)", "%1") -- literalize escaped sequences
- return str:gsub("[&#^_$]", escape_me) -- escape chars with special meaning
+ function rst_context.escape (str)
+ str = str:gsub("\\(.)", "%1")
+ return p_escape:match(str)
+ end
end
function rst_context.joinindented (tab)