Skip to content

Commit

Permalink
preserve markup (other than semx) in docidentifier when using it as c…
Browse files Browse the repository at this point in the history
…iteas attribute andf as content of eref tag: metanorma/bipm-si-brochure#224
  • Loading branch information
opoudjis committed Dec 19, 2024
1 parent eb7d59b commit de8143f
Show file tree
Hide file tree
Showing 3 changed files with 658 additions and 570 deletions.
13 changes: 11 additions & 2 deletions lib/isodoc/presentation_function/erefs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@ def citeas(xmldoc)
xmldoc.xpath(ns("//eref | //origin | //quote//source | //link"))
.each do |e|
e["bibitemid"] && e["citeas"] or next
a = @xrefs.anchor(e["bibitemid"], :xref, false) and
e["citeas"] = a.gsub(%r{</?[^>]+>}, "")
a = @xrefs.anchor(e["bibitemid"], :xref, false) or next
e["citeas"] = citeas_cleanup(a)
# link generated in collection postprocessing from eref
e.name == "link" && e.text.empty? and e.children = e["citeas"]
end
end

def citeas_cleanup(ref)
if /</.match?(ref)
xml = Nokogiri::XML("<root>#{ref}</root>")
xml.xpath("//semx").each { |x| x.replace(x.children) }
ref = to_xml(xml.at("//root").children)
end
ref
end

def expand_citeas(text)
text.nil? and return text
HTMLEntities.new.decode(text.gsub("&amp;#x", "&#"))
Expand Down
2 changes: 1 addition & 1 deletion lib/isodoc/presentation_function/xrefs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def anchor_linkend(node, linkend)
node["style"] == "id" and
return anchor_id_postproc(node)
node["citeas"].nil? && node["bibitemid"] and
return @xrefs.anchor(node["bibitemid"], :xref) || "???"
return citeas_cleanup(@xrefs.anchor(node["bibitemid"], :xref)) || "???"
node.at(ns("./location")) and
return combine_xref_locations(node) || "???"
node["target"] && node["droploc"] and
Expand Down
Loading

0 comments on commit de8143f

Please sign in to comment.