if not modules then modules = { } end modules ['node-par'] = {
    version   = 1.001,
    comment   = "companion to node-ini.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

local sequencers  = utilities.sequencers

-- This is called a lot! I'm a bit reluctant with this one because it is sensitive
-- for order. In many other callbacks there is no action at the tex end but here ...
-- Anyway, it has been around for a while now (2019) and so far I had no need for
-- extensive usage so we're okay.

do

    local insert_par_callback = nodes.tasks.actions("everypar")

    callbacks.register {
        name    = "insert_par",
        action  = insert_par_callback,
        comment = "after paragraph start",
        frozen  = true,
    }

end

-- Originally this one was meant to deal with the indentation (like turn a box into
-- a skip or prevent it) but that never really was used. The return value still
-- determines if an indentation box or skip is injected. Will I change that?

do

local id, enable, disable = callbacks.optimizer("begin_paragraph")

    local actions = sequencers.new {
        name         = "paragraph",
        arguments    = "mode,indented,context",
        returnvalues = "indented",
        results      = "indented",
enable       = enable,
disable      = disable,
    }

    sequencers.appendgroup(actions,"before") -- user
    sequencers.appendgroup(actions,"system") -- private
    sequencers.appendgroup(actions,"after" ) -- user

    local function begin_paragraph_callback(mode,indented,context) -- context used to be the cmd code
        local runner = actions.runner
        if runner then
            indented = runner(mode,indented,context)
        end
        return indented
    end

    callbacks.register {
        name    = "begin_paragraph",
        action  = begin_paragraph_callback,
        comment = "before paragraph start",
        frozen  = true,
    }

end

-- This one is a playground for some old metafun gimmicks that I want to improve
-- while I'm updating the manual to lmtx. but it might also be useful for other
-- purposes. It fits in the category obscure and probably takes while to stabelize
-- (if it stays at all). Again, this is one that has the danger of interference,
-- so when it finally got an action handler it only got a system one.

do

local id, enable, disable = callbacks.optimizer("paragraph_context")

    local actions = sequencers.new {
        name         = "paragraphcontext",
        arguments    = "context",
        returnvalues = "ignore",
        results      = "ignore",
enable       = enable,
disable      = disable,
    }

    ----------.appendgroup(actions,"before") -- user
    sequencers.appendgroup(actions,"system") -- private
    ----------.appendgroup(actions,"after" ) -- user

    local function paragraph_context_callback(parcontext)
        local runner = actions.runner
        if runner then
            return runner(parcontext) -- returns ignore
        end
    end

    callbacks.register {
        name    = "paragraph_context",
        action  = paragraph_context_callback,
        comment = "when the context is dealt with",
        frozen  = true,
    }

end
