public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Understanding traversal directive and customizing filters
@ 2023-06-16  0:51 H
  0 siblings, 0 replies; only message in thread
From: H @ 2023-06-16  0:51 UTC (permalink / raw)
  To: Pandoc Mailing List

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.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-16  0:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-16  0:51 Understanding traversal directive and customizing filters H

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