lib/isodoc/presentation_function/xrefs.rb in isodoc-2.1.1 vs lib/isodoc/presentation_function/xrefs.rb in isodoc-2.1.2
- old
+ new
@@ -24,28 +24,43 @@
end
def anchor_linkend1(node)
linkend = @xrefs.anchor(node["target"], :xref)
container = @xrefs.anchor(node["target"], :container, false)
- (container && get_note_container_id(node) != container &&
- @xrefs.get[node["target"]]) and
+ prefix_container?(container, node) and
linkend = prefix_container(container, linkend, node["target"])
capitalise_xref(node, linkend, anchor_value(node["target"]))
end
+ def prefix_container?(container, node)
+ type = @xrefs.anchor(node["target"], :type)
+ container &&
+ get_note_container_id(node, type) != container &&
+ @xrefs.get[node["target"]]
+ end
+
def combine_xref_locations(node)
locs = gather_xref_locations(node)
linkend = if can_conflate_xref_rendering?(locs)
- out = locs.each { |l| l[:target] = anchor_value(l[:target]) }
- l10n("#{locs.first[:elem]} #{combine_conn(out)}")
+ combine_conflated_xref_locations(locs)
else
- out = locs.each { |l| l[:target] = anchor_linked1(l[:node]) }
+ out = locs.each { |l| l[:target] = anchor_linkend1(l[:node]) }
l10n(combine_conn(out))
end
capitalise_xref(node, linkend, anchor_value(node["target"]))
end
+ def combine_conflated_xref_locations(locs)
+ out = locs.each { |l| l[:target] = anchor_value(l[:target]) }
+ ret = l10n("#{locs.first[:elem]} #{combine_conn(out)}")
+ container = @xrefs.anchor(locs.first[:node]["target"], :container,
+ false)
+ prefix_container?(container, locs.first[:node]) and
+ ret = prefix_container(container, ret, locs.first[:node]["target"])
+ ret
+ end
+
def gather_xref_locations(node)
node.xpath(ns("./location")).each_with_object([]) do |l, m|
type = @xrefs.anchor(l["target"], :type)
m << { conn: l["connective"], target: l["target"],
type: type, node: l, elem: @xrefs.anchor(l["target"], :elem),
@@ -72,10 +87,11 @@
@i18n.send("chain_#{entry[:conn]}").sub(/%1/, value)
.sub(/%2/, entry[:target])
end
def can_conflate_xref_rendering?(locs)
- !locs.all? { |l| l[:container].nil? } &&
+ (locs.all? { |l| l[:container].nil? } ||
+ locs.all? { |l| l[:container] == locs.first[:container] }) &&
locs.all? { |l| l[:type] == locs[0][:type] }
end
def capitalise_xref(node, linkend, label)
linktext = linkend.gsub(/<[^>]+>/, "")