summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/typo-hid.lmt
blob: e3b7567d9c6063756ea00c37ad8e08685bc3cc4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
if not modules then modules = { } end modules ['typo-hid'] = {
    version   = 1.001,
    comment   = "companion to typo-hid.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

local a_hidecontent = attributes.system("hidecontent")
local specialskips  = nodes.specialskipcodes
local glue_code     = nodes.nodecodes.glue
local nuts          = nodes.nuts
local getattr       = nuts.getattr
local getnext       = nuts.getnext
local setnext       = nuts.setnext
local getprev       = nuts.getprev
local setlist       = nuts.setlist
local setlink       = nuts.setlink
local nextnode      = nuts.traversers.node
local flushlist     = nuts.flush_list
local dimensions    = nuts.rangedimensions
local hpack         = nuts.hpack
local setwhd        = nuts.setwhd
local setattrlist   = nuts.setattrlist
local enableaction  = nodes.tasks.enableaction

function nodes.handlers.wipe(head,groupcode,line)
    if getattr(line,a_hidecontent) then
        flushlist(head)
        setlist(line)
    else
        -- we have normalized lines so always some skip to start with
        local b, e = nil, nil
        local function wipe()
            local h = hpack()
            local n = getnext(e)
            setwhd(h,dimensions(line,b,n))
            setlink(getprev(b),h,n)
            setattrlist(h,b)
            setnext(b)
            flushlist(b)
            b = nil
            e = nil
        end
        for n, id, subtype in nextnode, head do
            if id == glue_code and specialskips[subtype] then
                if b then
                    wipe()
                end
            elseif getattr(n,a_hidecontent) then
                if not b then
                    b = n
                end
                e = n
            elseif b then
                wipe()
            end
        end
        if b then
            -- can't happen because we had a skip
            wipe()
        end
        setlist(line,head)
    end
    return nil
end

interfaces.implement {
    name     = "enablehidecontent",
    onlyonce = true,
    actions  = function()
        enableaction("contributers","nodes.handlers.wipe")
    end,
}