Skip to content

Instantly share code, notes, and snippets.

@niklaskorz
Created December 1, 2018 11:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niklaskorz/c9d55b157078dd1e1f5badad15093a72 to your computer and use it in GitHub Desktop.
Save niklaskorz/c9d55b157078dd1e1f5badad15093a72 to your computer and use it in GitHub Desktop.
Pandoc filter for replacing quotation marks
local double_quotes = {"»", "«"}
local single_quotes = {"›", "‹"}
function get_preferences(m)
if m.double_quotes and m.double_quotes[1] and m.double_quotes[2] then
double_quotes = { m.double_quotes[1][1].c, m.double_quotes[2][1].c }
end
if m.single_quotes and m.single_quotes[1] and m.single_quotes[2] then
single_quotes = { m.single_quotes[1][1].c, m.single_quotes[2][1].c }
end
end
function replace_quotes(elem)
local quotes = double_quotes
if elem.quotetype == "SingleQuote" then
quotes = single_quotes
end
return {pandoc.Str(quotes[1])} .. elem.content .. {pandoc.Str(quotes[2])}
end
return {
{ Meta = get_preferences },
{ Quoted = replace_quotes },
}
@nobohan
Copy link

nobohan commented May 28, 2020

Cool, exactly what I was looking for!

But I don't understand why the quotes are "inverted": I had to modify like this:

return {pandoc.Str(quotes[2])} .. elem.content .. {pandoc.Str(quotes[1])} 

Or am I missing smthg?

@niklaskorz
Copy link
Author

Some languages use guillemets pointing inwards (German) instead of outwards (French). I wrote this for a German text, so it's using inwards pointing guillemets.

@nobohan
Copy link

nobohan commented May 28, 2020

OK good to know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment