summaryrefslogtreecommitdiff
path: root/mod/tex/context
diff options
context:
space:
mode:
Diffstat (limited to 'mod/tex/context')
-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)