From 76157dba09e46545cee2db3ed89e297d4c3397bb Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Fri, 12 Jul 2024 02:17:38 +1000 Subject: [PATCH] parse titles that have become detached downstream from their clause parents: https://github.com/metanorma/metanorma-standoc/issues/742 --- isodoc.gemspec | 1 + lib/isodoc/function/section_titles.rb | 8 + lib/isodoc/function/to_word_html.rb | 1 + spec/isodoc/section_spec.rb | 1870 ------------------------ spec/isodoc/section_title_spec.rb | 1936 +++++++++++++++++++++++++ 5 files changed, 1946 insertions(+), 1870 deletions(-) create mode 100644 spec/isodoc/section_title_spec.rb diff --git a/isodoc.gemspec b/isodoc.gemspec index f345e832..d490e43c 100644 --- a/isodoc.gemspec +++ b/isodoc.gemspec @@ -44,6 +44,7 @@ Gem::Specification.new do |spec| spec.add_dependency "twitter_cldr", ">= 6.6.0" spec.add_dependency "uuidtools" + spec.add_development_dependency "bigdecimal" spec.add_development_dependency "debug" spec.add_development_dependency "equivalent-xml", "~> 0.6" spec.add_development_dependency "guard", "~> 2.14" diff --git a/lib/isodoc/function/section_titles.rb b/lib/isodoc/function/section_titles.rb index 1131746b..31199f8f 100644 --- a/lib/isodoc/function/section_titles.rb +++ b/lib/isodoc/function/section_titles.rb @@ -18,6 +18,14 @@ def inline_header_title(out, node, title) end end + def freestanding_title(node, out) + parents = node.ancestors("clause, annex, terms, references, " \ + "definitions, acknowledgements, introduction, " \ + "foreword") + clause_parse_title(parents.empty? ? node : parents.first, + out, node, out) + end + # used for subclauses def clause_parse_title(node, div, title, out, header_class = {}) return if title.nil? diff --git a/lib/isodoc/function/to_word_html.rb b/lib/isodoc/function/to_word_html.rb index 66e538c2..506c7d49 100644 --- a/lib/isodoc/function/to_word_html.rb +++ b/lib/isodoc/function/to_word_html.rb @@ -255,6 +255,7 @@ def parse(node, out) when "option" then option_parse(node, out) when "textarea" then textarea_parse(node, out) when "toc" then toc_parse(node, out) + when "title" then freestanding_title(node, out) # not inside clause when "variant-title" then variant_title(node, out) when "span" then span_parse(node, out) when "location" then location_parse(node, out) diff --git a/spec/isodoc/section_spec.rb b/spec/isodoc/section_spec.rb index 6d7e289a..6b168bed 100644 --- a/spec/isodoc/section_spec.rb +++ b/spec/isodoc/section_spec.rb @@ -124,1876 +124,6 @@ OUTPUT end - it "processes section names" do - input = <<~INPUT - - - - - Copyright - - - - - License - - - - - Legal - - - - - Feedback - - - - - - Abstract - - - Foreword -

This is a preamble

-
- Introduction - Introduction Subsection - - - Dedication - Note to reader - - Acknowledgements - -
-

Initial note

- - WARNING -

Initial admonition

- - Scope -

Text

-
- Terms, Definitions, Symbols and Abbreviated Terms - Normal Terms - - Term2 - - - - Definitions -
-
Symbol
-
Definition
-
-
-
- - Symbols and abbreviated terms -
-
Symbol
-
Definition
-
-
- Clause 4 - Introduction - - - Clause 4.2 - - - - -
- Annex - - Annex A.1 - - Annex A.1a - - - Annex Bibliography - - - - - - - Normative References - - Bibliography - - Bibliography Subsection - - - - - Index - - - - Postface 1 - - - Postface 2 - - -
- INPUT - - presxml = <<~PRESXML - - - - - Copyright - - - - - License - - - - - Legal - - - - - Feedback - - - - - - Table of contents - - - Abstract - - - Foreword -

This is a preamble

-
- - Introduction - - Introduction Subsection - - - - Dedication - - - Note to reader - - - Acknowledgements - -
- - - NOTE -

Initial note

-
- - WARNING -

Initial admonition

-
- - 1.<tab/>Scope -

Text

-
- - 3.<tab/>Terms, Definitions, Symbols and Abbreviated Terms - - 3.1.<tab/>Normal Terms - - 3.1.1. - Term2 - - - - 3.2.<tab/>Definitions -
-
Symbol
-
Definition
-
-
-
- - 4.<tab/>Symbols and abbreviated terms -
-
Symbol
-
Definition
-
-
- - 5.<tab/>Clause 4 - - 5.1.<tab/>Introduction - - - 5.2.<tab/>Clause 4.2 - - - 5.3. - - - - 2.<tab/>Normative References - -
- - - <strong>Annex A</strong> - <br/> - (normative) - <br/> - <br/> - <strong>Annex</strong> - - - A.1.<tab/>Annex A.1 - - A.1.1.<tab/>Annex A.1a - - - A.1.2.<tab/>Annex Bibliography - - - - - - <strong>Annex B</strong> - <br/> - (normative) - - - - - Bibliography - - Bibliography Subsection - - - - - - Postface 1 - - - Postface 2 - - -
- PRESXML - - html = <<~"OUTPUT" - #{HTML_HDR} -
- -
-
-

License

-
-
- -
-
-

Feedback

-
-
-
-
-
-

Abstract

-
-
-
-

Foreword

-

This is a preamble

-
-
-
-

Introduction

-
-

Introduction Subsection

-
-
-
-
-

Dedication

-
-
-
-

Note to reader

-
-
-
-

Acknowledgements

-
-
-

- NOTE -   Initial note -

-
-
-

WARNING

-

Initial admonition

-
-
-

1.  Scope

-

Text

-
-
-

2.  Normative References

-
-

3.  Terms, Definitions, Symbols and Abbreviated Terms

-
-

3.1.  Normal Terms

-

3.1.1.

-

Term2

-

3.2.  Definitions

-
-

Symbol

Definition
-
-
-
-

4.  Symbols and abbreviated terms

-
-
-
-

Symbol

-
-
Definition
-
-
-
-
-

5.  Clause 4

-
-

5.1.  Introduction

-
-
-

5.2.  Clause 4.2

-
-
-

5.3.

-
-
-
-
-

Annex A
(normative)

Annex

-
-

A.1.  Annex A.1

-
-

A.1.1.  Annex A.1a

-
-

A.1.2.  Annex Bibliography

-
-
-
-
-

- Annex B -
- (normative) -

-
-
-
-

Bibliography

-
-

Bibliography Subsection

-
-
-
-
-

Postface 1

-
-
-

Postface 2

-
- - - - - OUTPUT - - word = <<~OUTPUT - - - - -
-

 

-
-

-
-

-
-

-
-

-
-

Table of contents

-
-

-
-

-
-

- Abstract -
-
- Variant 1 -

-
-

-
-

-
-

- Foreword -
-
- Variant 1 -

-

This is a preamble

-
-

-
-

-
-

Introduction

-
-

- Introduction Subsection -
-
- Variant 1 -

-
-
-

-
-

-
-

- Dedication -
-
- Variant 1 -

-
-

-
-

-
-

- Note to reader -
-
- Variant 1 -

-
-

-
-

-
-

- Acknowledgements -
-
- Variant 1 -

-
-

 

-
-

-
-

-
-
-

- NOTE -   - Initial note -

-
-
-

WARNING

-

Initial admonition

-
-
-

- 1. -   - Scope -
-
- Variant 1 -

-

Text

-
-
-

- 2. -   - Normative References -
-
- Variant 1 -

-
-
-

- 3. -   - Terms, Definitions, Symbols and Abbreviated Terms -
-
- Variant 1 -

-
-

- 3.1. -   - Normal Terms -
-
- Variant 1 -

-

3.1.1.

-

Term2

-
-
-

- 3.2. -   - Definitions -
-
- Variant 1 -

- - - - - -
-

Symbol

-
Definition
-
-
-
-

- 4. -   - Symbols and abbreviated terms -
-
- Variant 1 -

- - - - - -
-

Symbol

-
Definition
-
-
-

- 5. -   - Clause 4 -
-
- Variant 1 -

-
-

- 5.1. -   - Introduction -
-
- Variant 1 -

-
-
-

- 5.2. -   - Clause 4.2 -
-
- Variant 1 -

-
-
-

5.3.

-
-
-

-
-

-
-

- Annex A -
- (normative) -
-
- Annex -
-
- Variant 1 -

- -
-

- A.1. -   - Annex A.1 -
-
- Variant 1 -

-
-

- A.1.1. -   - Annex A.1a -
-
- Variant 1 -

-
-
-

- A.1.2. -   - Annex Bibliography -
-
- Variant 1 -

-
-
-
-

-
-

-
-

- Annex B -
- (normative) -

-
-

-
-

-
-

Bibliography

- -
-

- Bibliography Subsection -
-
- Variant 1 -

-
-
-
- - - OUTPUT - presxml = IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true) - expect(xmlpp(strip_guid(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true)))).to be_equivalent_to xmlpp(html) - expect(xmlpp(strip_guid(IsoDoc::WordConvert.new({}) - .convert("test", presxml, true)))).to be_equivalent_to xmlpp(word) - end - - it "processes section names suppressing section numbering" do - input = <<~INPUT - - - - Foreword -

This is a preamble

-
- Introduction - Introduction Subsection - -
- - Scope -

Text

-
- - Terms, Definitions, Symbols and Abbreviated Terms - Normal Terms - - Term2 - - - -
-
Symbol
-
Definition
-
-
-
- -
-
Symbol
-
Definition
-
-
- Clause 4 - Introduction - - - Clause 4.2 - - - - - -
- Annex - - Annex A.1 - - Annex A.1a - - - - Normative References - - Bibliography - - Bibliography Subsection - - - -
- INPUT - output = <<~OUTPUT - - - - Table of contents - - - Foreword -

This is a preamble

-
- - Introduction - - Introduction Subsection - - -
- - - Scope -

Text

-
- - Terms, Definitions, Symbols and Abbreviated Terms - - Normal Terms - - 3.1.1. - Term2 - - - -
-
Symbol
-
Definition
-
-
-
- -
-
Symbol
-
Definition
-
-
- - Clause 4 - - Introduction - - - Clause 4.2 - - - - - Normative References - -
- - - <strong>Annex A</strong> - <br/> - (normative) - <br/> - <br/> - <strong>Annex</strong> - - - Annex A.1 - - Annex A.1a - - - - - - Bibliography - - Bibliography Subsection - - - -
- OUTPUT - expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert - .new({ suppressheadingnumbers: true } - .merge(presxml_options)) - .convert("test", input, true)))).to be_equivalent_to xmlpp(output) - end - - it "processes unnumbered section names" do - input = <<~INPUT - - - - Scope -

Text

-
- Terms, Definitions, Symbols and Abbreviated Terms - Normal Terms - - Term2 - - - -
-
Symbol
-
Definition
-
-
-
- -
-
Symbol
-
Definition
-
-
- Clause 4 - - Introduction - - - Clause 4.2 - - - - - - - - - -
- Annex - - Annex A.1 - - Annex A.1a - - - - Normative References - - Bibliography - - Bibliography Subsection - - - -
- INPUT - output = <<~OUTPUT - - - - Table of contents - - - - - Scope -

Text

-
- - Terms, Definitions, Symbols and Abbreviated Terms - - Normal Terms - - - Term2 - - - - -
-
Symbol
-
Definition
-
-
-
- -
-
Symbol
-
Definition
-
-
- - Clause 4 - - Introduction - - - Clause 4.2 - - - - 1. - - - - - 2. - - - Normative References - -
- - <strong>Annex </strong><br/>(normative)<br/><br/><strong>Annex</strong> - - .1.<tab/>Annex A.1 - - .1.1.<tab/>Annex A.1a - - - - - - Bibliography - - Bibliography Subsection - - - -
- OUTPUT - expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert - .new(presxml_options) - .convert("test", input, true)))).to be_equivalent_to xmlpp(output) - end - - it "processes floating titles" do - input = <<~INPUT - - - A0

- - Introduction - A

- - Introduction Subsection - B

- - Introduction Sub-subsection - C

-
-
-
-
- - - Introduction - A

- - Introduction Subsection - B

- - Introduction Sub-subsection - C

-
-
-
- D

- Clause 2 -
-
- INPUT - - presxml = <<~PRESXML - - - - Table of contents - -

A0

- - Introduction -

A

- - Introduction Subsection -

B

- - Introduction Sub-subsection -

C

-
-
-
-
- - - - 1. - <tab/> - Introduction - -

A

- - - 1.1. - <tab/> - Introduction Subsection - -

B

- - - 1.1.1. - <tab/> - Introduction Sub-subsection - -

C

-
-
-
-

D

- - - 2. - <tab/> - Clause 2 - - -
-
- PRESXML - - html = <<~OUTPUT - #{HTML_HDR} -

A0

-
-
-

Introduction

-

A

-
-

Introduction Subsection

-

B

-
-

Introduction Sub-subsection

-

C

-
-
-
-
-

1.   Introduction

-

A

-
-

1.1.   Introduction Subsection

-

B

-
-

1.1.1.   Introduction Sub-subsection

-

C

-
-
-
-

D

-
-

2.   Clause 2

-
- - - - OUTPUT - - word = <<~OUTPUT - -


-

A0

-

 


- 1. -   - Introduction -

A

- 1.1. -   - Introduction Subsection -

B

- 1.1.1. -   - Introduction Sub-subsection -

C

D

- 2. -   - Clause 2 -

- - OUTPUT - expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true)))).to be_equivalent_to xmlpp(presxml) - expect(xmlpp(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true))).to be_equivalent_to xmlpp(html) - IsoDoc::WordConvert.new({}).convert("test", presxml, false) - expect(xmlpp(File.read("test.doc") - .sub(/^.*.*$}m, ""))) - .to be_equivalent_to xmlpp(word) - end - - it "processes section titles without ID" do - input = <<~INPUT - - - Introduction - Introduction Subsection - - - - - INPUT - output = <<~OUTPUT - - - - - Table of contents - - - Introduction - - Introduction Subsection - - - - - OUTPUT - expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert - .new({ suppressheadingnumbers: true } - .merge(presxml_options)) - .convert("test", input, true)))).to be_equivalent_to xmlpp(output) - end - - it "processes inline section headers" do - input = <<~INPUT - - - Clause 4 - Introduction - - - Clause 4.2 -

ABC

-
- -
-
- INPUT - - presxml = <<~PRESXML - - - - Table of contents - - - - - 1.<tab/>Clause 4 - - 1.1.<tab/>Introduction - - - 1.2.<tab/>Clause 4.2 -

ABC

-
-
-
-
- PRESXML - - output = <<~"OUTPUT" - #{HTML_HDR} -
-

1.  Clause 4

-
-

1.1.  Introduction

-
-
- 1.2.  Clause 4.2  -

ABC

-
-
-
- - - OUTPUT - expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true)))).to be_equivalent_to xmlpp(presxml) - expect(xmlpp(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true))).to be_equivalent_to xmlpp(output) - end - - it "processes inline section headers with suppressed heading numbering" do - input = <<~INPUT - - - Clause 4 - Introduction - - - Clause 4.2 - - - - - INPUT - expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert - .new({ suppressheadingnumbers: true } - .merge(presxml_options)) - .convert("test", input, true)))) - .to be_equivalent_to xmlpp(<<~OUTPUT) - - Table of contents - - - Clause 4 - - Introduction - - - Clause 4.2 - - - - - OUTPUT - end - - it "processes sections without titles" do - input = <<~INPUT - - - - Intro - - - - - - - - - - - - - INPUT - output = <<~OUTPUT - - - - Table of contents - - - Intro - - - - - - - 1. - - 1.1. - - - 1.2. - - - - - OUTPUT - expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true)))).to be_equivalent_to xmlpp(output) - end - it "processes indexsect" do input = <<~INPUT diff --git a/spec/isodoc/section_title_spec.rb b/spec/isodoc/section_title_spec.rb new file mode 100644 index 00000000..b931812f --- /dev/null +++ b/spec/isodoc/section_title_spec.rb @@ -0,0 +1,1936 @@ +require "spec_helper" + +RSpec.describe IsoDoc do + it "processes section names" do + input = <<~INPUT + + + + + Copyright + + + + + License + + + + + Legal + + + + + Feedback + + + + + + Abstract + + + Foreword +

This is a preamble

+
+ Introduction + Introduction Subsection + + + Dedication + Note to reader + + Acknowledgements + +
+

Initial note

+ + WARNING +

Initial admonition

+ + Scope +

Text

+
+ Terms, Definitions, Symbols and Abbreviated Terms + Normal Terms + + Term2 + + + + Definitions +
+
Symbol
+
Definition
+
+
+
+ + Symbols and abbreviated terms +
+
Symbol
+
Definition
+
+
+ Clause 4 + Introduction + + + Clause 4.2 + + + + +
+ Annex + + Annex A.1 + + Annex A.1a + + + Annex Bibliography + + + + + + + Normative References + + Bibliography + + Bibliography Subsection + + + + + Index + + + + Postface 1 + + + Postface 2 + + +
+ INPUT + + presxml = <<~PRESXML + + + + + Copyright + + + + + License + + + + + Legal + + + + + Feedback + + + + + + Table of contents + + + Abstract + + + Foreword +

This is a preamble

+
+ + Introduction + + Introduction Subsection + + + + Dedication + + + Note to reader + + + Acknowledgements + +
+ + + NOTE +

Initial note

+
+ + WARNING +

Initial admonition

+
+ + 1.<tab/>Scope +

Text

+
+ + 3.<tab/>Terms, Definitions, Symbols and Abbreviated Terms + + 3.1.<tab/>Normal Terms + + 3.1.1. + Term2 + + + + 3.2.<tab/>Definitions +
+
Symbol
+
Definition
+
+
+
+ + 4.<tab/>Symbols and abbreviated terms +
+
Symbol
+
Definition
+
+
+ + 5.<tab/>Clause 4 + + 5.1.<tab/>Introduction + + + 5.2.<tab/>Clause 4.2 + + + 5.3. + + + + 2.<tab/>Normative References + +
+ + + <strong>Annex A</strong> + <br/> + (normative) + <br/> + <br/> + <strong>Annex</strong> + + + A.1.<tab/>Annex A.1 + + A.1.1.<tab/>Annex A.1a + + + A.1.2.<tab/>Annex Bibliography + + + + + + <strong>Annex B</strong> + <br/> + (normative) + + + + + Bibliography + + Bibliography Subsection + + + + + + Postface 1 + + + Postface 2 + + +
+ PRESXML + + html = <<~"OUTPUT" + #{HTML_HDR} +
+ +
+
+

License

+
+
+ +
+
+

Feedback

+
+
+
+
+
+

Abstract

+
+
+
+

Foreword

+

This is a preamble

+
+
+
+

Introduction

+
+

Introduction Subsection

+
+
+
+
+

Dedication

+
+
+
+

Note to reader

+
+
+
+

Acknowledgements

+
+
+

+ NOTE +   Initial note +

+
+
+

WARNING

+

Initial admonition

+
+
+

1.  Scope

+

Text

+
+
+

2.  Normative References

+
+

3.  Terms, Definitions, Symbols and Abbreviated Terms

+
+

3.1.  Normal Terms

+

3.1.1.

+

Term2

+

3.2.  Definitions

+
+

Symbol

Definition
+
+
+
+

4.  Symbols and abbreviated terms

+
+
+
+

Symbol

+
+
Definition
+
+
+
+
+

5.  Clause 4

+
+

5.1.  Introduction

+
+
+

5.2.  Clause 4.2

+
+
+

5.3.

+
+
+
+
+

Annex A
(normative)

Annex

+
+

A.1.  Annex A.1

+
+

A.1.1.  Annex A.1a

+
+

A.1.2.  Annex Bibliography

+
+
+
+
+

+ Annex B +
+ (normative) +

+
+
+
+

Bibliography

+
+

Bibliography Subsection

+
+
+
+
+

Postface 1

+
+
+

Postface 2

+
+ + + + + OUTPUT + + word = <<~OUTPUT + + + + +
+

 

+
+

+
+

+
+

+
+

+
+

Table of contents

+
+

+
+

+
+

+ Abstract +
+
+ Variant 1 +

+
+

+
+

+
+

+ Foreword +
+
+ Variant 1 +

+

This is a preamble

+
+

+
+

+
+

Introduction

+
+

+ Introduction Subsection +
+
+ Variant 1 +

+
+
+

+
+

+
+

+ Dedication +
+
+ Variant 1 +

+
+

+
+

+
+

+ Note to reader +
+
+ Variant 1 +

+
+

+
+

+
+

+ Acknowledgements +
+
+ Variant 1 +

+
+

 

+
+

+
+

+
+
+

+ NOTE +   + Initial note +

+
+
+

WARNING

+

Initial admonition

+
+
+

+ 1. +   + Scope +
+
+ Variant 1 +

+

Text

+
+
+

+ 2. +   + Normative References +
+
+ Variant 1 +

+
+
+

+ 3. +   + Terms, Definitions, Symbols and Abbreviated Terms +
+
+ Variant 1 +

+
+

+ 3.1. +   + Normal Terms +
+
+ Variant 1 +

+

3.1.1.

+

Term2

+
+
+

+ 3.2. +   + Definitions +
+
+ Variant 1 +

+ + + + + +
+

Symbol

+
Definition
+
+
+
+

+ 4. +   + Symbols and abbreviated terms +
+
+ Variant 1 +

+ + + + + +
+

Symbol

+
Definition
+
+
+

+ 5. +   + Clause 4 +
+
+ Variant 1 +

+
+

+ 5.1. +   + Introduction +
+
+ Variant 1 +

+
+
+

+ 5.2. +   + Clause 4.2 +
+
+ Variant 1 +

+
+
+

5.3.

+
+
+

+
+

+
+

+ Annex A +
+ (normative) +
+
+ Annex +
+
+ Variant 1 +

+ +
+

+ A.1. +   + Annex A.1 +
+
+ Variant 1 +

+
+

+ A.1.1. +   + Annex A.1a +
+
+ Variant 1 +

+
+
+

+ A.1.2. +   + Annex Bibliography +
+
+ Variant 1 +

+
+
+
+

+
+

+
+

+ Annex B +
+ (normative) +

+
+

+
+

+
+

Bibliography

+ +
+

+ Bibliography Subsection +
+
+ Variant 1 +

+
+
+
+ + + OUTPUT + presxml = IsoDoc::PresentationXMLConvert.new(presxml_options) + .convert("test", input, true) + expect(xmlpp(strip_guid(IsoDoc::HtmlConvert.new({}) + .convert("test", presxml, true)))).to be_equivalent_to xmlpp(html) + expect(xmlpp(strip_guid(IsoDoc::WordConvert.new({}) + .convert("test", presxml, true)))).to be_equivalent_to xmlpp(word) + end + + it "processes section names suppressing section numbering" do + input = <<~INPUT + + + + Foreword +

This is a preamble

+
+ Introduction + Introduction Subsection + +
+ + Scope +

Text

+
+ + Terms, Definitions, Symbols and Abbreviated Terms + Normal Terms + + Term2 + + + +
+
Symbol
+
Definition
+
+
+
+ +
+
Symbol
+
Definition
+
+
+ Clause 4 + Introduction + + + Clause 4.2 + + + + + +
+ Annex + + Annex A.1 + + Annex A.1a + + + + Normative References + + Bibliography + + Bibliography Subsection + + + +
+ INPUT + output = <<~OUTPUT + + + + Table of contents + + + Foreword +

This is a preamble

+
+ + Introduction + + Introduction Subsection + + +
+ + + Scope +

Text

+
+ + Terms, Definitions, Symbols and Abbreviated Terms + + Normal Terms + + 3.1.1. + Term2 + + + +
+
Symbol
+
Definition
+
+
+
+ +
+
Symbol
+
Definition
+
+
+ + Clause 4 + + Introduction + + + Clause 4.2 + + + + + Normative References + +
+ + + <strong>Annex A</strong> + <br/> + (normative) + <br/> + <br/> + <strong>Annex</strong> + + + Annex A.1 + + Annex A.1a + + + + + + Bibliography + + Bibliography Subsection + + + +
+ OUTPUT + expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert + .new({ suppressheadingnumbers: true } + .merge(presxml_options)) + .convert("test", input, true)))).to be_equivalent_to xmlpp(output) + end + + it "processes unnumbered section names" do + input = <<~INPUT + + + + Scope +

Text

+
+ Terms, Definitions, Symbols and Abbreviated Terms + Normal Terms + + Term2 + + + +
+
Symbol
+
Definition
+
+
+
+ +
+
Symbol
+
Definition
+
+
+ Clause 4 + + Introduction + + + Clause 4.2 + + + + + + + + + +
+ Annex + + Annex A.1 + + Annex A.1a + + + + Normative References + + Bibliography + + Bibliography Subsection + + + +
+ INPUT + output = <<~OUTPUT + + + + Table of contents + + + + + Scope +

Text

+
+ + Terms, Definitions, Symbols and Abbreviated Terms + + Normal Terms + + + Term2 + + + + +
+
Symbol
+
Definition
+
+
+
+ +
+
Symbol
+
Definition
+
+
+ + Clause 4 + + Introduction + + + Clause 4.2 + + + + 1. + + + + + 2. + + + Normative References + +
+ + <strong>Annex </strong><br/>(normative)<br/><br/><strong>Annex</strong> + + .1.<tab/>Annex A.1 + + .1.1.<tab/>Annex A.1a + + + + + + Bibliography + + Bibliography Subsection + + + +
+ OUTPUT + expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true)))).to be_equivalent_to xmlpp(output) + end + + it "processes floating titles" do + input = <<~INPUT + + + A0

+ + Introduction + A

+ + Introduction Subsection + B

+ + Introduction Sub-subsection + C

+
+
+
+
+ + + Introduction + A

+ + Introduction Subsection + B

+ + Introduction Sub-subsection + C

+
+
+
+ D

+ Clause 2 +
+
+ INPUT + + presxml = <<~PRESXML + + + + Table of contents + +

A0

+ + Introduction +

A

+ + Introduction Subsection +

B

+ + Introduction Sub-subsection +

C

+
+
+
+
+ + + + 1. + <tab/> + Introduction + +

A

+ + + 1.1. + <tab/> + Introduction Subsection + +

B

+ + + 1.1.1. + <tab/> + Introduction Sub-subsection + +

C

+
+
+
+

D

+ + + 2. + <tab/> + Clause 2 + + +
+
+ PRESXML + + html = <<~OUTPUT + #{HTML_HDR} +

A0

+
+
+

Introduction

+

A

+
+

Introduction Subsection

+

B

+
+

Introduction Sub-subsection

+

C

+
+
+
+
+

1.   Introduction

+

A

+
+

1.1.   Introduction Subsection

+

B

+
+

1.1.1.   Introduction Sub-subsection

+

C

+
+
+
+

D

+
+

2.   Clause 2

+
+ + + + OUTPUT + + word = <<~OUTPUT + +


+

A0

+

 


+ 1. +   + Introduction +

A

+ 1.1. +   + Introduction Subsection +

B

+ 1.1.1. +   + Introduction Sub-subsection +

C

D

+ 2. +   + Clause 2 +

+ + OUTPUT + expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) + .convert("test", input, true)))).to be_equivalent_to xmlpp(presxml) + expect(xmlpp(IsoDoc::HtmlConvert.new({}) + .convert("test", presxml, true))).to be_equivalent_to xmlpp(html) + IsoDoc::WordConvert.new({}).convert("test", presxml, false) + expect(xmlpp(File.read("test.doc") + .sub(/^.*.*$}m, ""))) + .to be_equivalent_to xmlpp(word) + end + + it "processes section titles without ID" do + input = <<~INPUT + + + Introduction + Introduction Subsection + + + + + INPUT + output = <<~OUTPUT + + + + + Table of contents + + + Introduction + + Introduction Subsection + + + + + OUTPUT + expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert + .new({ suppressheadingnumbers: true } + .merge(presxml_options)) + .convert("test", input, true)))).to be_equivalent_to xmlpp(output) + end + + it "processes inline section headers" do + input = <<~INPUT + + + Clause 4 + Introduction + + + Clause 4.2 +

ABC

+
+ +
+
+ INPUT + + presxml = <<~PRESXML + + + + Table of contents + + + + + 1.<tab/>Clause 4 + + 1.1.<tab/>Introduction + + + 1.2.<tab/>Clause 4.2 +

ABC

+
+
+
+
+ PRESXML + + output = <<~"OUTPUT" + #{HTML_HDR} +
+

1.  Clause 4

+
+

1.1.  Introduction

+
+
+ 1.2.  Clause 4.2  +

ABC

+
+
+
+ + + OUTPUT + expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) + .convert("test", input, true)))).to be_equivalent_to xmlpp(presxml) + expect(xmlpp(IsoDoc::HtmlConvert.new({}) + .convert("test", presxml, true))).to be_equivalent_to xmlpp(output) + end + + it "processes inline section headers with suppressed heading numbering" do + input = <<~INPUT + + + Clause 4 + Introduction + + + Clause 4.2 + + + + + INPUT + expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert + .new({ suppressheadingnumbers: true } + .merge(presxml_options)) + .convert("test", input, true)))) + .to be_equivalent_to xmlpp(<<~OUTPUT) + + Table of contents + + + Clause 4 + + Introduction + + + Clause 4.2 + + + + + OUTPUT + end + + it "processes sections without titles" do + input = <<~INPUT + + + + Intro + + + + + + + + + + + + + INPUT + output = <<~OUTPUT + + + + Table of contents + + + Intro + + + + + + + 1. + + 1.1. + + + 1.2. + + + + + OUTPUT + expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) + .convert("test", input, true)))).to be_equivalent_to xmlpp(output) + end + + it "processes disconnected titles" do + input = <<~INPUT + + + + + + + + Title +

Para

+
+ + Iitre +

Alinée

+
+
+
+
+
+
+
+ INPUT + output = <<~OUTPUT + + + +
+

 

+
+
+
+

 

+
+
+
+
+

+
+
+ + + + + +
+

Title

+

Para

+
+

Iitre

+

Alinée

+
+
+
+

+
+ + + OUTPUT + expect(xmlpp(IsoDoc::HtmlConvert.new({}) + .convert("test", input, true))).to be_equivalent_to xmlpp(output) + end +end