pandoc-odt-filters
pandoc-odt-filters copied to clipboard
You can use a table as the replacement argument of string.gsub
I saw that here you are using a replacement function to just look up a value in a table. The function is unnecessary since if you pass a table with string keys and values as the replacement argument to string.gsub Lua will automatically use the first capture (or the whole match if there was no capture) as a key to look up in the table and use the value of that key as replacement, so you can replace that with
text = string.gsub(text, escPattern, escapes)
and it will have the exact same effect, except that since no extra Lua function is created and called every time it is much more efficient. (You will still need a function if you want to look up another capture than the first one of course!)