lxml-ent.lua /size: 1838 b    last modification: 2023-12-21 09:44
1if not modules then modules = { } end modules ['lxml-ent'] = {
2    version   = 1.001,
3    comment   = "this module is the basis for the lxml-* ones",
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 next = next
10local byte, format = string.byte, string.format
11local setmetatableindex = table.setmetatableindex
12
13-- We provide (at least here) two entity handlers. The more extensive resolver
14-- consults a hash first, tries to convert to UTF next, and finaly calls a handler
15-- when defines. When this all fails, the original entity is returned. We do things
16-- different now but it's still somewhat experimental.
17
18local trace_entities = false  trackers.register("xml.entities", function(v) trace_entities = v end)
19
20local report_xml = logs.reporter("xml")
21
22local xml = xml
23
24xml.entities = xml.entities or { }
25
26storage.register("xml/entities", xml.entities, "xml.entities" )
27
28local entities = xml.entities  -- maybe some day properties
29
30function xml.registerentity(key,value)
31    entities[key] = value
32    if trace_entities then
33        report_xml("registering entity %a as %a",key,value)
34    end
35end
36
37if characters and characters.entities then
38
39    -- the big entity table also has amp, quot, apos, lt, gt in them
40
41    local loaded = false
42
43    function characters.registerentities(forcecopy)
44        if loaded then
45            return
46        end
47        if forcecopy then
48            setmetatableindex(entities,nil)
49            for name, value in next, characters.entities do
50                if not entities[name] then
51                    entities[name] = value
52                end
53            end
54        else
55            setmetatableindex(entities,characters.entities)
56        end
57        loaded = true
58    end
59
60end
61