lib/isodoc/function/utils.rb in isodoc-2.5.8 vs lib/isodoc/function/utils.rb in isodoc-2.5.9
- old
+ new
@@ -58,11 +58,11 @@
Metanorma::Utils::numeric_escapes(xml)
end
def to_xhtml_prep(xml)
xml.gsub!(/<\?xml[^>]*>/, "")
- /<!DOCTYPE /.match(xml) || (xml = DOCTYPE_HDR + xml)
+ xml.include?("<!DOCTYPE ") || (xml = DOCTYPE_HDR + xml)
numeric_escapes(xml)
end
def to_xhtml_fragment(xml)
Metanorma::Utils::to_xhtml_fragment(xml)
@@ -128,11 +128,11 @@
def header_strip(hdr)
h1 = to_xhtml_fragment(hdr.to_s.gsub(%r{<br\s*/>}, " ")
.gsub(%r{</?p(\s[^>]+)?>}, "")
.gsub(/<\/?h[123456][^>]*>/, "").gsub(/<\/?b[^>]*>/, "").dup)
h1.traverse do |x|
- if x.name == "span" && /mso-tab-count/.match(x["style"])
+ if x.name == "span" && x["style"]&.include?("mso-tab-count")
x.replace(" ")
elsif header_strip_elem?(x) then x.remove
elsif x.name == "a" then x.replace(x.children)
end
end
@@ -141,11 +141,11 @@
def header_strip_elem?(elem)
elem.name == "img" ||
(elem.name == "span" && elem["class"] == "MsoCommentReference") ||
(elem.name == "a" && elem["class"] == "FootnoteRef") ||
- (elem.name == "span" && /mso-bookmark/.match(elem["style"]))
+ (elem.name == "span" && elem["style"]&.include?("mso-bookmark"))
end
def liquid(doc)
# unescape HTML escapes in doc
doc = doc.split(%r<(\{%|%\})>).each_slice(4).map do |a|
@@ -200,12 +200,18 @@
when %r{^([A-Z]:)?/} then img["src"]
else File.join(@localdir, img["src"])
end
end
- def labelled_ancestor(node)
- !node.ancestors("example, requirement, recommendation, permission, " \
- "note, table, figure, sourcecode").empty?
+ LABELLED_ANCESTOR_ELEMENTS =
+ %w(example requirement recommendation permission
+ note table figure sourcecode).freeze
+
+ def labelled_ancestor(elem)
+ #require "debug"; binding.b
+ #!elem.path.gsub(/\[\d+\]/, "").split(%r{/})[1..-1]
+ !elem.ancestors.map(&:name)
+ .intersection(LABELLED_ANCESTOR_ELEMENTS).empty?
end
def emf?(type)
%w(application/emf application/x-emf image/x-emf image/x-mgx-emf
application/x-msmetafile image/x-xbitmap image/emf).include? type