module Metanorma
module Standoc
module Section
def in_biblio?
@biblio
end
def in_norm_ref?
@norm_ref
end
def bibliography_parse(attrs, xml, node)
x = biblio_prep(attrs, xml, node) and return x
@biblio = true
attrs = attrs.merge(normative: node.attr("normative") || false)
xml.references **attr_code(attrs) do |xml_section|
xml_section.title { |t| t << node.title }
xml_section << node.content
end
@biblio = false
end
def bibitem_parse(attrs, xml, node)
norm_ref = @norm_ref
biblio = @biblio
@biblio = false
@norm_ref = false
ret = clause_parse(attrs, xml, node)
@biblio = biblio
@norm_ref = norm_ref
ret
end
def norm_ref_parse(attrs, xml, node)
x = biblio_prep(attrs, xml, node) and return x
@norm_ref = true
attrs = attrs.merge(normative: node.attr("normative") || true)
xml.references **attr_code(attrs) do |xml_section|
xml_section.title { |t| t << node.title }
xml_section << node.content
end
@norm_ref = false
end
def biblio_prep(attrs, xml, node)
if node.option? "bibitem"
bibitem_parse(attrs, xml, node)
else
node.attr("style") == "bibliography" or
@log.add("AsciiDoc Input", node,
"Section not marked up as [bibliography]!")
nil
end
end
def global_ievcache_name
"#{Dir.home}/.iev/cache"
end
def local_ievcache_name(cachename)
return nil if cachename.nil?
cachename += "_iev" unless cachename.empty?
cachename = "iev" if cachename.empty?
"#{cachename}/cache"
end
def fetch_ref(xml, code, year, **opts)
return nil if opts[:no_year]
code = code.sub(/^\([^)]+\)/, "")
hit = @bibdb&.fetch(code, year, opts)
return nil if hit.nil?
xml.parent.add_child(smart_render_xml(hit, code, opts))
xml
rescue RelatonBib::RequestError
@log.add("Bibliography", nil, "Could not retrieve #{code}: "\
"no access to online site")
nil
end
def fetch_ref_async(ref, idx, res)
if ref[:code].nil? || ref[:no_year] || @bibdb.nil?
res << [ref, idx, nil]
else
@bibdb.fetch_async(HTMLEntities.new.decode(ref[:code]),
ref[:year], ref) do |doc|
res << [ref, idx, doc]
end
end
end
def emend_biblio(xml, code, title, usrlbl)
unless xml.at("/bibitem/docidentifier[not(@type = 'DOI')][text()]")
@log.add("Bibliography", nil,
"ERROR: No document identifier retrieved for #{code}")
xml.root << "