public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Pulling blocks out of body and into metadata (a là abstract-to-meta lua filter)
@ 2020-12-20 15:40 Randy Josleyn
       [not found] ` <CAPYN8sNuV_TirDuM7RrVoKfEsvSSaTokykDV6Sx0HT+XHKAsBA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Randy Josleyn @ 2020-12-20 15:40 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 3472 bytes --]

Hi list members,

My first post here! (Let me know if there are any guidelines I should
follow when posting in the future!)

I want to extract sections in a document by the method shown in the
pandoc/luafilters/abstract-to-meta
<https://github.com/pandoc/lua-filters/blob/master/abstract-to-meta/abstract-to-meta.lua>
 filter, but I want to extract more than one section and put them in their
corresponding variables as denoted by the identifier of the section heading.

My goal is to take the sections and stick them in the metadata so I can
reference the metadata as variables in a custom bootstrap HTML template and
put them in cards in different places on the page. (The final output is
PDF. It’s a sort of feedback form for students.)

I was able to successfully remove the appropriate sections from the body of
the document, but it seems the content isn’t being stored in the metadata
because the corresponding variables produce no output in the PDF. If I
manually assign the variables in the YAML metadata, then they show up in
the output as expected.

I searched the group history for mentions of the abstract-to-meta filter
and found a couple, but I wasn’t successful in applying them to my use
case. Here’s the filter I’ve been able to come up with:

local sections = { 'comments', 'pronunciation', 'vocabulary' } --
remove these sectionslocal blocks = {}blocks['therest'] = {} -- all
the other stuff-- check if a value is in the tablelocal function
has_value(tab, val)    for index, value in ipairs(tab) do        if
value == val then            return true        end    end    return
falseend-- get teacher's comments, etc from list of blocksfunction
get_blocks (bodyblocks)    for _, e in ipairs(bodyblocks) do        if
e.t == 'Header' and e.level == 1 then            if
has_value(sections, e.identifier) then                section =
e.identifier                looking_at_section = true
blocks[section] = {}                lvl = e.level            else
          looking_at_section = false
blocks['therest'][#blocks['therest'] + 1] = e            end
elseif looking_at_section then
blocks[section][#blocks[section] + 1] = e        else
blocks['therest'][#blocks['therest'] + 1] = e        end    end
return blocks['therest']endreturn {{    Blocks = get_blocks,    Meta =
function (m)        for _, section in ipairs(sections) do
if not m.section and #blocks[section] > 0 then
m.section = pandoc.MetaBlocks(blocks[section])            end
end    end}}

The blocks are successfully being removed from the body, but they’re not
being placed into metadata. I guess there may be two reasons for this:

   - some sort of scope problem with blocks[], causing it to be undefined
   when used in the Meta function
   - my lack of understanding of Lua or how to correctly assign to Pandoc
   variables

Can anyone point me in the right direction as to how to get those body
blocks into their respective metadata variables?

Thank you all for your time!

Randy

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAPYN8sNuV_TirDuM7RrVoKfEsvSSaTokykDV6Sx0HT%2BXHKAsBA%40mail.gmail.com.

[-- Attachment #2: Type: text/html, Size: 24535 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Pulling blocks out of body and into metadata (a là abstract-to-meta lua filter)
       [not found] ` <CAPYN8sNuV_TirDuM7RrVoKfEsvSSaTokykDV6Sx0HT+XHKAsBA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2020-12-21 20:53   ` BPJ
       [not found]     ` <CADAJKhBjtkcnau7MEdMsF7YwHco0ipwre5sw-SRhPvOSOhf56w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: BPJ @ 2020-12-21 20:53 UTC (permalink / raw)
  To: pandoc-discuss

[-- Attachment #1: Type: text/plain, Size: 4524 bytes --]

You probably need to put each block in a MetaBlocks element
`pandoc.MetaBlocks{block}` and then put the MetaBlocks in the metadata.

-- 
Better --help|less than helpless

Den sön 20 dec. 2020 16:41Randy Josleyn <randy.josleyn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:

> Hi list members,
>
> My first post here! (Let me know if there are any guidelines I should
> follow when posting in the future!)
>
> I want to extract sections in a document by the method shown in the
> pandoc/luafilters/abstract-to-meta
> <https://github.com/pandoc/lua-filters/blob/master/abstract-to-meta/abstract-to-meta.lua>
>  filter, but I want to extract more than one section and put them in
> their corresponding variables as denoted by the identifier of the section
> heading.
>
> My goal is to take the sections and stick them in the metadata so I can
> reference the metadata as variables in a custom bootstrap HTML template and
> put them in cards in different places on the page. (The final output is
> PDF. It’s a sort of feedback form for students.)
>
> I was able to successfully remove the appropriate sections from the body
> of the document, but it seems the content isn’t being stored in the
> metadata because the corresponding variables produce no output in the PDF.
> If I manually assign the variables in the YAML metadata, then they show up
> in the output as expected.
>
> I searched the group history for mentions of the abstract-to-meta filter
> and found a couple, but I wasn’t successful in applying them to my use
> case. Here’s the filter I’ve been able to come up with:
>
> local sections = { 'comments', 'pronunciation', 'vocabulary' } -- remove these sectionslocal blocks = {}blocks['therest'] = {} -- all the other stuff-- check if a value is in the tablelocal function has_value(tab, val)    for index, value in ipairs(tab) do        if value == val then            return true        end    end    return falseend-- get teacher's comments, etc from list of blocksfunction get_blocks (bodyblocks)    for _, e in ipairs(bodyblocks) do        if e.t == 'Header' and e.level == 1 then            if has_value(sections, e.identifier) then                section = e.identifier                looking_at_section = true                blocks[section] = {}                lvl = e.level            else                looking_at_section = false                blocks['therest'][#blocks['therest'] + 1] = e            end        elseif looking_at_section then            blocks[section][#blocks[section] + 1] = e        else            blocks['therest'][#blocks['therest'] + 1] = e        end    end    return blocks['therest']endreturn {{    Blocks = get_blocks,    Meta = function (m)        for _, section in ipairs(sections) do            if not m.section and #blocks[section] > 0 then                m.section = pandoc.MetaBlocks(blocks[section])            end        end    end}}
>
> The blocks are successfully being removed from the body, but they’re not
> being placed into metadata. I guess there may be two reasons for this:
>
>    - some sort of scope problem with blocks[], causing it to be undefined
>    when used in the Meta function
>    - my lack of understanding of Lua or how to correctly assign to Pandoc
>    variables
>
> Can anyone point me in the right direction as to how to get those body
> blocks into their respective metadata variables?
>
> Thank you all for your time!
>
> Randy
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/CAPYN8sNuV_TirDuM7RrVoKfEsvSSaTokykDV6Sx0HT%2BXHKAsBA%40mail.gmail.com
> <https://groups.google.com/d/msgid/pandoc-discuss/CAPYN8sNuV_TirDuM7RrVoKfEsvSSaTokykDV6Sx0HT%2BXHKAsBA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhBjtkcnau7MEdMsF7YwHco0ipwre5sw-SRhPvOSOhf56w%40mail.gmail.com.

[-- Attachment #2: Type: text/html, Size: 24342 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Pulling blocks out of body and into metadata (a là abstract-to-meta lua filter)
       [not found]     ` <CADAJKhBjtkcnau7MEdMsF7YwHco0ipwre5sw-SRhPvOSOhf56w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2020-12-22  1:20       ` Randy Josleyn
  0 siblings, 0 replies; 3+ messages in thread
From: Randy Josleyn @ 2020-12-22  1:20 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw, BPJ

On December 22, 2020 4:53:04 AM GMT+08:00, BPJ <melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>You probably need to put each block in a MetaBlocks element
>`pandoc.MetaBlocks{block}` and then put the MetaBlocks in the metadata.

Thanks! I will take a look at that.

- Randy


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-22  1:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-20 15:40 Pulling blocks out of body and into metadata (a là abstract-to-meta lua filter) Randy Josleyn
     [not found] ` <CAPYN8sNuV_TirDuM7RrVoKfEsvSSaTokykDV6Sx0HT+XHKAsBA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-12-21 20:53   ` BPJ
     [not found]     ` <CADAJKhBjtkcnau7MEdMsF7YwHco0ipwre5sw-SRhPvOSOhf56w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-12-22  1:20       ` Randy Josleyn

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).