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