asciidoctor-iso 0.9.9 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +7 -0
  3. data/README.adoc +49 -9
  4. data/asciidoctor-iso.gemspec +3 -3
  5. data/lib/asciidoctor-iso.rb +2 -0
  6. data/lib/asciidoctor/iso/base.rb +14 -0
  7. data/lib/asciidoctor/iso/blocks.rb +1 -1
  8. data/lib/asciidoctor/iso/cleanup.rb +2 -2
  9. data/lib/asciidoctor/iso/cleanup_ref.rb +1 -1
  10. data/lib/asciidoctor/iso/inline.rb +1 -1
  11. data/lib/asciidoctor/iso/macros.rb +54 -0
  12. data/lib/asciidoctor/iso/ref.rb +7 -2
  13. data/lib/asciidoctor/iso/validate.rb +8 -8
  14. data/lib/asciidoctor/iso/validate_requirements.rb +5 -5
  15. data/lib/asciidoctor/iso/version.rb +1 -1
  16. data/lib/isodoc/iso/html/header.html +206 -0
  17. data/lib/isodoc/iso/html/html_iso_intro.html +34 -0
  18. data/lib/isodoc/iso/html/html_iso_titlepage.html +34 -0
  19. data/lib/isodoc/iso/html/htmlstyle.scss +46 -0
  20. data/lib/isodoc/iso/html/isodoc.scss +696 -0
  21. data/lib/isodoc/iso/html/scripts.html +174 -0
  22. data/lib/isodoc/iso/html/style-human.scss +1277 -0
  23. data/lib/isodoc/iso/html/style-iso.scss +1257 -0
  24. data/lib/isodoc/iso/html/word_iso_intro.html +72 -0
  25. data/lib/isodoc/iso/html/word_iso_titlepage.html +62 -0
  26. data/lib/isodoc/iso/html/wordstyle.scss +1175 -0
  27. data/lib/isodoc/iso/html_convert.rb +136 -0
  28. data/lib/isodoc/iso/metadata.rb +107 -0
  29. data/lib/isodoc/iso/word_convert.rb +139 -0
  30. data/spec/asciidoctor-iso/isobib_cache_spec.rb +18 -4
  31. data/spec/asciidoctor-iso/macros_spec.rb +92 -1
  32. data/spec/asciidoctor-iso/validate_spec.rb +173 -144
  33. data/spec/assets/header.html +7 -0
  34. data/spec/assets/html.css +2 -0
  35. data/spec/assets/htmlcover.html +4 -0
  36. data/spec/assets/htmlintro.html +5 -0
  37. data/spec/assets/i18n.yaml +2 -0
  38. data/spec/assets/iso.doc +2312 -0
  39. data/spec/assets/iso.headless.html +33 -0
  40. data/spec/assets/iso.html +1388 -0
  41. data/spec/assets/iso.xml +8 -0
  42. data/spec/assets/rice_image1.png +0 -0
  43. data/spec/assets/scripts.html +3 -0
  44. data/spec/assets/std.css +2 -0
  45. data/spec/assets/word.css +2 -0
  46. data/spec/assets/wordcover.html +3 -0
  47. data/spec/assets/wordintro.html +4 -0
  48. data/spec/examples/103_01_02.html +247 -0
  49. data/spec/isodoc/i18n_spec.rb +642 -0
  50. data/spec/isodoc/iso_spec.rb +168 -0
  51. data/spec/isodoc/metadata_spec.rb +152 -0
  52. data/spec/isodoc/postproc_spec.rb +409 -0
  53. data/spec/isodoc/section_spec.rb +522 -0
  54. data/spec/isodoc/xref_spec.rb +1337 -0
  55. data/spec/spec_helper.rb +45 -0
  56. metadata +45 -9
@@ -0,0 +1,168 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe IsoDoc::Iso do
4
+ system "rm -f test.html"
5
+ it "processes isodoc as ISO: HTML output" do
6
+ IsoDoc::Iso::HtmlConvert.new({}).convert("test", <<~"INPUT", false)
7
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
8
+ <preface><foreword>
9
+ <note>
10
+ <p id="_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f">These results are based on a study carried out on three different types of kernel.</p>
11
+ </note>
12
+ </foreword></preface>
13
+ </iso-standard>
14
+ INPUT
15
+ html = File.read("test.html", encoding: "utf-8")
16
+ expect(html).to match(%r[\.Sourcecode[^{]+\{[^{]+font-family: "Courier New", monospace;]m)
17
+ expect(html).to match(%r[blockquote[^{]+\{[^{]+font-family: "Cambria", serif;]m)
18
+ expect(html).to match(%r[\.h2Annex[^{]+\{[^{]+font-family: "Cambria", serif;]m)
19
+ end
20
+
21
+ it "processes isodoc as ISO: alt HTML output" do
22
+ system "rm -f test.html"
23
+ IsoDoc::Iso::HtmlConvert.new({alt: true}).convert("test", <<~"INPUT", false)
24
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
25
+ <preface><foreword>
26
+ <note>
27
+ <p id="_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f">These results are based on a study carried out on three different types of kernel.</p>
28
+ </note>
29
+ </foreword></preface>
30
+ </iso-standard>
31
+ INPUT
32
+ html = File.read("test.html", encoding: "utf-8")
33
+ expect(html).to match(%r[\.Sourcecode[^{]+\{[^{]+font-family: "Space Mono", monospace;]m)
34
+ expect(html).to match(%r[blockquote[^{]+\{[^{]+font-family: "Lato", sans-serif;]m)
35
+ expect(html).to match(%r[\.h2Annex[^{]+\{[^{]+font-family: "Lato", sans-serif;]m)
36
+ end
37
+
38
+ it "processes isodoc as ISO: Chinese HTML output" do
39
+ system "rm -f test.html"
40
+ IsoDoc::Iso::HtmlConvert.new({script: "Hans"}).convert("test", <<~"INPUT", false)
41
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
42
+ <preface><foreword>
43
+ <note>
44
+ <p id="_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f">These results are based on a study carried out on three different types of kernel.</p>
45
+ </note>
46
+ </foreword></preface>
47
+ </iso-standard>
48
+ INPUT
49
+ html = File.read("test.html", encoding: "utf-8")
50
+ expect(html).to match(%r[\.Sourcecode[^{]+\{[^{]+font-family: "Courier New", monospace;]m)
51
+ expect(html).to match(%r[blockquote[^{]+\{[^{]+font-family: "SimSun", serif;]m)
52
+ expect(html).to match(%r[\.h2Annex[^{]+\{[^{]+font-family: "SimHei", sans-serif;]m)
53
+ end
54
+
55
+ it "processes isodoc as ISO: user nominated fonts" do
56
+ system "rm -f test.html"
57
+ IsoDoc::Iso::HtmlConvert.new({bodyfont: "Zapf Chancery", headerfont: "Comic Sans", monospacefont: "Andale Mono"}).convert("test", <<~"INPUT", false)
58
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
59
+ <preface><foreword>
60
+ <note>
61
+ <p id="_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f">These results are based on a study carried out on three different types of kernel.</p>
62
+ </note>
63
+ </foreword></preface>
64
+ </iso-standard>
65
+ INPUT
66
+ html = File.read("test.html", encoding: "utf-8")
67
+ expect(html).to match(%r[\.Sourcecode[^{]+\{[^{]+font-family: Andale Mono;]m)
68
+ expect(html).to match(%r[blockquote[^{]+\{[^{]+font-family: Zapf Chancery;]m)
69
+ expect(html).to match(%r[\.h2Annex[^{]+\{[^{]+font-family: Comic Sans;]m)
70
+ end
71
+
72
+ it "processes isodoc as ISO: Word output" do
73
+ system "rm -f test.doc"
74
+ IsoDoc::Iso::WordConvert.new({}).convert("test", <<~"INPUT", false)
75
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
76
+ <preface><foreword>
77
+ <note>
78
+ <p id="_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f">These results are based on a study carried out on three different types of kernel.</p>
79
+ </note>
80
+ </foreword></preface>
81
+ </iso-standard>
82
+ INPUT
83
+ html = File.read("test.doc", encoding: "utf-8")
84
+ expect(html).to match(%r[\.Sourcecode[^{]+\{[^{]+font-family: "Courier New", monospace;]m)
85
+ expect(html).to match(%r[Quote[^{]+\{[^{]+font-family: "Cambria", serif;]m)
86
+ expect(html).to match(%r[\.h2Annex[^{]+\{[^{]+font-family: "Cambria", serif;]m)
87
+ end
88
+
89
+ it "does not include IEV in references" do
90
+ expect(IsoDoc::Iso::HtmlConvert.new({}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT"
91
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
92
+ <preface><foreword>
93
+ <p id="_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f">
94
+ <eref bibitemid="IEV"/>
95
+ <eref bibitemid="ISO20483"/>
96
+ </p>
97
+ </foreword></preface>
98
+ <bibliography><references id="_normative_references" obligation="informative"><title>Normative References</title>
99
+ <bibitem type="international-standard" id="IEV">
100
+ <title format="text/plain" language="en" script="Latn">Electropedia:
101
+ The World's Online Electrotechnical Vocabulary</title>
102
+ <source type="src">http://www.electropedia.org</source>
103
+ <docidentifier>IEV</docidentifier>
104
+ <date type="published"> <on>2018</on> </date>
105
+ <contributor>
106
+ <role type="publisher"/>
107
+ <organization>
108
+ <name>International Electrotechnical Commission</name>
109
+ <abbreviation>IEC</abbreviation>
110
+ <uri>www.iec.ch</uri>
111
+ </organization>
112
+ </contributor>
113
+ <language>en</language> <language>fr</language>
114
+ <script>Latn</script>
115
+ <copyright>
116
+ <from>2018</from>
117
+ <owner>
118
+ <organization>
119
+ <name>International Electrotechnical Commission</name>
120
+ <abbreviation>IEC</abbreviation>
121
+ <uri>www.iec.ch</uri>
122
+ </organization>
123
+ </owner>
124
+ </copyright>
125
+ <relation type="updates">
126
+ <bibitem>
127
+ <formattedref>IEC 60050</formattedref>
128
+ </bibitem>
129
+ </relation>
130
+ </bibitem>
131
+ <bibitem id="ISO20483" type="standard">
132
+ <title format="text/plain">Cereals and pulses</title>
133
+ <docidentifier>ISO 20483</docidentifier>
134
+ <date type="published"><from>2013</from><to>2014</to></date>
135
+ <contributor>
136
+ <role type="publisher"/>
137
+ <organization>
138
+ <name>International Organization for Standardization</name>
139
+ </organization>
140
+ </contributor>
141
+ </bibitem>
142
+ </references>
143
+ </bibliography>
144
+ </iso-standard>
145
+ INPUT
146
+ #{HTML_HDR}
147
+ <br/>
148
+ <div>
149
+ <h1 class="ForewordTitle">Foreword</h1>
150
+ <p id="_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f">
151
+ <a href="#IEV">IEV:2018</a>
152
+ <a href="#ISO20483">ISO 20483:2013&#8211;2014</a>
153
+ </p>
154
+ </div>
155
+ <p class="zzSTDTitle1"/>
156
+ <div>
157
+ <h1>1.&#160; Normative references</h1>
158
+ <p>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.</p>
159
+ <p id="ISO20483" class="NormRef">ISO 20483:2013&#8211;2014, <i> Cereals and pulses</i></p>
160
+ </div>
161
+ </div>
162
+ </body>
163
+ </html>
164
+
165
+ OUTPUT
166
+ end
167
+
168
+ end
@@ -0,0 +1,152 @@
1
+ require "spec_helper"
2
+ require "nokogiri"
3
+
4
+ RSpec.describe IsoDoc::Iso::Metadata do
5
+ it "processes IsoXML metadata" do
6
+ c = IsoDoc::Iso::HtmlConvert.new({})
7
+ arr = c.convert_init(<<~"INPUT", "test", false)
8
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
9
+ INPUT
10
+ expect(Hash[c.info(Nokogiri::XML(<<~"INPUT"), nil).sort]).to be_equivalent_to <<~"OUTPUT"
11
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
12
+ <bibdata type="international-standard">
13
+ <title>
14
+ <title-intro language="en" format="text/plain">Cereals and pulses</title-intro>
15
+ <title-main language="en" format="text/plain">Specifications and test methods</title-main>
16
+ <title-part language="en" format="text/plain">Rice</title-part>
17
+ </title>
18
+ <title>
19
+ <title-intro language="fr" format="text/plain">Céréales et légumineuses</title-intro>
20
+ <title-main language="fr" format="text/plain">Spécification et méthodes d'essai</title-main>
21
+ <title-part language="fr" format="text/plain">Riz</title-part>
22
+ </title>
23
+ <docidentifier>
24
+ <project-number part="1">17301</project-number>
25
+ <tc-document-number>17301</tc-document-number>
26
+ </docidentifier>
27
+ <date type="published"><on>2011</on></date>
28
+ <date type="accessed"><on>2012</on></date>
29
+ <date type="created"><from>2010</from><to>2011</to></date>
30
+ <date type="activated"><on>2013</on></date>
31
+ <date type="obsoleted"><on>2014</on></date>
32
+ <contributor>
33
+ <role type="author"/>
34
+ <organization>
35
+ <abbreviation>ISO</abbreviation>
36
+ </organization>
37
+ </contributor>
38
+ <contributor>
39
+ <role type="publisher"/>
40
+ <organization>
41
+ <abbreviation>ISO</abbreviation>
42
+ </organization>
43
+ </contributor>
44
+ <language>en</language>
45
+ <script>Latn</script>
46
+ <status>
47
+ <stage>30</stage>
48
+ <substage>92</substage>
49
+ <iteration>3</iteration>
50
+ </status>
51
+ <copyright>
52
+ <from>2016</from>
53
+ <owner>
54
+ <organization>
55
+ <abbreviation>ISO</abbreviation>
56
+ </organization>
57
+ </owner>
58
+ </copyright>
59
+ <editorialgroup>
60
+ <technical-committee number="34">Food products</technical-committee>
61
+ <subcommittee number="4">Cereals and pulses</subcommittee>
62
+ <workgroup number="3">Rice Group</workgroup>
63
+ <secretariat>GB</secretariat>
64
+ </editorialgroup>
65
+ </bibdata><version>
66
+ <edition>2</edition>
67
+ <revision-date>2016-05-01</revision-date>
68
+ <draft>0.4</draft>
69
+ </version>
70
+ </iso-standard>
71
+ INPUT
72
+ {:accesseddate=>"2012", :activateddate=>"2013", :agency=>"ISO", :confirmeddate=>"XXX", :createddate=>"2010&ndash;2011", :docnumber=>"PreCD3 17301-1", :docsubtitle=>"C&#xe9;r&#xe9;ales et l&#xe9;gumineuses&nbsp;&mdash; Sp&#xe9;cification et m&#xe9;thodes d&#x27;essai&nbsp;&mdash; Partie&nbsp;1: Riz", :docsubtitleintro=>"C&#xe9;r&#xe9;ales et l&#xe9;gumineuses", :docsubtitlemain=>"Sp&#xe9;cification et m&#xe9;thodes d&#x27;essai", :docsubtitlepart=>"Partie&nbsp;1: Riz", :doctitle=>"Cereals and pulses&nbsp;&mdash; Specifications and test methods&nbsp;&mdash; Part&nbsp;1: Rice", :doctitleintro=>"Cereals and pulses", :doctitlemain=>"Specifications and test methods", :doctitlepart=>"Part&nbsp;1: Rice", :doctype=>"International Standard", :docyear=>"2016", :draft=>"0.4", :draftinfo=>" (draft 0.4, 2016-05-01)", :editorialgroup=>["TC 34", "SC 4", "WG 3"], :ics=>"XXX", :implementeddate=>"XXX", :issueddate=>"XXX", :obsoleteddate=>"2014", :obsoletes=>nil, :obsoletes_part=>nil, :publisheddate=>"2011", :revdate=>"2016-05-01", :sc=>"SC 4", :secretariat=>"GB", :stage=>"30", :stage_int=>30, :stageabbr=>"PreCD3", :tc=>"TC 34", :updateddate=>"XXX", :wg=>"WG 3"}
73
+ OUTPUT
74
+ end
75
+
76
+ it "processes IsoXML metadata" do
77
+ c = IsoDoc::Iso::HtmlConvert.new({})
78
+ arr = c.convert_init(<<~"INPUT", "test", false)
79
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
80
+ INPUT
81
+ expect(Hash[c.info(Nokogiri::XML(<<~"INPUT"), nil).sort]).to be_equivalent_to <<~"OUTPUT"
82
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
83
+ <bibdata type="international-standard">
84
+ <title>
85
+ <title-intro language="en" format="text/plain">Cereals and pulses</title-intro>
86
+ <title-main language="en" format="text/plain">Specifications and test methods</title-main>
87
+ <title-part language="en" format="text/plain">Rice</title-part>
88
+ </title>
89
+ <title>
90
+ <title-intro language="fr" format="text/plain">Céréales et légumineuses</title-intro>
91
+ <title-main language="fr" format="text/plain">Spécification et méthodes d'essai</title-main>
92
+ <title-part language="fr" format="text/plain">Riz</title-part>
93
+ </title>
94
+ <docidentifier>
95
+ <project-number part="1" subpart="3">17301</project-number>
96
+ <tc-document-number>17301</tc-document-number>
97
+ </docidentifier>
98
+ <contributor>
99
+ <role type="author"/>
100
+ <organization>
101
+ <name>ISO</name>
102
+ </organization>
103
+ </contributor>
104
+ <contributor>
105
+ <role type="publisher"/>
106
+ <organization>
107
+ <abbreviation>ISO</abbreviation>
108
+ </organization>
109
+ </contributor>
110
+ <contributor>
111
+ <role type="publisher"/>
112
+ <organization>
113
+ <abbreviation>IEC</abbreviation>
114
+ </organization>
115
+ </contributor>
116
+ <language>en</language>
117
+ <script>Latn</script>
118
+ <status>
119
+ <stage>30</stage>
120
+ <substage>92</substage>
121
+ </status>
122
+ <copyright>
123
+ <from>2016</from>
124
+ <owner>
125
+ <organization>
126
+ <name>International Organization for Standardization</name>
127
+ </organization>
128
+ </owner>
129
+ </copyright>
130
+ <relation type="obsoletes">
131
+ <locality type="clause"><referenceFrom>3.1</referenceFrom></locality>
132
+ <docidentifier>IEC 8121</docidentifier>
133
+ </relation>
134
+ <editorialgroup>
135
+ <technical-committee number="34" type="ABC">Food products</technical-committee>
136
+ <subcommittee number="4" type="DEF">Cereals and pulses</subcommittee>
137
+ <workgroup number="3" type="GHI">Rice Group</workgroup>
138
+ </editorialgroup>
139
+ <ics><code>1.2.3</code></ics>
140
+ <ics><code>1.2.3</code></ics>
141
+ </bibdata><version>
142
+ <edition>2</edition>
143
+ <revision-date>2016-05-01</revision-date>
144
+ <draft>12</draft>
145
+ </version>
146
+ </iso-standard>
147
+ INPUT
148
+ {:accesseddate=>"XXX", :agency=>"ISO/IEC", :confirmeddate=>"XXX", :createddate=>"XXX", :docnumber=>"CD 17301-1-3", :docsubtitle=>"C&#xe9;r&#xe9;ales et l&#xe9;gumineuses&nbsp;&mdash; Sp&#xe9;cification et m&#xe9;thodes d&#x27;essai&nbsp;&mdash; Partie&nbsp;1&ndash;3: Riz", :docsubtitleintro=>"C&#xe9;r&#xe9;ales et l&#xe9;gumineuses", :docsubtitlemain=>"Sp&#xe9;cification et m&#xe9;thodes d&#x27;essai", :docsubtitlepart=>"Partie&nbsp;1&ndash;3: Riz", :doctitle=>"Cereals and pulses&nbsp;&mdash; Specifications and test methods&nbsp;&mdash; Part&nbsp;1&ndash;3: Rice", :doctitleintro=>"Cereals and pulses", :doctitlemain=>"Specifications and test methods", :doctitlepart=>"Part&nbsp;1&ndash;3: Rice", :doctype=>"International Standard", :docyear=>"2016", :draft=>"12", :draftinfo=>" (draft 12, 2016-05-01)", :editorialgroup=>["ABC 34", "DEF 4", "GHI 3"], :ics=>"1.2.3, 1.2.3", :implementeddate=>"XXX", :issueddate=>"XXX", :obsoleteddate=>"XXX", :obsoletes=>"IEC 8121", :obsoletes_part=>"3.1", :publisheddate=>"XXX", :revdate=>"2016-05-01", :sc=>"DEF 4", :secretariat=>"XXXX", :stage=>"30", :stage_int=>30, :stageabbr=>"CD", :tc=>"ABC 34", :updateddate=>"XXX", :wg=>"GHI 3"}
149
+ OUTPUT
150
+ end
151
+
152
+ end
@@ -0,0 +1,409 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe IsoDoc do
4
+ it "generates file based on string input" do
5
+ system "rm -f test.doc"
6
+ system "rm -f test.html"
7
+ IsoDoc::Iso::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css", filename: "test"}).convert("test", <<~"INPUT", false)
8
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
9
+ <preface><foreword>
10
+ <note>
11
+ <p id="_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f">These results are based on a study carried out on three different types of kernel.</p>
12
+ </note>
13
+ </foreword></preface>
14
+ </iso-standard>
15
+ INPUT
16
+ expect(File.exist?("test.html")).to be true
17
+ html = File.read("test.html")
18
+ expect(html).to match(%r{<title>test</title><style>})
19
+ expect(html).to match(%r{cdnjs\.cloudflare\.com/ajax/libs/mathjax/2\.7\.1/MathJax\.js})
20
+ expect(html).to match(/delimiters: \[\['\(#\(', '\)#\)'\]\]/)
21
+ end
22
+
23
+ it "generates HTML output docs with null configuration" do
24
+ system "rm -f test.doc"
25
+ system "rm -f test.html"
26
+ IsoDoc::Iso::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("test", <<~"INPUT", false)
27
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
28
+ <preface><foreword>
29
+ <note>
30
+ <p id="_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f">These results are based on a study carried out on three different types of kernel.</p>
31
+ </note>
32
+ </foreword></preface>
33
+ </iso-standard>
34
+ INPUT
35
+ expect(File.exist?("test.html")).to be true
36
+ html = File.read("test.html")
37
+ expect(html).to match(%r{<title>test</title><style>})
38
+ expect(html).to match(%r{cdnjs\.cloudflare\.com/ajax/libs/mathjax/2\.7\.1/MathJax\.js})
39
+ expect(html).to match(/delimiters: \[\['\(#\(', '\)#\)'\]\]/)
40
+ end
41
+
42
+ it "generates Word output docs with null configuration" do
43
+ system "rm -f test.doc"
44
+ system "rm -f test.html"
45
+ IsoDoc::Iso::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("test", <<~"INPUT", false)
46
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
47
+ <preface><foreword>
48
+ <note>
49
+ <p id="_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f">These results are based on a study carried out on three different types of kernel.</p>
50
+ </note>
51
+ </foreword></preface>
52
+ </iso-standard>
53
+ INPUT
54
+ expect(File.exist?("test.doc")).to be true
55
+ word = File.read("test.doc")
56
+ expect(word).to match(/<style>/)
57
+ end
58
+
59
+ it "generates HTML output docs with null configuration from file" do
60
+ system "rm -f spec/assets/iso.doc"
61
+ system "rm -f spec/assets/iso.html"
62
+ IsoDoc::Iso::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("spec/assets/iso.xml", nil, false)
63
+ expect(File.exist?("spec/assets/iso.html")).to be true
64
+ html = File.read("spec/assets/iso.html")
65
+ expect(html).to match(/<style>/)
66
+ expect(html).to match(%r{https://use.fontawesome.com})
67
+ expect(html).to match(%r{libs/jquery})
68
+ end
69
+
70
+ it "generates Word output docs with null configuration from file" do
71
+ system "rm -f spec/assets/iso.doc"
72
+ IsoDoc::Iso::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("spec/assets/iso.xml", nil, false)
73
+ expect(File.exist?("spec/assets/iso.doc")).to be true
74
+ word = File.read("spec/assets/iso.doc")
75
+ expect(word).to match(/<w:WordDocument>/)
76
+ expect(word).to match(/<style>/)
77
+ end
78
+
79
+ it "converts annex subheadings to h2Annex class for Word" do
80
+ system "rm -f test.doc"
81
+ system "rm -f test.html"
82
+ IsoDoc::Iso::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("test", <<~"INPUT", false)
83
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
84
+ <annex id="P" inline-header="false" obligation="normative">
85
+ <title>Annex</title>
86
+ <clause id="Q" inline-header="false" obligation="normative">
87
+ <title>Annex A.1</title>
88
+ </clause>
89
+ <appendix id="Q2" inline-header="false" obligation="normative">
90
+ <title>An Appendix</title>
91
+ </appendix>
92
+ </annex>
93
+ </iso-standard>
94
+ INPUT
95
+ word = File.read("test.doc").sub(/^.*<div class="WordSection3">/m, '<div class="WordSection3">').
96
+ sub(%r{<div style="mso-element:footnote-list"/>.*$}m, "")
97
+ expect(word).to be_equivalent_to <<~"OUTPUT"
98
+ <div class="WordSection3">
99
+ <p class="zzSTDTitle1"></p>
100
+ <br clear="all" style="mso-special-character:line-break;page-break-before:always"/>
101
+ <div class="Section3"><a name="P" id="P"></a>
102
+ <h1 class="Annex"><b>Annex A</b><br/>(normative)<br/><br/><b>Annex</b></h1>
103
+ <div><a name="Q" id="Q"></a>
104
+ <p class="h2Annex">A.1. Annex A.1</p>
105
+ </div>
106
+ <div><a name="Q2" id="Q2"></a>
107
+ <p class="h2Annex">Appendix 1. An Appendix</p>
108
+ </div>
109
+ </div>
110
+ </div>
111
+ <br clear="all" style="page-break-before:left;mso-break-type:section-break"/>
112
+ <div class="colophon"></div>
113
+ OUTPUT
114
+ end
115
+
116
+ it "populates Word template with terms reference labels" do
117
+ system "rm -f test.doc"
118
+ system "rm -f test.html"
119
+ IsoDoc::Iso::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("test", <<~"INPUT", false)
120
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
121
+ <sections>
122
+ <terms id="_terms_and_definitions" obligation="normative"><title>Terms and Definitions</title>
123
+
124
+ <term id="paddy1"><preferred>paddy</preferred>
125
+ <definition><p id="_eb29b35e-123e-4d1c-b50b-2714d41e747f">rice retaining its husk after threshing</p></definition>
126
+ <termsource status="modified">
127
+ <origin bibitemid="ISO7301" type="inline" citeas="ISO 7301:2011"><locality type="clause"><referenceFrom>3.1</referenceFrom></locality></origin>
128
+ <modification>
129
+ <p id="_e73a417d-ad39-417d-a4c8-20e4e2529489">The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here</p>
130
+ </modification>
131
+ </termsource></term>
132
+
133
+ </terms>
134
+ </sections>
135
+ </iso-standard>
136
+
137
+ INPUT
138
+ word = File.read("test.doc").sub(/^.*<div class="WordSection3">/m, '<div class="WordSection3">').
139
+ sub(%r{<div style="mso-element:footnote-list"/>.*$}m, "")
140
+ expect(word).to be_equivalent_to <<~"OUTPUT"
141
+ <div class="WordSection3">
142
+ <p class="zzSTDTitle1"></p>
143
+ <div><a name="_terms_and_definitions" id="_terms_and_definitions"></a><h1>1.<span style="mso-tab-count:1">&#xA0; </span>Terms and definitions</h1><p class="MsoNormal">For the purposes of this document,
144
+ the following terms and definitions apply.</p>
145
+ <p class="MsoNormal">ISO and IEC maintain terminological databases for use in
146
+ standardization at the following addresses:</p>
147
+
148
+ <ul>
149
+ <li style="mso-list:l3 level1 lfo1;" class="MsoNormal"> <p class="MsoNormal">ISO Online browsing platform: available at
150
+ <a href="http://www.iso.org/obp">http://www.iso.org/obp</a></p> </li>
151
+ <li style="mso-list:l3 level1 lfo1;" class="MsoNormal"> <p class="MsoNormal">IEC Electropedia: available at
152
+ <a href="http://www.electropedia.org">http://www.electropedia.org</a>
153
+ </p> </li> </ul>
154
+ <p class="TermNum"><a name="paddy1" id="paddy1"></a>1.1</p><p class="Terms" style="text-align:left;">paddy</p>
155
+ <p class="MsoNormal"><a name="_eb29b35e-123e-4d1c-b50b-2714d41e747f" id="_eb29b35e-123e-4d1c-b50b-2714d41e747f"></a>rice retaining its husk after threshing</p>
156
+ <p class="MsoNormal">[SOURCE: <a href="#ISO7301">ISO 7301:2011, 3.1</a>, modified &mdash; The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here]</p></div>
157
+ </div>
158
+ <br clear="all" style="page-break-before:left;mso-break-type:section-break"/>
159
+ <div class="colophon"></div>
160
+ OUTPUT
161
+ end
162
+
163
+ it "populates Word header" do
164
+ system "rm -f test.doc"
165
+ IsoDoc::Iso::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css", header: "spec/assets/header.html"}).convert("test", <<~"INPUT", false)
166
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
167
+ <bibdata type="article">
168
+ <docidentifier>
169
+ <project-number part="1">1000</project-number>
170
+ </docidentifier>
171
+ </bibdata>
172
+ </iso-standard>
173
+
174
+ INPUT
175
+ word = File.read("test.doc").sub(%r{^.*Content-Location: file:///C:/Doc/test_files/header.html}m, "Content-Location: file:///C:/Doc/test_files/header.html").
176
+ sub(/------=_NextPart.*$/m, "")
177
+ #expect(word).to include(%{Content-Location: file:///C:/Doc/test_files/header.html\nContent-Transfer-Encoding: base64\nContent-Type: text/html charset="utf-8" })
178
+ expect(word).to include(%{Content-Location: file:///C:/Doc/test_files/header.html})
179
+ end
180
+
181
+ it "populates Word ToC" do
182
+ system "rm -f test.doc"
183
+ IsoDoc::Iso::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css", wordintropage: "spec/assets/wordintro.html"}).convert("test", <<~"INPUT", false)
184
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
185
+ <sections>
186
+ <clause inline-header="false" obligation="normative"><title>Clause 4</title><clause id="N" inline-header="false" obligation="normative">
187
+
188
+ <title>Introduction<bookmark id="Q"/> to this<fn reference="1">
189
+ <p id="_ff27c067-2785-4551-96cf-0a73530ff1e6">Formerly denoted as 15 % (m/m).</p>
190
+ </fn></title>
191
+ </clause>
192
+ <clause id="O" inline-header="false" obligation="normative">
193
+ <title>Clause 4.2</title>
194
+ <p>A<fn reference="1">
195
+ <p id="_ff27c067-2785-4551-96cf-0a73530ff1e6">Formerly denoted as 15 % (m/m).</p>
196
+ </fn></p>
197
+ </clause></clause>
198
+ </sections>
199
+ </iso-standard>
200
+
201
+ INPUT
202
+ word = File.read("test.doc").sub(/^.*<p class="zzContents"/m, '<p class="zzContents"').
203
+ sub(%r{<br clear="all" class="section"/>\s*<div class="WordSection3">.*$}m, "")
204
+ expect(word.gsub(/_Toc\d\d+/, "_Toc")).to be_equivalent_to <<~'OUTPUT'
205
+ <p class="zzContents" style="margin-top:0cm">
206
+ <span lang="EN-GB" xml:lang="EN-GB">Contents</span>
207
+ </p>
208
+
209
+ <p class="MsoToc1"><span lang="EN-GB" xml:lang="EN-GB"><span style="mso-element:field-begin"></span><span style="mso-spacerun:yes">&#xA0;</span>TOC
210
+ \o "1-2" \h \z \u <span style="mso-element:field-separator"></span></span>
211
+ <span class="MsoHyperlink"><span lang="EN-GB" style="mso-no-proof:yes" xml:lang="EN-GB">
212
+ <a href="#_Toc">1.<span style="mso-tab-count:1">&#xA0; </span>Clause 4<span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB">
213
+ <span style="mso-tab-count:1 dotted">. </span>
214
+ </span><span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB">
215
+ <span style="mso-element:field-begin"></span></span>
216
+ <span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB"> PAGEREF _Toc \h </span>
217
+ <span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB"><span style="mso-element:field-separator"></span></span><span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB">1</span>
218
+ <span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB"></span><span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB"><span style="mso-element:field-end"></span></span></a></span></span></p>
219
+
220
+ <p class="MsoToc2">
221
+ <span class="MsoHyperlink">
222
+ <span lang="EN-GB" style="mso-no-proof:yes" xml:lang="EN-GB">
223
+ <a href="#_Toc">1.1. Introduction to this<span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB">
224
+ <span style="mso-tab-count:1 dotted">. </span>
225
+ </span><span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB">
226
+ <span style="mso-element:field-begin"></span></span>
227
+ <span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB"> PAGEREF _Toc \h </span>
228
+ <span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB"><span style="mso-element:field-separator"></span></span><span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB">1</span>
229
+ <span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB"></span><span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB"><span style="mso-element:field-end"></span></span></a></span>
230
+ </span>
231
+ </p>
232
+
233
+ <p class="MsoToc2">
234
+ <span class="MsoHyperlink">
235
+ <span lang="EN-GB" style="mso-no-proof:yes" xml:lang="EN-GB">
236
+ <a href="#_Toc">1.2. Clause 4.2<span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB">
237
+ <span style="mso-tab-count:1 dotted">. </span>
238
+ </span><span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB">
239
+ <span style="mso-element:field-begin"></span></span>
240
+ <span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB"> PAGEREF _Toc \h </span>
241
+ <span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB"><span style="mso-element:field-separator"></span></span><span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB">1</span>
242
+ <span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB"></span><span lang="EN-GB" class="MsoTocTextSpan" xml:lang="EN-GB"><span style="mso-element:field-end"></span></span></a></span>
243
+ </span>
244
+ </p>
245
+
246
+ <p class="MsoToc1">
247
+ <span lang="EN-GB" xml:lang="EN-GB">
248
+ <span style="mso-element:field-end"></span>
249
+ </span>
250
+ <span lang="EN-GB" xml:lang="EN-GB">
251
+ <p class="MsoNormal">&#xA0;</p>
252
+ </span>
253
+ </p>
254
+
255
+
256
+ <p class="MsoNormal">&#xA0;</p>
257
+ </div>
258
+ OUTPUT
259
+ end
260
+
261
+ it "reorders footnote numbers in HTML" do
262
+ system "rm -f test.html"
263
+ IsoDoc::Iso::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css", wordintropage: "spec/assets/wordintro.html"}).convert("test", <<~"INPUT", false)
264
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
265
+ <sections>
266
+ <clause inline-header="false" obligation="normative"><title>Clause 4</title><fn reference="3">
267
+ <p id="_ff27c067-2785-4551-96cf-0a73530ff1e6">This is a footnote.</p>
268
+ </fn><clause id="N" inline-header="false" obligation="normative">
269
+
270
+ <title>Introduction to this<fn reference="2">
271
+ <p id="_ff27c067-2785-4551-96cf-0a73530ff1e6">Formerly denoted as 15 % (m/m).</p>
272
+ </fn></title>
273
+ </clause>
274
+ <clause id="O" inline-header="false" obligation="normative">
275
+ <title>Clause 4.2</title>
276
+ <p>A<fn reference="1">
277
+ <p id="_ff27c067-2785-4551-96cf-0a73530ff1e6">Formerly denoted as 15 % (m/m).</p>
278
+ </fn></p>
279
+ </clause></clause>
280
+ </sections>
281
+ </iso-standard>
282
+ INPUT
283
+ html = File.read("test.html").sub(/^.*<main class="main-section">/m, '<main class="main-section">').
284
+ sub(%r{</main>.*$}m, "</main>")
285
+ expect(html).to be_equivalent_to <<~"OUTPUT"
286
+ <main class="main-section"><button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
287
+ <p class="zzSTDTitle1"></p>
288
+ <div>
289
+ <h1>1.&#xA0; Clause 4</h1>
290
+ <a rel="footnote" href="#fn:3" epub:type="footnote" id="fnref:1">
291
+ <sup>1</sup>
292
+ </a>
293
+ <div id="N">
294
+
295
+ <h2>1.1. Introduction to this<a rel="footnote" href="#fn:2" epub:type="footnote" id="fnref:2"><sup>2</sup></a></h2>
296
+ </div>
297
+ <div id="O">
298
+ <h2>1.2. Clause 4.2</h2>
299
+ <p>A<a rel="footnote" href="#fn:2" epub:type="footnote"><sup>2</sup></a></p>
300
+ </div>
301
+ </div>
302
+ <aside id="fn:3" class="footnote">
303
+ <p id="_ff27c067-2785-4551-96cf-0a73530ff1e6"><a rel="footnote" href="#fn:3" epub:type="footnote" id="fnref:1">
304
+ <sup>1</sup>
305
+ </a>This is a footnote.</p>
306
+ <a href="#fnref:1">&#x21A9;</a></aside>
307
+ <aside id="fn:2" class="footnote">
308
+ <p id="_ff27c067-2785-4551-96cf-0a73530ff1e6"><a rel="footnote" href="#fn:2" epub:type="footnote" id="fnref:2"><sup>2</sup></a>Formerly denoted as 15 % (m/m).</p>
309
+ <a href="#fnref:2">&#x21A9;</a></aside>
310
+
311
+ </main>
312
+ OUTPUT
313
+ end
314
+
315
+ it "moves images in HTML" do
316
+ system "rm -f test.html"
317
+ system "rm -rf _images"
318
+ IsoDoc::Iso::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("test", <<~"INPUT", false)
319
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
320
+ <preface><foreword>
321
+ <figure id="_">
322
+ <name>Split-it-right sample divider</name>
323
+ <image src="spec/assets/rice_image1.png" id="_" imagetype="PNG"/>
324
+ <image src="spec/assets/rice_image1.png" id="_" width="20000" height="300000" imagetype="PNG"/>
325
+ <image src="spec/assets/rice_image1.png" id="_" width="99" height="auto" imagetype="PNG"/>
326
+ </figure>
327
+ </foreword></preface>
328
+ </iso-standard>
329
+ INPUT
330
+ html = File.read("test.html").sub(/^.*<main class="main-section">/m, '<main class="main-section">').
331
+ sub(%r{</main>.*$}m, "</main>")
332
+ expect(`ls _images`).to match(/\.png$/)
333
+ expect(html.gsub(/\/[0-9a-f-]+\.png/, "/_.png")).to be_equivalent_to <<~"OUTPUT"
334
+ <main class="main-section"><button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
335
+ <br />
336
+ <div>
337
+ <h1 class="ForewordTitle">Foreword</h1>
338
+ <div id="_" class="figure">
339
+ <img src="_images/_.png" height="776" width="922" />
340
+ <img src="_images/_.png" height="800" width="53" />
341
+ <img src="_images/_.png" height="83" width="99" />
342
+ <p class="FigureTitle" align="center">Figure 1&#xA0;&#x2014; Split-it-right sample divider</p></div>
343
+ </div>
344
+ <p class="zzSTDTitle1"></p>
345
+ </main>
346
+ OUTPUT
347
+
348
+ end
349
+
350
+ it "processes IsoXML terms for HTML" do
351
+ system "rm -f test.doc"
352
+ system "rm -f test.html"
353
+ IsoDoc::Iso::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("test", <<~"INPUT", false)
354
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
355
+ <sections>
356
+ <terms id="_terms_and_definitions" obligation="normative"><title>Terms and Definitions</title>
357
+
358
+ <term id="paddy1"><preferred>paddy</preferred>
359
+ <domain>rice</domain>
360
+ <definition><p id="_eb29b35e-123e-4d1c-b50b-2714d41e747f">rice retaining its husk after threshing</p></definition>
361
+ <termexample id="_bd57bbf1-f948-4bae-b0ce-73c00431f892">
362
+ <p id="_65c9a509-9a89-4b54-a890-274126aeb55c">Foreign seeds, husks, bran, sand, dust.</p>
363
+ <ul>
364
+ <li>A</li>
365
+ </ul>
366
+ </termexample>
367
+ <termexample id="_bd57bbf1-f948-4bae-b0ce-73c00431f894">
368
+ <ul>
369
+ <li>A</li>
370
+ </ul>
371
+ </termexample>
372
+
373
+ <termsource status="modified">
374
+ <origin bibitemid="ISO7301" type="inline" citeas="ISO 7301:2011"><locality type="clause"><referenceFrom>3.1</referenceFrom></locality></origin>
375
+ <modification>
376
+ <p id="_e73a417d-ad39-417d-a4c8-20e4e2529489">The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here</p>
377
+ </modification>
378
+ </termsource></term>
379
+
380
+ <term id="paddy"><preferred>paddy</preferred><admitted>paddy rice</admitted>
381
+ <admitted>rough rice</admitted>
382
+ <deprecates>cargo rice</deprecates>
383
+ <definition><p id="_eb29b35e-123e-4d1c-b50b-2714d41e747f">rice retaining its husk after threshing</p></definition>
384
+ <termexample id="_bd57bbf1-f948-4bae-b0ce-73c00431f893">
385
+ <ul>
386
+ <li>A</li>
387
+ </ul>
388
+ </termexample>
389
+ <termnote id="_671a1994-4783-40d0-bc81-987d06ffb74e">
390
+ <p id="_19830f33-e46c-42cc-94ca-a5ef101132d5">The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.</p>
391
+ </termnote>
392
+ <termnote id="_671a1994-4783-40d0-bc81-987d06ffb74f">
393
+ <ul><li>A</li></ul>
394
+ <p id="_19830f33-e46c-42cc-94ca-a5ef101132d5">The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.</p>
395
+ </termnote>
396
+ <termsource status="identical">
397
+ <origin bibitemid="ISO7301" type="inline" citeas="ISO 7301:2011"><locality type="clause"><referenceFrom>3.1</referenceFrom></locality></origin>
398
+ </termsource></term>
399
+ </terms>
400
+ </sections>
401
+ </iso-standard>
402
+ INPUT
403
+ expect(File.exist?("test.html")).to be true
404
+ html = File.read("test.html")
405
+ expect(html).to match(%r{<h2 class="TermNum" id="paddy1">1\.1</h2>})
406
+ expect(html).to match(%r{<h2 class="TermNum" id="paddy">1\.2</h2>})
407
+ end
408
+
409
+ end