diff --git a/show-pdf-tags/show-pdf-tags.lua b/show-pdf-tags/show-pdf-tags.lua index ad893a1..f985217 100755 --- a/show-pdf-tags/show-pdf-tags.lua +++ b/show-pdf-tags/show-pdf-tags.lua @@ -416,12 +416,19 @@ local function format_subtype(subtype) end end +local function format_xml_name(s) +-- %p would include _ + return s:gsub("([:+(),@%s])", + function (c) return string.format("_x%02X_",c:byte()) end + ) + end + local function format_subtype_xml(subtype) if subtype.namespace then return string.format('<%s xmlns="%s"', subtype.subtype, (hide_w3c and subtype.namespace:gsub('http://www.w3.org', 'http://-www.w3.org')) or subtype.namespace) else - return "<" .. subtype.subtype:gsub(":","_x3A_") + return "<" .. format_xml_name(subtype.subtype) end end @@ -683,7 +690,7 @@ local function print_tree_xml(tree, ctx) if follow_rolemap and mapped then print(indent .. "") else - print(indent .. "") + print(indent .. "") end elseif #lines > 0 then for i=1, #lines-1 do @@ -693,7 +700,7 @@ local function print_tree_xml(tree, ctx) if follow_rolemap and mapped then print(indent .. "") else - print(indent .. "") + print(indent .. "") end end end