public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org>
To: "Agustín Martín"
	<agusmba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	pandoc-discuss
	<pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: lua filter, convert Para into RawBlock
Date: Wed, 06 Jun 2018 15:00:17 -0700	[thread overview]
Message-ID: <yh480k7enbh8y6.fsf@johnmacfarlane.net> (raw)
In-Reply-To: <e32ff546-810b-4df6-a96e-71b07b753397-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>


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.


  parent reply	other threads:[~2018-06-06 22:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-06 17:03 Agustín Martín
     [not found] ` <e32ff546-810b-4df6-a96e-71b07b753397-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2018-06-06 22:00   ` John MacFarlane [this message]
     [not found]     ` <yh480k7enbh8y6.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2018-06-07  7:06       ` Agustín Martín

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=yh480k7enbh8y6.fsf@johnmacfarlane.net \
    --to=jgm-tvlzxgkolnx2fbvcvol8/a@public.gmane.org \
    --cc=agusmba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).