I have a Markdown document containing raw LaTeX commands. I am trying to use a Lua filter with Pandoc (2.0.1.1) to convert the LaTeX commands into something more portable. In particular, commands that specify the language of text should be converted into spans with a lang attribute. The problem is that I don't know how to pass the attributes to the pandoc.Span constructor. This is my attempt at a filter (filter.lua):
function RawInline(elem)
if elem.format == "tex" then
text = string.match(elem.text, "\\textspanish{(.+)}")
if text then
contents = {pandoc.Str(text)}
attrs = pandoc.Attr("",{},{lang = "es-SP"})
return pandoc.Span(contents, attrs)
end
else
return elem
end
end
Sample usage:
echo '\textspanish{hola}' | pandoc -f markdown -t native --lua-filter=filter.lua
The output is [Para [Span ("",[],[]) [Str "hola"]]], with no attributes on the span.
If I pass a name and/or class to pandoc.Attr, these come through, e.g., attrs = pandoc.Attr("name",{"class"},{lang = "es-SP"}) produces [Para [Span ("name",["class"],[]) [Str "hola"]]]. But attributes I pass to the constructor never appear in the output. What is the right way to pass attributes to pandoc.Attr?