From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/20317 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?Q?Agust=C3=ADn_Mart=C3=ADn?= Newsgroups: gmane.text.pandoc Subject: lua filter, convert Para into RawBlock Date: Wed, 6 Jun 2018 10:03:36 -0700 (PDT) Message-ID: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_34915_1736985554.1528304616885" X-Trace: blaine.gmane.org 1528304495 21352 195.159.176.226 (6 Jun 2018 17:01:35 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 6 Jun 2018 17:01:35 +0000 (UTC) To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDC7PRMFWYJBB2NH4DMAKGQEQMTY5GI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Jun 06 19:01:30 2018 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane.org Original-Received: from mail-ot0-f190.google.com ([74.125.82.190]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fQboN-0005Ms-9m for gtp-pandoc-discuss@m.gmane.org; Wed, 06 Jun 2018 19:01:27 +0200 Original-Received: by mail-ot0-f190.google.com with SMTP id z25-v6sf1229694otk.3 for ; Wed, 06 Jun 2018 10:03:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:date:from:to:message-id:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=YXceN/4brmgL9rgo/6OX7aZb4EovmTm0qBznUdcEukQ=; b=iRkgwW2seIxhAgkh2DvtmjzMYsPwfbYXZi4WC+5GUZMpLF3eBlc5tCd5KqZTahK4aX 9HfVQOETuDgsyTqNJx9gysD2kmXeHb1YzZv5iYvvOrA/QgAsuXC6mgxG9yAYNK02Lqj5 Ck0ivxEYrInH53DmniJhW05HmcH+geZmP1372bfNP3FZGEa3QTeKmJa7VodoFXySFryZ +bdJQ+5fABp5aWcoWnNIY+xFRc2F720NdouW31t937gu1e1wKI1SANlofeqw74Bh1o// Pc+u+Mo1QcAVb6BUnqAHfnB/EKKA1g1fc1CumaHZ1dgPVEGMYnHpDNoU5gWattp4BNhP Lkqw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:message-id:subject:mime-version:x-original-sender :reply-to:precedence:mailing-list:list-id:list-post:list-help :list-archive:list-subscribe:list-unsubscribe; bh=YXceN/4brmgL9rgo/6OX7aZb4EovmTm0qBznUdcEukQ=; b=l0GQUn6lepTEJD+5PEjy3VbkWZChuHx1CYEpUs1uyAHdXIpAJrWThZnw5diOLzm5Pf qXfCTIB7Q2WfHZ1oNzplL+j7sdAYjpHcVaONACWVgSMsULhFEyaEJyaBXJpB1tN8KMwD yYrfhDQzt4iaJ4I4cukWdFXG9EdgbEXD5ho/FO2z16yZ2JOgEaIO4zgCvjspRlqHPY8t +rjt7lOYt0YYoxbbr8rEXoqYm4MCO7QG/NroYc9DGc7GydqEW/zIjNqah73suZu0BbRC q1RpxKLPcHrirlVitdolBja7bHPcwvnHv6GIDPVrjWLJVgzALy6E6Lc98vlNz+V2KHW9 gsAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:date:from:to:message-id:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=YXceN/4brmgL9rgo/6OX7aZb4EovmTm0qBznUdcEukQ=; b=ZFEO3Pj3ExImU/+2/jOTG+zdrsAsSKQwwz8k3lg5JqpadLcrfM8GAQfGPPNdbUbvg0 Od3krWnAz3wfjxLYbA4XA45EfaDsmZBtfdfI8IR7pAABIMLSZlt1msOVFNUJtyvrDvWk JpdlKxoRah3FGyvGe0HyTkvGDLL0DLptfxuOfmykfz+VlBSAOi+uUOvXxHEbT/HgyKjS ChUpkRYjaYfQmUWH4muTUbdTcoG7PXD4YGh4pq5OLUWs7JZzmFiyCXvWx5iFPJ5jVSBy nOivK6lpWl8iuerX/znwIzz+cEfgc1go37QpECKcPm6bI3ev1zRumFp8BV4szlC8ohzZ BHSg== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: APt69E1H5cEEnVEbpUL5qtx1uxm1la4F7ufCYE6tWiUFpXpU/MDvCFsQ NeYmr5Bl+fJNC6vmVCY+ojc= X-Google-Smtp-Source: ADUXVKL6IVOBFFHtwU96HBcqRw826nvyuRKe8RR1eChE4GxfmG+m+M/utFDJwGsLCTZTAbj3v+Tmpg== X-Received: by 2002:a9d:5788:: with SMTP id q8-v6mr146694oth.3.1528304618372; Wed, 06 Jun 2018 10:03:38 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a9d:7313:: with SMTP id e19-v6ls2272947otk.20.gmail; Wed, 06 Jun 2018 10:03:37 -0700 (PDT) X-Received: by 2002:a9d:5608:: with SMTP id e8-v6mr145077oti.5.1528304617443; Wed, 06 Jun 2018 10:03:37 -0700 (PDT) X-Original-Sender: agusmba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Spam-Checked-In-Group: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.org gmane.text.pandoc:20317 Archived-At: ------=_Part_34915_1736985554.1528304616885 Content-Type: multipart/alternative; boundary="----=_Part_34916_244281912.1528304616885" ------=_Part_34916_244281912.1528304616885 Content-Type: text/plain; charset="UTF-8" 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", ""} 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\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") "" ,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\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. ------=_Part_34916_244281912.1528304616885 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
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 ex= isting haskel filters for this, and that I could also use a raw block direc= tly 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 differ= ent approaches I have ended up with:

-- file: ma= cro-expander.lua

function pagebreak_= to_docx (inlines)<= br>

=C2=A0 if #inlines= ~=3D 1 then return end
=C2=A0if inlines[1].t =3D=3D 'Str' and inlines[1].text =3D=3D "{{pagebreak}}" then
=C2=A0 =C2=A0return pandoc.RawBlock{"openxm= l", "<w:p>= ;<w:r><w:br w:type=3D\"page\"/></w:r></w:p>"}
=C2=A0end
end

= =C2=A0 function Para (c)
=C2=A0 =C2=A0return pagebreak_to_docx(c.content)
=C2=A0end

Still when I run it with a basic example, I get the fo= llowing error:=C2=A0

Could not read list: Could no= t 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\`\`\`{=3Dopenxml= }\n<w:p>\n\`\`\` \n\nLua Filter Test: \n\n{{pagebreak}}" | pando= c -f markdown -t native
[Para [Str "= ;Raw",Space,Str "Block",Space,Str "in",Space,Str &= quot;md:"]
,RawBlock (Format "= openxml") "<w:p>"
,= Para [Str "Lua",Space,Str "Filter",Space,Str "Test= :"]
,Para [Str "{{pagebreak}}&= quot;]]

With the filter I'd expect the= last Para to turn into a RawBlock but...

$ echo -e "Raw Block in md: \n\n\`\`\`{=3Do= penxml}\n<w:p>\n\`\`\` \n\nLua Filter Test: \n\n{{pagebreak}}" |= pandoc -f markdown -t native --lua-filter=3D"./macro-expander.lua"
<= div class=3D"subprettyprint">
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 &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@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.co= m.
For more options, visit http= s://groups.google.com/d/optout.
------=_Part_34916_244281912.1528304616885-- ------=_Part_34915_1736985554.1528304616885--