lib/isodoc/function/utils.rb in isodoc-2.1.1 vs lib/isodoc/function/utils.rb in isodoc-2.1.2
- old
+ new
@@ -56,28 +56,34 @@
abort "Malformed Output XML for #{@format}: #{e} "\
"(see #{@filename}.#{@format}.err)"
end
end
- def to_xhtml_prep(xml)
- xml.gsub!(/<\?xml[^>]*>/, "")
- /<!DOCTYPE /.match(xml) || (xml = DOCTYPE_HDR + xml)
+ def numeric_escapes(xml)
+ c = HTMLEntities.new
xml.split(/(&[^ \r\n\t#;]+;)/).map do |t|
if /^(&[^ \t\r\n#;]+;)/.match?(t)
- HTMLEntities.new.encode(HTMLEntities.new.decode(t), :hexadecimal)
+ c.encode(c.decode(t), :hexadecimal)
else t
end
end.join
end
+ def to_xhtml_prep(xml)
+ xml.gsub!(/<\?xml[^>]*>/, "")
+ /<!DOCTYPE /.match(xml) || (xml = DOCTYPE_HDR + xml)
+ numeric_escapes(xml)
+ end
+
def to_xhtml_fragment(xml)
doc = ::Nokogiri::XML.parse(NOKOHEAD)
doc.fragment(xml)
end
def from_xhtml(xml)
- xml.to_xml.sub(%r{ xmlns="http://www.w3.org/1999/xhtml"}, "")
+ numeric_escapes(xml.to_xml
+ .sub(%r{ xmlns="http://www.w3.org/1999/xhtml"}, ""))
end
CLAUSE_ANCESTOR =
".//ancestor::*[local-name() = 'annex' or "\
"local-name() = 'definitions' or "\
@@ -98,11 +104,15 @@
"local-name() = 'acknowledgements' or local-name() = 'term' or "\
"local-name() = 'clause' or local-name() = 'references' or "\
"local-name() = 'figure' or local-name() = 'formula' or "\
"local-name() = 'table' or local-name() = 'example']/@id"
- def get_note_container_id(node)
- container = node.xpath(NOTE_CONTAINER_ANCESTOR)
+ # no recursion on references
+ def get_note_container_id(node, type)
+ xpath = NOTE_CONTAINER_ANCESTOR.dup
+ %w(figure table example).include?(type) and
+ xpath.sub!(%r[ or local-name\(\) = '#{type}'], "")
+ container = node.xpath(xpath)
container&.last&.text || nil
end
def sentence_join(array)
return "" if array.nil? || array.empty?