lib/isodoc/presentation_function/xrefs.rb in isodoc-2.9.3 vs lib/isodoc/presentation_function/xrefs.rb in isodoc-2.9.4

- old
+ new

@@ -2,11 +2,12 @@ class PresentationXMLConvert < ::IsoDoc::Convert def prefix_container(container, linkend, node, target) prefix_container?(container, node) or return linkend container_container = @xrefs.anchor(container, :container, false) container_label = - prefix_container(container_container, anchor_xref(node, container), + prefix_container(container_container, + anchor_xref(node, container, container: true), node, target) l10n(@i18n.nested_xref.sub("%1", container_label) .sub("%2", linkend)) end @@ -38,25 +39,31 @@ container = @xrefs.anchor(node["target"], :container, false) linkend = prefix_container(container, linkend, node, node["target"]) capitalise_xref(node, linkend, anchor_value(node["target"])) end - def anchor_xref(node, target) - x = @xrefs.anchor(target, :xref) + def anchor_xref(node, target, container: false) + x = anchor_xref_short(node, target, container) t = @xrefs.anchor(target, :title) ret = case node["style"] when "basic" then t when "full" then anchor_xref_full(x, t) when "short", nil then x else @xrefs.anchor(target, node[:style].to_sym) end ret || x end + def anchor_xref_short(node, target, container) + if (l = node["label"]) && !container + @i18n.l10n("#{l} #{anchor_value(target)}") + else @xrefs.anchor(target, :xref) + end + end + def anchor_xref_full(num, title) (!title.nil? && !title.empty?) or return nil - l10n("#{num}, #{title}") end def prefix_container?(container, node) node["style"] == "modspec" and return false # TODO: move to mn-requirements? @@ -75,11 +82,12 @@ l10n(combine_conn(out)) end capitalise_xref(node, linkend, anchor_value(node["target"])) end - # Note % to entry and Note % to entry: cannot conflate as Note % to entry 1 and 2 + # Note % to entry and Note % to entry: + # cannot conflate as Note % to entry 1 and 2 # So Notes 1 and 3, but Note 1 to entry and Note 3 to entry def combine_conflated_xref_locations(locs) out = if locs.any? { |l| l[:elem]&.include?("%") } locs.each { |l| l[:label] = @xrefs.anchor(l[:target], :xref) } else @@ -121,12 +129,11 @@ entry[:label] end end def combine_conn(list) - return list.first[:label] if list.size == 1 - + list.size == 1 and list.first[:label] if list[1..-1].all? { |l| l[:conn] == "and" } @i18n.boolean_conj(list.map { |l| loc2xref(l) }, "and") elsif list[1..-1].all? { |l| l[:conn] == "or" } @i18n.boolean_conj(list.map { |l| loc2xref(l) }, "or") else @@ -152,10 +159,9 @@ linktext = linkend.gsub(/<[^>]+>/, "") (label && !label.empty? && /^#{Regexp.escape(label)}/.match?(linktext)) || linktext[0, 1].match?(/\p{Upper}/) and return linkend node["case"] and return Common::case_with_markup(linkend, node["case"], @script) - capitalise_xref1(node, linkend) end def capitalise_xref1(node, linkend) if start_of_sentence(node)