Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions show-pdf-tags/show-pdf-tags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -683,7 +690,7 @@ local function print_tree_xml(tree, ctx)
if follow_rolemap and mapped then
print(indent .. "</" .. mapped.subtype ..">")
else
print(indent .. "</" .. subtype.subtype:gsub(":","_x3A_") ..">")
print(indent .. "</" .. format_xml_name(subtype.subtype) ..">")
end
elseif #lines > 0 then
for i=1, #lines-1 do
Expand All @@ -693,7 +700,7 @@ local function print_tree_xml(tree, ctx)
if follow_rolemap and mapped then
print(indent .. "</" .. mapped.subtype ..">")
else
print(indent .. "</" .. subtype.subtype:gsub(":","_x3A_") ..">")
print(indent .. "</" .. format_xml_name(subtype.subtype) ..">")
end
end
end
Expand Down
Loading