From 7d83202dd805012ab197424a1f2be5262354ae2a Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Thu, 9 Jan 2025 23:58:10 +0200 Subject: [PATCH] Presentation XML refactor, terms: https://github.com/metanorma/isodoc/issues/630 --- Gemfile.devel | 4 + lib/isodoc/bipm/presentation_xml_convert.rb | 9 +- spec/isodoc/html_convert_spec.rb | 253 ++++++++++++++------ spec/isodoc/section_spec.rb | 64 ++++- spec/metanorma/processor_spec.rb | 2 +- spec/spec_helper.rb | 1 + 6 files changed, 241 insertions(+), 92 deletions(-) create mode 100644 Gemfile.devel diff --git a/Gemfile.devel b/Gemfile.devel new file mode 100644 index 0000000..b0030bc --- /dev/null +++ b/Gemfile.devel @@ -0,0 +1,4 @@ +gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "feature/presentation-terms" +gem "metanorma-iso", git: "https://github.com/metanorma/metanorma-iso", branch: "feature/presentation-terms" +gem "metanorma-generic", git: "https://github.com/metanorma/metanorma-generic", branch: "feature/presentation-terms" +gem "mn-requirements", git: "https://github.com/metanorma/mn-requirements", branch: "main" diff --git a/lib/isodoc/bipm/presentation_xml_convert.rb b/lib/isodoc/bipm/presentation_xml_convert.rb index 63d2d2f..d586f57 100644 --- a/lib/isodoc/bipm/presentation_xml_convert.rb +++ b/lib/isodoc/bipm/presentation_xml_convert.rb @@ -128,7 +128,7 @@ def jcgm_eref(docxml, xpath) def extract_brackets(node) start = node.at("./text()[1]") finish = node.at("./text()[last()]") - (/^\[/.match?(start.text) && /\]$/.match?(finish.text)) or return + (/^\[/.match?(start&.text) && /\]$/.match?(finish&.text)) or return start.replace(start.text[1..-1]) node.previous = "[" finish = node.at("./text()[last()]") @@ -143,7 +143,8 @@ def quotedtitles(docxml) end end - def termsource1(elem) + # KILL + def termsource1_xx(elem) # elem["status"] == "modified" and return super while elem&.next_element&.name == "termsource" elem << "; #{to_xml(elem.next_element.remove.children)}" @@ -152,6 +153,10 @@ def termsource1(elem) "#{to_xml(elem.children).strip}]") end + def termsource_label(elem, sources) + elem.replace(l10n("[#{termsource_adapt(elem['status'])} #{sources}]")) + end + def termsource_adapt(status) case status when "adapted" then @i18n.adapted_from diff --git a/spec/isodoc/html_convert_spec.rb b/spec/isodoc/html_convert_spec.rb index 603b66b..2012722 100644 --- a/spec/isodoc/html_convert_spec.rb +++ b/spec/isodoc/html_convert_spec.rb @@ -183,7 +183,7 @@ Terms, Definitions, Symbols and Abbreviated Terms - Term2 + Term2 3.1 @@ -192,7 +192,7 @@ - Term3 + Term3
  • A
  • @@ -253,17 +253,42 @@ . 1 - Term2 - - [Modified from: + + + Term2 + + + +

    + + Term2 + +

    +
    + 3.1 - ISO 7301:2011, Clause 3.1 - — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here] + +

    The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here

    +
    + + [Modified from: + + + + 3.1 + + ISO 7301:2011, Clause 3.1 + + — + The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here + + ] + @@ -280,8 +305,19 @@ . 2 - Term3 - + + + Term3 + + + +

    + + Term3 + +

    +
    + EXAMPLE @@ -359,16 +395,25 @@

The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.

- - [ + 3.2 - ISO 7301:2011, Clause 3.2 - ] + + [ + + + + 3.2 + + ISO 7301:2011, Clause 3.2 + + + ] +
@@ -376,29 +421,34 @@ INPUT output = Xml::C14n.format(<<~OUTPUT) - -
-

 

-
-
-
-

 

-
-
-
-
-
-

Contents

-
+ +
+

 

+
+
+
+

 

+
+
+
+
+
+

Contents

+

1.  Terms, Definitions, Symbols and Abbreviated Terms

1.1.

-

Term2

-

[Modified from: ISO 7301:2011, Clause 3.1 - — - The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here]

+

+ Term2 +

+

[Modified from: + ISO 7301:2011, Clause 3.1 + — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here + ]

1.2.

-

Term3

+

+ Term3 +

EXAMPLE

@@ -424,7 +474,9 @@

The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.

-

[ISO 7301:2011, Clause 3.2]

+

[ + ISO 7301:2011, Clause 3.2 + ]

@@ -460,7 +512,7 @@ Terms, Definitions, Symbols and Abbreviated Terms - Term2 + Term2 3.1 @@ -469,7 +521,7 @@ - Term3 + Term3
  • A
  • @@ -539,18 +591,43 @@ . 1 - Term2 - - [Modified from: + + + Term2 + + + +

    + + Term2 + +

    +
    + 3.1 - ISO 7301:2011, - 3.1 - — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here] + +

    The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here

    +
    + + [Modified from: + + + + 3.1 + + ISO 7301:2011, + 3.1 + + — + The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here + + ] + @@ -566,8 +643,19 @@ . 2 - Term3 - + + + Term3 + + + +

    + + Term3 + +

    +
    + EXAMPLE @@ -642,17 +730,26 @@

The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.

- - [ + 3.2 - ISO 7301:2011, - 3.2 - ] + + [ + + + + 3.2 + + ISO 7301:2011, + 3.2 + + + ] +
@@ -660,30 +757,36 @@ INPUT output = Xml::C14n.format(<<~OUTPUT) - -
-

 

-
-
-
-

 

-
-
-
-
-
-

Contents

-
-
-

1.  Terms, Definitions, Symbols and Abbreviated Terms

-

1.1.

-

Term2

-

[Modified from: ISO 7301:2011, 3.1 - — - The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here]

-

1.2.

-

Term3

-
+ +
+

 

+
+
+
+

 

+
+
+
+
+
+

Contents

+
+
+

1.  Terms, Definitions, Symbols and Abbreviated Terms

+

1.1.

+

+ Term2 +

+

+ [Modified from: ISO 7301:2011, + 3.1 + — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here ] +

+

1.2.

+

+ Term3 +

+

EXAMPLE

    @@ -709,16 +812,12 @@

    The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.

- [ISO 7301:2011, + [ ISO 7301:2011, 3.2 ]

- -

[ISO 7301:2011, 3.2]

-
-
OUTPUT pres_output = diff --git a/spec/isodoc/section_spec.rb b/spec/isodoc/section_spec.rb index 4c3b3b0..62fa29d 100644 --- a/spec/isodoc/section_spec.rb +++ b/spec/isodoc/section_spec.rb @@ -27,7 +27,7 @@ Normal Terms - Term2 + Term2 @@ -176,7 +176,18 @@ . 1 - Term2 + + + Term2 + + + +

+ + Term2 + +

+
@@ -434,9 +445,18 @@ . 1 - - Term - + + + Term + + + +

+ + Term + +

+
@@ -489,7 +509,7 @@

1.1.  Normal Terms

1.1.1.

-

Term2

+

Term2

1.2.  Scope

@@ -619,7 +639,7 @@ Normal Terms - Term2 + Term2 @@ -799,7 +819,18 @@ . 1 - Term2 + + + Term2 + + + +

+ + Term2 + +

+
@@ -1069,7 +1100,7 @@

3.1.  Normal Terms

3.1.1.

-

Term2

+

Term2

3.2.  Scope

@@ -1678,9 +1709,18 @@ [term-term-1] " - - Term - + + + Term + + + +

+ + Term + +

+
diff --git a/spec/metanorma/processor_spec.rb b/spec/metanorma/processor_spec.rb index ed5d6c7..eefd8e2 100644 --- a/spec/metanorma/processor_spec.rb +++ b/spec/metanorma/processor_spec.rb @@ -44,7 +44,7 @@ 1.Terms, Definitions, Symbols and Abbreviated Terms 1.1. - Term2 +

Term2

diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 16cceb5..0379b0e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -61,6 +61,7 @@ def metadata(hash) def strip_guid(html) html .gsub(%r{ id="_[^"]+"}, ' id="_"') + .gsub(%r{ original-id="_[^"]+"}, ' original-id="_"') .gsub(%r{ target="_[^"]+"}, ' target="_"') .gsub(%r{ source="_[^"]+"}, ' source="_"') .gsub(%r{[^<]+}, "")