public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: H <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org>
To: Pandoc Mailing List
	<pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Understanding traversal directive and customizing filters
Date: Thu, 15 Jun 2023 20:51:21 -0400	[thread overview]
Message-ID: <0bb80078-e128-4a1d-064e-8be88b4c42d4@meddatainc.com> (raw)

I decided to rewrite the custom html-filter I have been working on. Although it works pretty well, it does some convoluted processing of my markdown document.

So, in the interest of furthering my understanding of writing lua code for pandoc and improving my code quality, I decided to experiment using the traversal directive 'topdown' and allowing for different processing depending on some variable. I found the following code for a filter on the 'net and decided to cut it down and start experimenting:

https://stackoverflow.com/questions/72752648/pandoc-lua-how-to-walk-inside-a-div

The filter code I am experimenting with is:

local div1filter = {
    traverse = 'topdown',

    Header = function(el)
        el.identifier = {}
        return el
    end,

    Div = function(div)
        local filter

        if (div.level == 1) then
            filter = div2filter
        else
            filter = div1filter
        end

        return div:walk(filter), false
    end
}

local div2filter = {
    traverse = 'topdown',

    Header = function(el)
        el.identifier = 'test'
        return el
    end
}

--    pandoc main function
Pandoc = function(doc)
    return doc:walk(div1filter)
end

My code above simply removes the header identifier if a header is level 1 and if the header has any other level it replaces the identifier with 'test'. The only purpose of the code is to increase my understanding of selective filter processing and using the 'topdown' directive.

However, despite the Pandoc function being identical to on the webpage, it fails on the return statement complaining that it expected a string but got a table.

I am sure there is some very simple error that I as a beginning pandoc coder have yet to pick up...

-- 
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/0bb80078-e128-4a1d-064e-8be88b4c42d4%40meddatainc.com.


                 reply	other threads:[~2023-06-16  0:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=0bb80078-e128-4a1d-064e-8be88b4c42d4@meddatainc.com \
    --to=agents-fczobrvlydubuy7/sjonfg@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).