require "asciidoctor" require "tempfile" require "uuidtools" require "htmlentities" require "nokogiri" module Metanorma module Utils NAMECHAR = "\u0000-\u002c\u002f\u003a-\u0040\\u005b-\u005e" \ "\u0060\u007b-\u00b6\u00b8-\u00bf\u00d7\u00f7\u037e" \ "\u2000-\u200b" \ "\u200e-\u203e\u2041-\u206f\u2190-\u2bff\u2ff0-\u3000".freeze NAMESTARTCHAR = "\\u002d\u002e\u0030-\u0039\u00b7\u0300-\u036f" \ "\u203f-\u2040".freeze NOKOHEAD = <<~HERE.freeze
def wrap_in_para(node, out)
if node.blocks? then out << node.content
else
out.p { |p| p << node.content }
end
end
# all element/attribute pairs that are ID anchors in Metanorma
def anchor_attributes
[%w[* id], %w[* bibitemid], %w[review from],
%w[review to], %w[index to], %w[xref target],
%w[callout target], %w[location target]]
end
# convert definition list term/value pair into Nokogiri XML attribute
def dl_to_attrs(elem, dlist, name)
e = dlist.at("./dt[text()='#{name}']") or return
val = e.at("./following::dd/p") || e.at("./following::dd") or return
elem[name] = val.text
end
# convert definition list term/value pairs into Nokogiri XML elements
def dl_to_elems(ins, elem, dlist, name)
a = elem.at("./#{name}[last()]")
ins = a if a
dlist.xpath("./dt[text()='#{name}']").each do |e|
ins = dl_to_elems1(e, name, ins)
end
ins
end
def dl_to_elems1(term, name, ins)
v = term.at("./following::dd")
e = v.elements and e.size == 1 && e.first.name == "p" and v = e.first
v.name = name
ins.next = v
ins.next
end
def case_transform_xml(xml, kase)
x = Nokogiri::XML("