node-par.lua /size: 1310 b    last modification: 2021-10-28 13:50
1if not modules then modules = { } end modules ['node-par'] = {
2    version   = 1.001,
3    comment   = "companion to node-ini.mkiv",
4    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5    copyright = "PRAGMA ADE / ConTeXt Development Team",
6    license   = "see context related readme files"
7}
8
9local starttiming = statistics.starttiming
10local stoptiming  = statistics.stoptiming
11
12local sequencers  = utilities.sequencers
13
14-- This are called a lot!
15
16local actions = nodes.tasks.actions("everypar")
17
18local function everypar(head)
19    starttiming(builders)
20    head = actions(head)
21    stoptiming(builders)
22    return head
23end
24
25callbacks.register("insert_local_par",everypar,"after paragraph start")
26
27local actions = sequencers.new {
28    name         = "paragraph",
29    arguments    = "mode,indented",
30    returnvalues = "indented",
31    results      = "indented",
32}
33
34sequencers.appendgroup(actions,"before") -- user
35sequencers.appendgroup(actions,"system") -- private
36sequencers.appendgroup(actions,"after" ) -- user
37
38local function paragraph(mode,indented)
39    local runner = actions.runner
40    if runner then
41        starttiming(builders)
42        indented = runner(mode,indented)
43        stoptiming(builders)
44    end
45    return indented
46end
47
48callbacks.register("new_graf",paragraph,"before paragraph start")
49