Reputation: 39
I am beginner in Pandoc and Lua who is experimenting with converting Word documents to Markdown. I want to convert chapter headings in Word to paragraph of text in Markdown. Furthermore, I want to insert some text before and after the chapter headings.
To achieve that, I used the following lua filter (sample.lua)
function Header(el)
if el.level == 1 then
return {"something before (",el.content,") something after"}
end
end
after which I performed the conversion using
pandoc --lua-filter=sample.lua -s file.docx -t markdown -o file.txt
where file.docx is just minimal example document containing one chapter heading. However, using this filter, I obtained
something before (
Chapter title
) something after
What I want to get, however, is
something before (Chapter title) something after
but since (if I am not mistaken) el.content is inline element, there are linebreaks around it. I tried to solve this problem by using pandoc documentation and various lua functions, but to no avail, which is why I would kindly ask for help.
Upvotes: 1
Views: 838
Reputation: 22609
Try this instead:
function Header(el)
if el.level == 1 then
return {{"something before ("} .. el.content .. {") something after"}}
end
end
The reason is that el.content
is a list of inline elements, and it can be be extended by concatenating lists with additional content. The operator ..
is the concatenation operator; it works with strings and pandoc lists.
Upvotes: 2