From 60dc046a6e3791cc44795ed243cc4f38ae39e825 Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Wed, 6 Mar 2024 21:27:27 +1100 Subject: [PATCH 1/2] use a single instance of relaton-render (bibrender variable), so that URI fetches are cached between classes of isodoc; store authoritative identifiers retrieved from relaton-render in Presentation XML as docidentifier[scope = 'biblio-tag']: https://github.com/metanorma/metanorma-iso/issues/1114 --- lib/isodoc/convert.rb | 11 +++++++---- lib/isodoc/function/references.rb | 14 ++++++++++++-- lib/isodoc/presentation_function/bibdata.rb | 1 - lib/isodoc/presentation_function/refs.rb | 4 ++-- lib/isodoc/presentation_xml_convert.rb | 1 + lib/isodoc/xref.rb | 1 + 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/isodoc/convert.rb b/lib/isodoc/convert.rb index e91b8021..5f603e7d 100644 --- a/lib/isodoc/convert.rb +++ b/lib/isodoc/convert.rb @@ -10,7 +10,7 @@ module IsoDoc class Convert < ::IsoDoc::Common attr_accessor :options, :i18n, :meta, :xrefs, :reqt_models, - :requirements_processor, :doctype + :requirements_processor, :doctype, :bibrender # htmlstylesheet: Generic stylesheet for HTML # htmlstylesheet_override: Override stylesheet for HTML @@ -86,7 +86,7 @@ def requirements_processor def bibrenderer(options = {}) ::Relaton::Render::IsoDoc::General.new(options.merge(language: @lang, - i18nhash: @i18n.get)) + i18nhash: @i18n.get)) end def convert1(docxml, filename, dir) @@ -108,7 +108,8 @@ def convert_init(file, input_filename, debug) docxml.root.default_namespace = "" convert_i18n_init(docxml) metadata_init(@lang, @script, @locale, @i18n) - xref_init(@lang, @script, self, @i18n, { locale: @locale }) + xref_init(@lang, @script, self, @i18n, + { locale: @locale, bibrender: @bibrender }) docxml = preprocess_xslt(docxml) toc_init(docxml) [docxml, filename, dir] @@ -121,7 +122,8 @@ def preprocess_xslt(docxml) end docxml rescue ::Error => e - require "debug"; binding.b + require "debug" + binding.b end def extract_preprocess_xslt(docxml) @@ -136,6 +138,7 @@ def extract_preprocess_xslt(docxml) def convert_i18n_init(docxml) convert_i18n_init1(docxml) i18n_init(@lang, @script, @locale) + @bibrender ||= bibrenderer @reqt_models = requirements_processor .new({ default: "default", lang: @lang, script: @script, locale: @locale, labels: @i18n.get, diff --git a/lib/isodoc/function/references.rb b/lib/isodoc/function/references.rb index 4feb86b9..3e050e44 100644 --- a/lib/isodoc/function/references.rb +++ b/lib/isodoc/function/references.rb @@ -32,8 +32,18 @@ def std_bibitem_entry(list, bib, _ordinal, biblio) def pref_ref_code(bib) bib["suppress_identifier"] == "true" and return nil - @bibrenderer ||= bibrenderer - data, = @bibrenderer.parse(bib) + ret = bib.xpath(ns("./docidentifier[@scope = 'biblio-tag']")) + ret.empty? or return ret.map(&:text) + ret = pref_ref_code_parse(bib) or return nil + ins = bib.at(ns("./docidentifier[last()]")) + ret.reverse.each do |r| + ins.next = "#{docid_l10n(r)}" + end + ret + end + + def pref_ref_code_parse(bib) + data, = @bibrender.parse(bib) ret = data[:authoritative_identifier] or return nil ret.empty? and return nil ret diff --git a/lib/isodoc/presentation_function/bibdata.rb b/lib/isodoc/presentation_function/bibdata.rb index 73a330f1..d295ef83 100644 --- a/lib/isodoc/presentation_function/bibdata.rb +++ b/lib/isodoc/presentation_function/bibdata.rb @@ -3,7 +3,6 @@ module IsoDoc class PresentationXMLConvert < ::IsoDoc::Convert def bibdata(docxml) - docid_prefixes(docxml) a = bibdata_current(docxml) or return address_precompose(a) bibdata_i18n(a) diff --git a/lib/isodoc/presentation_function/refs.rb b/lib/isodoc/presentation_function/refs.rb index 83326f20..287f577c 100644 --- a/lib/isodoc/presentation_function/refs.rb +++ b/lib/isodoc/presentation_function/refs.rb @@ -37,8 +37,8 @@ def references_render(docxml) prep_for_rendering(b) m << to_xml(b) end.join - @xrefs.klass.bibrenderer.render_all("#{refs}", - type: citestyle) + @bibrender.render_all("#{refs}", + type: citestyle) end def prep_for_rendering(bib) diff --git a/lib/isodoc/presentation_xml_convert.rb b/lib/isodoc/presentation_xml_convert.rb index 866fffa7..7ea83b6b 100644 --- a/lib/isodoc/presentation_xml_convert.rb +++ b/lib/isodoc/presentation_xml_convert.rb @@ -19,6 +19,7 @@ def initialize(options) end def convert1(docxml, _filename, _dir) + docid_prefixes(docxml) # feeds @xrefs.parse citation processing @xrefs.parse docxml bibitem_lookup(docxml) info docxml, nil diff --git a/lib/isodoc/xref.rb b/lib/isodoc/xref.rb index 89d85bb1..c2349bb5 100644 --- a/lib/isodoc/xref.rb +++ b/lib/isodoc/xref.rb @@ -24,6 +24,7 @@ def initialize(lang, script, klass, i18n, options = {}) @i18n = i18n @labels = @i18n.get @klass.i18n = @i18n + @klass.bibrender ||= options[:bibrender] @locale = options[:locale] @reqt_models = @klass.requirements_processor .new({ From afed88f904d7586513ccd9b920fec1695d092e5b Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Thu, 7 Mar 2024 01:17:18 +1100 Subject: [PATCH 2/2] rspec --- spec/isodoc/blocks_spec.rb | 11 +- spec/isodoc/figures_spec.rb | 479 ++++++++++++++++++------------------ spec/isodoc/i18n_spec.rb | 5 +- spec/isodoc/inline_spec.rb | 76 +++--- spec/isodoc/ref_spec.rb | 31 ++- spec/isodoc/table_spec.rb | 1 + spec/spec_helper.rb | 13 + 7 files changed, 329 insertions(+), 287 deletions(-) diff --git a/spec/isodoc/blocks_spec.rb b/spec/isodoc/blocks_spec.rb index 0cf1044c..9d5ccca8 100644 --- a/spec/isodoc/blocks_spec.rb +++ b/spec/isodoc/blocks_spec.rb @@ -767,7 +767,7 @@ Bibliography - 2020-03-27 Hypertext Transfer Protocol — HTTP/1.1 https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2616.xml https://www.rfc-editor.org/info/rfc2616 RFC 2616 RFC2616 10.17487/RFC2616 1999-06 R. Fielding IETF IETF J. Gettys IETF IETF J. Mogul IETF IETF H. Frystyk IETF IETF L. Masinter IETF IETF P. Leach IETF IETF T. Berners-Lee IETF IETF en HTTP has been in use by the World-Wide Web global information initiative since 1990. This specification defines the protocol referred to as “HTTP/1.1”, and is an update to RFC 2068. [STANDARDS-TRACK] RFC 2616 Fremont, CA + 2020-03-27 Hypertext Transfer Protocol — HTTP/1.1 RFC 2616 RFC2616 10.17487/RFC2616 1999-06 R. Fielding IETF IETF J. Gettys IETF IETF J. Mogul IETF IETF H. Frystyk IETF IETF L. Masinter IETF IETF P. Leach IETF IETF T. Berners-Lee IETF IETF en HTTP has been in use by the World-Wide Web global information initiative since 1990. This specification defines the protocol referred to as “HTTP/1.1”, and is an update to RFC 2068. [STANDARDS-TRACK] RFC 2616 Fremont, CA INPUT @@ -807,7 +807,12 @@ Bibliography - R. FIELDING, J. GETTYS, J. MOGUL, H. FRYSTYK, L. MASINTER, P. LEACH and T. BERNERS-LEE. Hypertext Transfer Protocol — HTTP/1.1. In: RFC. 1999. Fremont, CA. https://www.rfc-editor.org/info/rfc2616.https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2616.xmlhttps://www.rfc-editor.org/info/rfc2616[1]IETF RFC 2616IETF RFC2616DOI 10.17487/RFC2616 + R. FIELDING, J. GETTYS, J. MOGUL, H. FRYSTYK, L. MASINTER, P. LEACH and T. BERNERS-LEE. Hypertext Transfer Protocol — HTTP/1.1. In: RFC. 1999. Fremont, CA. + [1] + IETF RFC 2616 + IETF RFC2616 + DOI 10.17487/RFC2616 + IETF RFC 2616 [1]IETF RFC 2616, @@ -848,7 +853,7 @@

Bibliography

-

[1]  IETF RFC 2616, R. FIELDING, J. GETTYS, J. MOGUL, H. FRYSTYK, L. MASINTER, P. LEACH and T. BERNERS-LEE. Hypertext Transfer Protocol — HTTP/1.1. In: RFC. 1999. Fremont, CA. https://www.rfc-editor.org/info/rfc2616.

+

[1]  IETF RFC 2616, R. FIELDING, J. GETTYS, J. MOGUL, H. FRYSTYK, L. MASINTER, P. LEACH and T. BERNERS-LEE. Hypertext Transfer Protocol — HTTP/1.1. In: RFC. 1999. Fremont, CA.

diff --git a/spec/isodoc/figures_spec.rb b/spec/isodoc/figures_spec.rb index 3023b236..30006273 100644 --- a/spec/isodoc/figures_spec.rb +++ b/spec/isodoc/figures_spec.rb @@ -4,105 +4,105 @@ RSpec.describe IsoDoc do it "processes figures" do input = <<~INPUT - - -
- Split-it-right sample divider

X

- alttext - - - - -

The time t_90 was estimated to be 18,2 min for this example.

-
-
-
A
-

B

-
- - - - - 1 - - - - -

with adjustments

-
- -
-
-
A <
-      B
-
-
-
A <
-      B
-
-
- Normative References - - Cereals or cereal products - Cereals and cereal products - ISO 712 - - - - International Organization for Standardization - - - - -
+ + +
+ Split-it-right sample divider

X

+ alttext + + + + +

The time t_90 was estimated to be 18,2 min for this example.

+
+
+
A
+

B

+
+ + + + + 1 + + + + +

with adjustments

+
+ +
+
+
A <
+        B
+
+
+
A <
+        B
+
+
+ Normative References + + Cereals or cereal products + Cereals and cereal products + ISO 712 + + + + International Organization for Standardization + + + + +
INPUT presxml = <<~OUTPUT - - - - - Table of contents - - -
- Figure 1 — Split-it-right sample divider

X

- alttext - - - - -

The time t_90 was estimated to be 18,2 min for this example.

-
-
-
A
-

B

-
- [SOURCE: ISO 712, Section 1 – with adjustments] -
-
- Figure 2 -
A <
-      B
-
-
-
A <
-      B
-
-
- - - 1.<tab/>Normative References - - International Organization for Standardization. Cereals and cereal products. - ISO 712 - ISO 712, - - - - - -
+ + + + Table of contents + + +
+ Figure 1 — Split-it-right sample divider

X

+ alttext + + + + +

The time t_90 was estimated to be 18,2 min for this example.

+
+
+
A
+

B

+
+ [SOURCE: ISO 712, Section 1 – with adjustments] +
+
+ Figure 2 +
A <
+        B
+
+
+
A <
+        B
+
+
+ + + 1.<tab/>Normative References + + International Organization for Standardization. Cereals and cereal products. + ISO 712 + ISO 712 + ISO 712, + + + + + +
OUTPUT html = <<~OUTPUT @@ -245,26 +245,26 @@ INPUT presxml = <<~OUTPUT - - - - Table of contents - - -
- Figure 1 — Overall title -
- Figure 1-1 — Subfigure 1 - alttext -
-
- Figure 1-2 — Subfigure 2 - + + + + Table of contents + + +
+ Figure 1 — Overall title +
+ Figure 1-1 — Subfigure 1 + alttext +
+
+ Figure 1-2 — Subfigure 2 + +
-
- - - + + + OUTPUT html = <<~OUTPUT #{HTML_HDR} @@ -377,49 +377,49 @@ INPUT presxml = <<~OUTPUT - - - - Table of contents - - -
- - Diagram 1 — Split-it-right - sample - divider - -

X

+ + + + Table of contents + + +
+ + Diagram 1 — Split-it-right + sample + divider + +

X

+
+
+ alttext + + + + +

+ The time + t_90 + was estimated to be 18,2 min for this example. +

- - alttext - - - - -

- The time - t_90 - was estimated to be 18,2 min for this example. -

-
-
-
A
-
-

B

-
-
-
-
- Plate 1 -
A < B
-
-
-
A < B
-
-
-
-
+
+
A
+
+

B

+
+
+
+
+ Plate 1 +
A < B
+
+
+
A < B
+
+
+
+
OUTPUT expect(strip_guid(xmlpp(IsoDoc::PresentationXMLConvert.new(presxml_options) .convert("test", input, true).gsub(/</, "<")))) @@ -440,25 +440,25 @@ INPUT presxml = <<~OUTPUT - - - - - Table of contents - - -
- Figure 1 - - - - - - -
-
-
-
+ + + + + Table of contents + + +
+ Figure 1 + + + + + + +
+
+
+
OUTPUT expect(strip_guid(xmlpp(IsoDoc::PresentationXMLConvert.new(presxml_options) .convert("test", input, true) @@ -480,26 +480,26 @@ INPUT presxml = <<~OUTPUT - - - - - Table of contents - - -
- Figure 1 - - - - - - - -
-
-
-
+ + + + + Table of contents + + +
+ Figure 1 + + + + + + + +
+
+
+
OUTPUT html = <<~HTML @@ -594,32 +594,32 @@ INPUT presxml = <<~OUTPUT - - - - Table of contents - - -
- Figure 1 - - - - - - - - - - - - - - -
-
-
-
+ + + + Table of contents + + +
+ Figure 1 + + + + + + + + + + + + + + +
+
+
+
OUTPUT word = <<~OUTPUT @@ -666,7 +666,7 @@ OUTPUT output = IsoDoc::PresentationXMLConvert .new(presxml_options.merge(output_formats: { html: "html", doc: "doc" })) - .convert("test", input, true) + .convert("test", input, true) expect(strip_guid(xmlpp(output .sub(%r{.* - - en - - - - Table of contents - - - - LabelA B C -
Label

  A

- A B C -

  A

-
-
+ + + en + + + + Table of contents + + + + LabelA B C +
Label

  A

+ A B C +

  A

+
+
INPUT output = <<~OUTPUT #{HTML_HDR} @@ -788,6 +788,7 @@ diff --git a/spec/isodoc/i18n_spec.rb b/spec/isodoc/i18n_spec.rb index 4aee82c1..5728d719 100644 --- a/spec/isodoc/i18n_spec.rb +++ b/spec/isodoc/i18n_spec.rb @@ -755,7 +755,9 @@ 2.<tab/>Normative References - Cereals and cereal productsISO 712 + Cereals and cereal products + ISO 712 + ISO 712 ISO 712, @@ -1010,6 +1012,7 @@ Cereals and cereal products. ISO 712 + ISO 712 ISO 712, diff --git a/spec/isodoc/inline_spec.rb b/spec/isodoc/inline_spec.rb index c79c8bf5..9fad09d9 100644 --- a/spec/isodoc/inline_spec.rb +++ b/spec/isodoc/inline_spec.rb @@ -234,38 +234,35 @@

  • - #{' '} (Clause 2)
  • -
  • term#{' '} +
  • term (Clause 2)
  • -
  • w[o]rd#{' '} +
  • w[o]rd [Clause #1]
  • -
  • term#{' '} +
  • term (ISO 712)
  • -
  • word#{' '} +
  • word [The Aforementioned Citation]
  • -
  • word#{' '} +
  • word (ISO 712, Clause 3.1, Figure a)
  • -
  • word#{' '} +
  • word (ISO 712, Clause 3.1 and Figure b)
  • -
  • word#{' '} +
  • word [ - #{' '} - #{' '} The Aforementioned Citation ]
  • -
  • word#{' '} +
  • word ()
  • -
  • word#{' '} +
  • word [The IEV database]
  • @@ -285,6 +282,7 @@ International Organization for Standardization. Cereals and cereal products. ISO 712 + ISO 712 ISO 712, @@ -982,6 +980,7 @@ Cereals and cereal products ISO 712 + ISO 712 @@ -995,6 +994,7 @@ Cereals and cereal products ISO 713 + ISO 713 @@ -1116,6 +1116,7 @@ Cereals and cereal products. ISO 712 + ISO 712 ISO 712, @@ -1232,6 +1233,8 @@ INPUT + date = Date.today.localize(:fr).with_timezone(timezone_identifier_local) + .to_date.to_long_s presxml = <<~OUTPUT @@ -1268,39 +1271,27 @@ Normative References - - Cereals and cereal products - . - https://www.google.com/fr - . - + Cereals and cereal products. https://www.google.com/fr. [vu : #{date}]. https://www.google.com https://www.google.com/en https://www.google.com/fr ISO 712 + ISO 712 ISO 712, - - Cereals and cereal products - . - spec/assets/iso713 - . - + Cereals and cereal products. spec/assets/iso713. [vu : #{date}]. spec/assets/iso713 spec/assets/iso714 ISO 713 + ISO 713 ISO 713, - - Cereals and cereal products - . - spec/assets/iso714.svg - . - + Cereals and cereal products. spec/assets/iso714.svg. [vu : #{date}]. spec/assets/iso714.svg ISO 714 + ISO 714 ISO 714, @@ -1356,21 +1347,21 @@ Cereals and cereal products . https://www.google.com/fr - . + . [vu : #{date}].

    ISO 713, Cereals and cereal products . spec/assets/iso713 - . + . [vu : #{date}].

    ISO 714, Cereals and cereal products . spec/assets/iso714.svg - . + . [vu : #{date}].

    @@ -1433,19 +1424,19 @@ Cereals and cereal products . https://www.google.com/fr - . + . [vu : #{date}].

    ISO 713, Cereals and cereal products . spec/assets/iso713 - . + . [vu : #{date}].

    ISO 714, Cereals and cereal products . spec/assets/iso714.svg - . + . [vu : #{date}].

    @@ -1538,15 +1529,17 @@ @@ -1652,7 +1645,6 @@ Normative References Cereals and cereal products - http://www.example.com ISO 712 @@ -1670,7 +1662,7 @@ Table of contents

    - BSI BS EN ISO 19011:2018 — TC + BSI BS EN ISO 19011:2018 — TC

    @@ -1682,9 +1674,9 @@ Normative References - Cereals and cereal products. http://www.example.com. - http://www.example.com + Cereals and cereal products. ISO 712 + ISO 712 ISO 712, diff --git a/spec/isodoc/ref_spec.rb b/spec/isodoc/ref_spec.rb index 318b3a6d..59495d1a 100644 --- a/spec/isodoc/ref_spec.rb +++ b/spec/isodoc/ref_spec.rb @@ -165,17 +165,20 @@ International Organization for Standardization. Cereals and cereal products. ISO 712 [110] + ISO 712 [110], ISO 712,
    Cereals, pulses, milled cereal products, oilseeds and animal feeding stuffs. ISO 16634:-- (all parts) + ISO 16634:-- (all parts) Under preparation. (Stage at the time of publication ISO/DIS 16634) ISO 16634:-- (all parts)

    Under preparation. (Stage at the time of publication ISO/DIS 16634)

    ,
    International Organization for Standardization. Cereals and pulses. 2013–2014. ISO 20483:2013-2014 + ISO 20483:2013-2014 ISO 20483:2013-2014, @@ -192,6 +195,7 @@ ) ICC/167 + ICC/167 ICC/167, @@ -232,6 +236,7 @@ Water for analytical laboratory use. [3] ISO 3696 + ISO 3696 Under preparation. (Stage at the time of publication ISO/DIS 3696) [3]ISO 3696

    Under preparation. (Stage at the time of publication ISO/DIS 3696)

    ,
    @@ -254,11 +259,13 @@ Internet Calendaring and Scheduling Core Object Specification (iCalendar). [5] IETF RFC 10 + IETF RFC 10 [5]IETF RFC 10, @@ -269,12 +276,14 @@ [Citn] IETF RFC 20 + IETF RFC 20 CitnIETF RFC 20, Internet Calendaring and Scheduling Core Object Specification (iCalendar). [6] IETF RFC 20 + IETF RFC 20 [6]IETF RFC 20, @@ -769,17 +778,20 @@ International Organization for Standardization. Cereals and cereal products. ISO 712 [110] + ISO 712 [110], ISO 712, Cereals, pulses, milled cereal products, oilseeds and animal feeding stuffs. ISO 16634:-- (all parts) + ISO 16634:-- (all parts) Under preparation. (Stage at the time of publication ISO/DIS 16634) ISO 16634:-- (all parts)

    Under preparation. (Stage at the time of publication ISO/DIS 16634)

    ,
    International Organization for Standardization. Cereals and pulses. 2013–2014. ISO 20483:2013-2014 + ISO 20483:2013-2014 ISO 20483:2013-2014, @@ -795,6 +807,7 @@ ) ICC/167 + ICC/167 ICC/167, @@ -832,6 +845,7 @@ Water for analytical laboratory use. ISO 3696 + ISO 3696 [3]ISO 3696, @@ -851,6 +865,7 @@ Internet Calendaring and Scheduling Core Object Specification (iCalendar). IETF RFC 10 + IETF RFC 10 [5]IETF RFC 10, @@ -861,6 +876,7 @@ [Citn] IETF RFC 20 + IETF RFC 20 CitnIETF RFC 20, @@ -960,12 +976,14 @@ International Organization for Standardization. Cereals and cereal products. ISO 712 [110] + ISO 712 Cereals, pulses, milled cereal products, oilseeds and animal feeding stuffs ISO 16634:-- (all parts) + ISO 16634:-- (all parts) -- @@ -1104,6 +1122,7 @@ Cereals or cereal products. [1] IEC 217 + IEC 217 [1]IEC 217, @@ -1115,6 +1134,7 @@ Cereals or cereal products. [3] ABC + ABC [3]ABC, @@ -1204,16 +1224,19 @@ Cereals or cereal products. [1] ABC + ABC [1]ABC, Cereals or cereal products. [2] ABE + ABE [2]ABE, @@ -1370,7 +1393,7 @@ 1.<tab/>Normative References

    The following documents are referred to in the text in such a way that some or all of their content constitutes requirements of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies.

    - International Organization for Standardization and International Electrotechnical Commission. International vocabulary of metrology — Basic and general concepts and associated terms (VIM). First edition. 2007. https://www.iso.org/standard/45324.html. + International Organization for Standardization and International Electrotechnical Commission. International vocabulary of metrology — Basic and general concepts and associated terms (VIM). First edition. 2007. https://www.iso.org/standard/45324.html. [viewed: #{Date.today.strftime('%B %-d, %Y')}]. https://www.iso.org/standard/45324.html https://www.iso.org/obp/ui/#!iso:std:45324:en https://www.iso.org/contents/data/standard/04/53/45324.detail.rss @@ -1387,7 +1410,7 @@

    1.  Normative References

    The following documents are referred to in the text in such a way that some or all of their content constitutes requirements of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies.

    -

    ISO/IEC Guide 99:20071 International Organization for Standardization and International Electrotechnical Commission. International vocabulary of metrology — Basic and general concepts and associated terms (VIM). First edition. 2007. https://www.iso.org/standard/45324.html.

    +

    ISO/IEC Guide 99:20071 International Organization for Standardization and International Electrotechnical Commission. International vocabulary of metrology — Basic and general concepts and associated terms (VIM). First edition. 2007. https://www.iso.org/standard/45324.html. [viewed: #{Date.today.strftime('%B %-d, %Y')}].