diff options
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luaxml/luaxml-entities.lua')
-rw-r--r-- | Master/texmf-dist/tex/luatex/luaxml/luaxml-entities.lua | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/Master/texmf-dist/tex/luatex/luaxml/luaxml-entities.lua b/Master/texmf-dist/tex/luatex/luaxml/luaxml-entities.lua index dd7e6f7156f..4a6f3011989 100644 --- a/Master/texmf-dist/tex/luatex/luaxml/luaxml-entities.lua +++ b/Master/texmf-dist/tex/luatex/luaxml/luaxml-entities.lua @@ -9,24 +9,41 @@ local function get_named_entity(name) return named_entities[name] end +local function test_invalid_unicode(charnumber) + return charnumber > 127 and charnumber < 256 +end + +local function get_entity(charcode, chartable, base) + local character = chartable[charcode] + if not character then + local charnumber = tonumber(charcode,base) + -- if test_invalid_unicode(charnumber) then + -- return nil + -- end + character = char(charnumber) + chartable[charcode] = character + end + return character +end + + function M.decode(s) return s:gsub("&([#a-zA-Z0-9]+);?", function(m) -- check if this is named entity first local named = get_named_entity(m) + local original_entity = "&" .. m .. ";" if named then return named end -- check if it is numeric entity local hex, charcode = m:match("#([xX]?)([a-fA-F0-9]+)") -- if the entity is not numeric if not charcode then return - "&" .. m .. ";" + original_entity end local character if hex~="" then - character = hexchartable[charcode] or char(tonumber(charcode,16)) - hexchartable[charcode] = character + character = get_entity(charcode, hexchartable, 16) or original_entity else - character = decchartable[charcode] or char(tonumber(charcode)) - decchartable[charcode] = character + character = get_entity(charcode, decchartable, 10) end return character end) |