From 5a14707f7d4eddc85ba2e5721a02e88081625651 Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Sun, 10 Nov 2024 22:11:30 +1100 Subject: [PATCH] allow multiple sections of same type if specified through heading attribute: https://github.com/metanorma/metanorma-standoc/issues/939 --- lib/metanorma/standoc/blocks.rb | 1 - lib/metanorma/standoc/isodoc.rng | 2 +- lib/metanorma/standoc/section.rb | 2 +- spec/metanorma/cleanup_sections_spec.rb | 1353 ++++++++++++----------- spec/metanorma/section_spec.rb | 84 ++ 5 files changed, 785 insertions(+), 657 deletions(-) diff --git a/lib/metanorma/standoc/blocks.rb b/lib/metanorma/standoc/blocks.rb index 8df034ec..940fd93c 100644 --- a/lib/metanorma/standoc/blocks.rb +++ b/lib/metanorma/standoc/blocks.rb @@ -212,7 +212,6 @@ def pass(node) noko do |xml| xml.passthrough **attr_code(formats: node.attr("format") || "metanorma") do |p| - # p << @c.encode(@c.decode(node.content), :basic, :hexadecimal) p << @c.encode(node.content, :basic, :hexadecimal) end end diff --git a/lib/metanorma/standoc/isodoc.rng b/lib/metanorma/standoc/isodoc.rng index efd04351..09843dc0 100644 --- a/lib/metanorma/standoc/isodoc.rng +++ b/lib/metanorma/standoc/isodoc.rng @@ -17,7 +17,7 @@ these elements; we just want one namespace for any child grammars of this. --> - + diff --git a/lib/metanorma/standoc/section.rb b/lib/metanorma/standoc/section.rb index f03b6b47..851bcadc 100644 --- a/lib/metanorma/standoc/section.rb +++ b/lib/metanorma/standoc/section.rb @@ -24,7 +24,7 @@ def sectiontype(node, level = true) ret1 = preface_main_filter(sectiontype_streamline(ret), node) ret1 == "symbols and abbreviated terms" and return ret1 !level || node.level == 1 || node.attr("heading") or return nil - @seen_headers.include? ret and return nil + !node.attr("heading") && @seen_headers.include?(ret) and return nil @seen_headers << ret unless ret1.nil? @seen_headers_canonical << ret1 unless ret1.nil? ret1 diff --git a/spec/metanorma/cleanup_sections_spec.rb b/spec/metanorma/cleanup_sections_spec.rb index 2eeebd81..4c7249fe 100644 --- a/spec/metanorma/cleanup_sections_spec.rb +++ b/spec/metanorma/cleanup_sections_spec.rb @@ -289,188 +289,197 @@ - - Abstract -

Text

-
- - - Foreword - <fn reference="1"> - <p id="_">A</p> - </fn> - -

Text

-
- - Introduction - - Introduction Subsection - - - - Dedication - - - - Acknowledgements - <fn reference="1"> - <p id="_">A</p> - </fn> - - -
- - - - Scope - <fn reference="1"> - <p id="_">A</p> - </fn> - -

Text

-
- - - Terms and definitions - <fn reference="1"> - <p id="_">A</p> - </fn> - -

For the purposes of this document, the following terms and definitions apply.

- - - - Term1 - - - -
- - - Terms, Definitions, Symbols and Abbreviated Terms. - <fn reference="1"> - <p id="_">A</p> - </fn> - - - Introduction - - Intro 1 - - - - Intro 2 - - Intro 3 - - - - Intro 4 - - Intro 5 - - Term1 - - - - - Normal Terms - - Term2 - - - - - Symbols and abbreviated terms - <fn reference="1"> - <p id="_">A</p> - </fn> - - - General - - - - Symbols - <fn reference="1"> - <p id="_">A</p> - </fn> - - - - - - - Abbreviated terms - <fn reference="1"> - <p id="_">A</p> - </fn> - - - - Clause 4 - - Introduction - - - Clause 4.2 - - - - Terms and Definitions - -
- - - Annex. - <fn reference="1"> - <p id="_">A</p> - </fn> - - - Annex A.1 - - - - - - Normative references - <fn reference="1"> - <p id="_">A</p> - </fn> - -

There are no normative references in this document.

-
- - - Normative References 2. - <fn reference="1"> - <p id="_">A</p> - </fn> - - - - - Bibliography - <fn reference="1"> - <p id="_">A</p> - </fn> - - - - - Bibliography 2. - <fn reference="1"> - <p id="_">A</p> - </fn> - - - Bibliography Subsection - - -
- + + Abstract +

Text

+
+ + + Foreword + <fn reference="1"> + <p id="_">A</p> + </fn> + +

Text

+
+ + Introduction + + Introduction Subsection + + + + Dedication + + + + Acknowledgements + <fn reference="1"> + <p id="_">A</p> + </fn> + + + + + + + Scope + <fn reference="1"> + <p id="_">A</p> + </fn> + +

Text

+
+ + + Terms and definitions + <fn reference="1"> + <p id="_">A</p> + </fn> + +

For the purposes of this document, the following terms and definitions apply.

+ + + + Term1 + + + +
+ + + Terms, definitions, symbols and abbreviated terms + <fn reference="1"> + <p id="_">A</p> + </fn> + +

For the purposes of this document, the following terms and definitions apply.

+ + Introduction + + Intro 1 + + + + Intro 2 + + Intro 3 + + + + Intro 4 + + Intro 5 + + + + Term1 + + + + + + + Normal Terms + + + + Term2 + + + + + + + Symbols and abbreviated terms + <fn reference="1"> + <p id="_">A</p> + </fn> + + + General + + + + Symbols + <fn reference="1"> + <p id="_">A</p> + </fn> + + + +
+ + + Abbreviated terms + <fn reference="1"> + <p id="_">A</p> + </fn> + + + + Clause 4 + + Introduction + + + Clause 4.2 + + + + Terms and Definitions + +
+ + + Annex. + <fn reference="1"> + <p id="_">A</p> + </fn> + + + Annex A.1 + + + + + + Normative references + <fn reference="1"> + <p id="_">A</p> + </fn> + +

There are no normative references in this document.

+
+ + + Normative References 2. + <fn reference="1"> + <p id="_">A</p> + </fn> + + + + + Bibliography + <fn reference="1"> + <p id="_">A</p> + </fn> + + + + + Bibliography 2. + <fn reference="1"> + <p id="_">A</p> + </fn> + + + Bibliography Subsection + + +
+ OUTPUT xml = Nokogiri::XML(Asciidoctor.convert(input, *OPTIONS)) xml.at("//xmlns:metanorma-extension")&.remove @@ -594,124 +603,133 @@ standoc - - - Abstract -

Text

-
- - Foreword -

Text

-
- - Introduction - - Introduction Subsection - - - - Dedication - - - Acknowledgements - -
- - - Scope -

Text

-
- - Terms and definitions -

For the purposes of this document, the following terms and definitions apply.

- - - - Term1 - - - -
- - Terms, Definitions, Symbols and Abbreviated Terms - - Introduction - - Intro 1 - - - - Intro 2 - - Intro 3 - - - - Intro 4 - - Intro 5 - - Term1 - - - - - Normal Terms - - Term2 - - - - Symbols and abbreviated terms - - General - - - Symbols - - - - - Abbreviated terms - - - Clause 4 - - Introduction - - - Clause 4.2 - - - - Terms and Definitions - -
- - Annex - - Annex A.1 - - - - - Normative references -

There are no normative references in this document.

-
- - Normative References 2 - - - Bibliography - - - Bibliography 2 - - Bibliography Subsection - - -
- + + + Abstract +

Text

+
+ + Foreword +

Text

+
+ + Introduction + + Introduction Subsection + + + + Dedication + + + Acknowledgements + +
+ + + Scope +

Text

+
+ + Terms and definitions +

For the purposes of this document, the following terms and definitions apply.

+ + + + Term1 + + + +
+ + Terms, definitions, symbols and abbreviated terms +

For the purposes of this document, the following terms and definitions apply.

+ + Introduction + + Intro 1 + + + + Intro 2 + + Intro 3 + + + + Intro 4 + + Intro 5 + + + + Term1 + + + + + + + Normal Terms + + + + Term2 + + + + + + Symbols and abbreviated terms + + General + + + Symbols + + +
+ + Abbreviated terms + + + Clause 4 + + Introduction + + + Clause 4.2 + + + + Terms and Definitions + +
+ + Annex + + Annex A.1 + + + + + Normative references +

There are no normative references in this document.

+
+ + Normative References 2 + + + Bibliography + + + Bibliography 2 + + Bibliography Subsection + + +
+ OUTPUT xml = Nokogiri::XML(Asciidoctor.convert(input, *OPTIONS)) xml.at("//xmlns:metanorma-extension")&.remove @@ -835,124 +853,133 @@ standoc - - - Résumé -

Text

-
- - Avant-propos -

Text

-
- - Introduction - - Introduction Subsection - - - - Dedication - - - Remerciements - -
- - - Domaine d’application -

Text

-
- - Termes et définitions -

Pour les besoins du présent document, les termes et définitions suivants s’appliquent.

- - - - Term1 - - - -
- - Terms, Definitions, Symbols and Abbreviated Terms - - Introduction - - Intro 1 - - - - Intro 2 - - Intro 3 - - - - Intro 4 - - Intro 5 - - Term1 - - - - - Normal Terms - - Term2 - - - - Symboles et termes abrégés - - General - - - Symboles - - - - - Termes abrégés - - - Clause 4 - - Introduction - - - Clause 4.2 - - - - Terms and Definitions - -
- - Annex - - Annex A.1 - - - - - Références normatives -

Le présent document ne contient aucune référence normative.

-
- - Normative References 2 - - - Bibliographie - - - Bibliography 2 - - Bibliography Subsection - - -
- + + + Résumé +

Text

+
+ + Avant-propos +

Text

+
+ + Introduction + + Introduction Subsection + + + + Dedication + + + Remerciements + +
+ + + Domaine d’application +

Text

+
+ + Termes et définitions +

Pour les besoins du présent document, les termes et définitions suivants s’appliquent.

+ + + + Term1 + + + +
+ + Termes, définitions, symboles et termes abrégés +

Pour les besoins du présent document, les termes et définitions suivants s’appliquent.

+ + Introduction + + Intro 1 + + + + Intro 2 + + Intro 3 + + + + Intro 4 + + Intro 5 + + + + Term1 + + + + + + + Normal Terms + + + + Term2 + + + + + + Symboles et termes abrégés + + General + + + Symboles + + +
+ + Termes abrégés + + + Clause 4 + + Introduction + + + Clause 4.2 + + + + Terms and Definitions + +
+ + Annex + + Annex A.1 + + + + + Références normatives +

Le présent document ne contient aucune référence normative.

+
+ + Normative References 2 + + + Bibliographie + + + Bibliography 2 + + Bibliography Subsection + + +
+ OUTPUT xml = Nokogiri::XML(Asciidoctor.convert(input, *OPTIONS)) xml.at("//xmlns:metanorma-extension")&.remove @@ -1076,124 +1103,133 @@ standoc - - - 摘要 -

Text

-
- - 前言 -

Text

-
- - 引言 - - Introduction Subsection - - - - Dedication - - - 致謝 - -
- - - 范围 -

Text

-
- - 术语和定义 -

下列术语和定义适用于本文件。

- - - - Term1 - - - -
- - Terms, Definitions, Symbols and Abbreviated Terms - - Introduction - - Intro 1 - - - - Intro 2 - - Intro 3 - - - - Intro 4 - - Intro 5 - - Term1 - - - - - Normal Terms - - Term2 - - - - 符号、代号和缩略语 - - General - - - 符号 - - - - - 代号和缩略语 - - - Clause 4 - - Introduction - - - Clause 4.2 - - - - Terms and Definitions - -
- - Annex - - Annex A.1 - - - - - 规范性引用文件 -

本文件并没有规范性引用文件。

-
- - Normative References 2 - - - 参考文献 - - - Bibliography 2 - - Bibliography Subsection - - -
- + + + 摘要 +

Text

+
+ + 前言 +

Text

+
+ + 引言 + + Introduction Subsection + + + + Dedication + + + 致謝 + +
+ + + 范围 +

Text

+
+ + 术语和定义 +

下列术语和定义适用于本文件。

+ + + + Term1 + + + +
+ + 术语、定义、符号、代号和缩略语 +

下列术语和定义适用于本文件。

+ + Introduction + + Intro 1 + + + + Intro 2 + + Intro 3 + + + + Intro 4 + + Intro 5 + + + + Term1 + + + + + + + Normal Terms + + + + Term2 + + + + + + 符号、代号和缩略语 + + General + + + 符号 + + +
+ + 代号和缩略语 + + + Clause 4 + + Introduction + + + Clause 4.2 + + + + Terms and Definitions + +
+ + Annex + + Annex A.1 + + + + + 规范性引用文件 +

本文件并没有规范性引用文件。

+
+ + Normative References 2 + + + 参考文献 + + + Bibliography 2 + + Bibliography Subsection + + +
+ OUTPUT xml = Nokogiri::XML(Asciidoctor.convert(input, *OPTIONS)) xml.at("//xmlns:metanorma-extension")&.remove @@ -1317,124 +1353,133 @@ standoc - - - Abstract -

Text

-
- - Antaŭparolo -

Text

-
- - Enkonduko - - Introduction Subsection - - - - Dedication - - - Acknowledgements - -
- - - Amplekso -

Text

-
- - Terms and definitions -

For the purposes of this document, the following terms and definitions apply.

- - - - Term1 - - - -
- - Terms, Definitions, Symbols and Abbreviated Terms - - Introduction - - Intro 1 - - - - Intro 2 - - Intro 3 - - - - Intro 4 - - Intro 5 - - Term1 - - - - - Normal Terms - - Term2 - - - - Symbols and abbreviated terms - - General - - - Simboloj kai mallongigitaj terminoj - - - - - Abbreviated terms - - - Clause 4 - - Introduction - - - Clause 4.2 - - - - Terms and Definitions - -
- - Annex - - Annex A.1 - - - - - Normaj citaĵoj -

There are no normative references in this document.

-
- - Normative References 2 - - - Bibliografio - - - Bibliography 2 - - Bibliography Subsection - - -
- + + + Abstract +

Text

+
+ + Antaŭparolo +

Text

+
+ + Enkonduko + + Introduction Subsection + + + + Dedication + + + Acknowledgements + +
+ + + Amplekso +

Text

+
+ + Terms and definitions +

For the purposes of this document, the following terms and definitions apply.

+ + + + Term1 + + + +
+ + Terms, definitions, symbols and abbreviated terms +

For the purposes of this document, the following terms and definitions apply.

+ + Introduction + + Intro 1 + + + + Intro 2 + + Intro 3 + + + + Intro 4 + + Intro 5 + + + + Term1 + + + + + + + Normal Terms + + + + Term2 + + + + + + Symbols and abbreviated terms + + General + + + Simboloj kai mallongigitaj terminoj + + +
+ + Abbreviated terms + + + Clause 4 + + Introduction + + + Clause 4.2 + + + + Terms and Definitions + +
+ + Annex + + Annex A.1 + + + + + Normaj citaĵoj +

There are no normative references in this document.

+
+ + Normative References 2 + + + Bibliografio + + + Bibliography 2 + + Bibliography Subsection + + +
+ OUTPUT xml = Nokogiri::XML(Asciidoctor.convert(input, *OPTIONS)) xml.at("//xmlns:metanorma-extension")&.remove diff --git a/spec/metanorma/section_spec.rb b/spec/metanorma/section_spec.rb index 28c50045..89ec51ed 100644 --- a/spec/metanorma/section_spec.rb +++ b/spec/metanorma/section_spec.rb @@ -1879,4 +1879,88 @@ expect(Xml::C14n.format(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to Xml::C14n.format(output) end + + it "ignores second terms section" do + input = <<~INPUT + #{ASCIIDOC_BLANK_HDR} + + == Terms and definitions + + === Term1 + + == Terms and definitions + + === Term2 + INPUT + output = <<~OUTPUT + #{BLANK_HDR} + + + Terms and definitions +

For the purposes of this document, the following terms and definitions apply.

+ + + + Term1 + + + +
+ + Terms and definitions + + Term2 + + +
+ + OUTPUT + expect(Xml::C14n.format(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) + .to be_equivalent_to Xml::C14n.format(output) + end + + it "does not ignore second terms section if specified as heading" do + input = <<~INPUT + #{ASCIIDOC_BLANK_HDR} + + == Terms and definitions + + === Term1 + + [heading="Terms and definitions"] + == Terms and definitions + + === Term2 + INPUT + output = <<~OUTPUT + #{BLANK_HDR} + + + Terms and definitions +

For the purposes of this document, the following terms and definitions apply.

+ + + + Term1 + + + +
+ + Terms and definitions +

For the purposes of this document, the following terms and definitions apply.

+ + + + Term2 + + + +
+
+ + OUTPUT + expect(Xml::C14n.format(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) + .to be_equivalent_to Xml::C14n.format(output) + end end