* lua filter, convert Para into RawBlock @ 2018-06-06 17:03 Agustín Martín [not found] ` <e32ff546-810b-4df6-a96e-71b07b753397-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 3+ messages in thread From: Agustín Martín @ 2018-06-06 17:03 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 2315 bytes --] Hi, I'm new to lua, so forgive me if this is something basic. I'm trying to create a filter to convert the text "{{pagebreak}}" into a docx page break. I know there are existing haskel filters for this, and that I could also use a raw block directly in my docx (I've done that already) but I wanted to scratch my itch and do it with a lua filter. So far trying different approaches I have ended up with: -- file: macro-expander.lua function pagebreak_to_docx (inlines) if #inlines ~= 1 then return end if inlines[1].t == 'Str' and inlines[1].text == "{{pagebreak}}" then return pandoc.RawBlock{"openxml", "<w:p><w:r><w:br w:type=\"page\" /></w:r></w:p>"} end end function Para (c) return pagebreak_to_docx(c.content) end Still when I run it with a basic example, I get the following error: Could not read list: Could not get Block value: Expected a string but got a nil Right at the exact place where the {{pagebreak}} occurs. Without the filter: $ echo -e "Raw Block in md: \n\n\`\`\`{=openxml}\n<w:p>\n\`\`\` \n\nLua Filter Test: \n\n{{pagebreak}}" | pandoc -f markdown -t native [Para [Str "Raw",Space,Str "Block",Space,Str "in",Space,Str "md:"] ,RawBlock (Format "openxml") "<w:p>" ,Para [Str "Lua",Space,Str "Filter",Space,Str "Test:"] ,Para [Str "{{pagebreak}}"]] With the filter I'd expect the last Para to turn into a RawBlock but... $ echo -e "Raw Block in md: \n\n\`\`\`{=openxml}\n<w:p>\n\`\`\` \n\nLua Filter Test: \n\n{{pagebreak}}" | pandoc -f markdown -t native --lua-filter="./macro-expander.lua" Error running filter ./src/servicio-gestion-software/macro-expander.lua: Could not read list: Could not get Block value: Expected a string but got a nil Any help would be appreciated. Thanks! -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e32ff546-810b-4df6-a96e-71b07b753397%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. [-- Attachment #1.2: Type: text/html, Size: 5895 bytes --] ^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <e32ff546-810b-4df6-a96e-71b07b753397-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: lua filter, convert Para into RawBlock [not found] ` <e32ff546-810b-4df6-a96e-71b07b753397-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2018-06-06 22:00 ` John MacFarlane [not found] ` <yh480k7enbh8y6.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org> 0 siblings, 1 reply; 3+ messages in thread From: John MacFarlane @ 2018-06-06 22:00 UTC (permalink / raw) To: Agustín Martín, pandoc-discuss Almost there! pandoc.RawBlock is a function that takes two arguments (not a table), so you should have () rather than {} after it. Agustín Martín <agusmba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > Hi, I'm new to lua, so forgive me if this is something basic. > > I'm trying to create a filter to convert the text "{{pagebreak}}" into a > docx page break. I know there are existing haskel filters for this, and > that I could also use a raw block directly in my docx (I've done that > already) but I wanted to scratch my itch and do it with a lua filter. > > So far trying different approaches I have ended up with: > > -- file: macro-expander.lua > > function pagebreak_to_docx (inlines) > > if #inlines ~= 1 then return end > if inlines[1].t == 'Str' and inlines[1].text == "{{pagebreak}}" then > return pandoc.RawBlock{"openxml", "<w:p><w:r><w:br w:type=\"page\" > /></w:r></w:p>"} > end > end > > function Para (c) > return pagebreak_to_docx(c.content) > end > > Still when I run it with a basic example, I get the following error: > > Could not read list: Could not get Block value: Expected a string but got a > nil > > Right at the exact place where the {{pagebreak}} occurs. > > Without the filter: > > $ echo -e "Raw Block in md: \n\n\`\`\`{=openxml}\n<w:p>\n\`\`\` \n\nLua > Filter Test: \n\n{{pagebreak}}" | pandoc -f markdown -t native > [Para [Str "Raw",Space,Str "Block",Space,Str "in",Space,Str "md:"] > ,RawBlock (Format "openxml") "<w:p>" > ,Para [Str "Lua",Space,Str "Filter",Space,Str "Test:"] > ,Para [Str "{{pagebreak}}"]] > > With the filter I'd expect the last Para to turn into a RawBlock but... > > $ echo -e "Raw Block in md: \n\n\`\`\`{=openxml}\n<w:p>\n\`\`\` \n\nLua > Filter Test: \n\n{{pagebreak}}" | pandoc -f markdown -t native > --lua-filter="./macro-expander.lua" > > Error running filter ./src/servicio-gestion-software/macro-expander.lua: > Could not read list: Could not get Block value: Expected a string but got a > nil > > > Any help would be appreciated. > Thanks! > > -- > You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e32ff546-810b-4df6-a96e-71b07b753397%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/yh480k7enbh8y6.fsf%40johnmacfarlane.net. For more options, visit https://groups.google.com/d/optout. ^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <yh480k7enbh8y6.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>]
* Re: lua filter, convert Para into RawBlock [not found] ` <yh480k7enbh8y6.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org> @ 2018-06-07 7:06 ` Agustín Martín 0 siblings, 0 replies; 3+ messages in thread From: Agustín Martín @ 2018-06-07 7:06 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 814 bytes --] Indeed! Thank you John!! On Thursday, June 7, 2018 at 12:00:33 AM UTC+2, John MacFarlane wrote: > > > Almost there! pandoc.RawBlock is a function that takes two > arguments (not a table), so you should have () rather than {} after it. > -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/242addf6-b7ee-4b2a-a2d7-8b3df10d8584%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. [-- Attachment #1.2: Type: text/html, Size: 1390 bytes --] ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-06-07 7:06 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-06-06 17:03 lua filter, convert Para into RawBlock Agustín Martín [not found] ` <e32ff546-810b-4df6-a96e-71b07b753397-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2018-06-06 22:00 ` John MacFarlane [not found] ` <yh480k7enbh8y6.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org> 2018-06-07 7:06 ` Agustín Martín
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).