lib/asciidoctor/iso/ref.rb in asciidoctor-iso-0.9.7 vs lib/asciidoctor/iso/ref.rb in asciidoctor-iso-0.9.9

- old
+ new

@@ -86,24 +86,33 @@ xml rescue Algolia::AlgoliaProtocolError nil # Render reference without an Internet connection. end - # TODO: alternative where only title is available - def refitem(xml, item, node) - unless m = NON_ISO_REF.match(item) - Utils::warning(node, "no anchor on reference", item) - return - end + def refitem_render(xml, m) xml.bibitem **attr_code(id: m[:anchor]) do |t| t.formattedref **{ format: "application/x-isodoc+xml" } do |i| i << ref_normalise_no_format(m[:text]) end t.docidentifier(/^\d+$/.match?(m[:code]) ? "[#{m[:code]}]" : m[:code]) end end + # TODO: alternative where only title is available + def refitem(xml, item, node) + unless m = NON_ISO_REF.match(item) + Utils::warning(node, "no anchor on reference", item) + return + end + unless m[:code] && /^\d+$/.match?(m[:code]) + ref = fetch_ref xml, m[:code], + m.named_captures.has_key?("year") ? m[:year] : nil, {} + return use_my_anchor(ref, m[:anchor]) if ref + end + refitem_render(xml, m) + end + def ref_normalise(ref) ref. # gsub(/&#8201;&#8212;&#8201;/, " -- "). gsub(/&amp;amp;/, "&amp;"). gsub(%r{^<em>(.*)</em>}, "\\1") @@ -128,11 +137,11 @@ \[(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)(:(?<year>[0-9][0-9-]+))?\s \(all\sparts\)\]</ref>,?\s (?<text>.*)$}xm NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)"> - \[(?<code>[^\]]+)\]</ref>,?\s + \[(?<code>[^\]]+?)([:-](?<year>(19|20)[0-9][0-9]))?\]</ref>,?\s (?<text>.*)$}xm # @param item [String] # @return [Array<MatchData>] def reference1_matches(item) @@ -163,11 +172,11 @@ end end.join("\n") end def bibliocache_name(global) - global ? "#{Dir.home}/.relaton-bib.json" : - "#{@filename}.relaton.json" + global ? "#{Dir.home}/.relaton-bib.pstore" : + "#{@filename}.relaton.pstore" end end end end