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
14
15
16
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
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
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 |