Skip to content

Commit

Permalink
Merge pull request #566 from metanorma/fix/rewrite-citeas
Browse files Browse the repository at this point in the history
overwrite eref/citeas citations with finalised authoritative identifi…
  • Loading branch information
opoudjis authored Mar 12, 2024
2 parents 704892e + b895291 commit 0f57687
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 326 deletions.
30 changes: 16 additions & 14 deletions lib/isodoc/presentation_function/erefs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

module IsoDoc
class PresentationXMLConvert < ::IsoDoc::Convert
def citeas(xmldoc)
xmldoc.xpath(ns("//eref | //origin | //quote/source")).each do |e|
e["bibitemid"] && e["citeas"] or next
a = @xrefs.anchor(e["bibitemid"], :xref, false) and e["citeas"] = a
end
end

def expand_citeas(text)
text.nil? and return text
HTMLEntities.new.decode(text.gsub("&amp;#x", "&#"))
Expand Down Expand Up @@ -40,7 +47,6 @@ def can_conflate_eref_rendering?(refs)
(refs.size > 1 &&
refs.all? { |r| r.name == "localityStack" } &&
refs.all? { |r| r.xpath(ns("./locality")).size == 1 }) or return false

first = refs.first.at(ns("./locality/@type")).text
refs.all? do |r|
r.at(ns("./locality/@type")).text == first
Expand Down Expand Up @@ -97,8 +103,7 @@ def eref_locality_stacks(refs, target, node)
added = eref_locality_stack(r, i, target, node)
added.empty? and next
added.each { |a| m << a }
next if i == refs.size - 1

i == refs.size - 1 and next
m << eref_locality_delimiter(r)
end
ret.empty? ? ret : [", "] + ret
Expand Down Expand Up @@ -156,8 +161,7 @@ def eref_localities1_zh(opt)

# def eref_localities1(target, type, from, upto, node, lang = "en")
def eref_localities1(opt)
return nil if opt[:type] == "anchor"

opt[:type] == "anchor" and return nil
opt[:lang] == "zh" and
# return l10n(eref_localities1_zh(target, type, from, upto, node))
return l10n(eref_localities1_zh(opt))
Expand All @@ -168,8 +172,7 @@ def eref_localities1(opt)
end

def eref_locality_populate(type, node, number)
return "" if node["droploc"] == "true"

node["droploc"] == "true" and return ""
loc = type.sub(/^locality:/, "")
ret = @i18n.locality[loc] || loc
number == "pl" and ret = @i18n.inflect(ret, number: "pl")
Expand Down Expand Up @@ -206,9 +209,8 @@ def eref2link1(node, href)
end

def suffix_url(url)
return url if url.nil? || %r{^https?://|^#}.match?(url)
return url unless File.extname(url).empty?

url.nil? || %r{^https?://|^#}.match?(url) and return url
File.extname(url).empty? or return url
url.sub(/#{File.extname(url)}$/, ".html")
end

Expand All @@ -221,10 +223,10 @@ def eref_target(node)
end

def eref_url(id)
@bibitems.nil? and return nil
b = @bibitems[id] or return nil
url = (b.at(ns("./uri[@type = 'citation'][@language = '#{@lang}']")) ||
b.at(ns("./uri[@type = 'citation']"))) and return url.text
@bibitem_lookup.nil? and return nil
b = @bibitem_lookup[id] or return nil
url = b.at(ns("./uri[@type = 'citation'][@language = '#{@lang}']")) ||
b.at(ns("./uri[@type = 'citation']")) and return url.text
b["hidden"] == "true" and return b.at(ns("./uri"))&.text
"##{id}"
end
Expand Down
11 changes: 6 additions & 5 deletions lib/isodoc/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ def initialize(options)
def convert1(docxml, _filename, _dir)
docid_prefixes(docxml) # feeds @xrefs.parse citation processing
@xrefs.parse docxml
bibitem_lookup(docxml)
info docxml, nil
conversions(docxml)
docxml.root["type"] = "presentation"
docxml.to_xml.gsub("&lt;", "&#x3c;").gsub("&gt;", "&#x3e;")
end

def bibitem_lookup(docxml)
@bibitems = docxml.xpath(ns("//references/bibitem"))
@bibitem_lookup ||= docxml.xpath(ns("//references/bibitem"))
.each_with_object({}) do |b, m|
m[b["id"]] = b
end
Expand Down Expand Up @@ -83,10 +82,12 @@ def block(docxml)
end

def inline(docxml)
bibitem_lookup(docxml) # feeds citeas
citeas docxml # feeds xref, eref, origin, quotesource
xref docxml
eref docxml # feeds docxml
origin docxml # feeds docxml
quotesource docxml # feeds docxml
eref docxml # feeds eref2link
origin docxml # feeds eref2link
quotesource docxml # feeds eref2link
eref2link docxml
mathml docxml
ruby docxml
Expand Down
Loading

0 comments on commit 0f57687

Please sign in to comment.