metanorma-iso 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +4 -0
  3. data/.gitignore +11 -0
  4. data/.hound.yml +3 -0
  5. data/.oss-guides.rubocop.yml +1077 -0
  6. data/.rubocop.ribose.yml +66 -0
  7. data/.rubocop.tb.yml +650 -0
  8. data/.rubocop.yml +15 -0
  9. data/.travis.yml +21 -0
  10. data/CODE_OF_CONDUCT.md +46 -0
  11. data/Gemfile +7 -0
  12. data/LICENSE +25 -0
  13. data/Makefile +39 -0
  14. data/README.adoc +882 -0
  15. data/Rakefile +6 -0
  16. data/asciidoctor-iso.gemspec.old +50 -0
  17. data/bin/rspec +18 -0
  18. data/docs/customisation.adoc +186 -0
  19. data/docs/guidance.adoc +436 -0
  20. data/docs/htmloutput.adoc +115 -0
  21. data/docs/quickstart.adoc +375 -0
  22. data/lib/asciidoctor-iso.rb +11 -0
  23. data/lib/asciidoctor/iso/base.rb +48 -0
  24. data/lib/asciidoctor/iso/biblio.rng +836 -0
  25. data/lib/asciidoctor/iso/cleanup.rb +39 -0
  26. data/lib/asciidoctor/iso/converter.rb +19 -0
  27. data/lib/asciidoctor/iso/front.rb +131 -0
  28. data/lib/asciidoctor/iso/isodoc.rng +1059 -0
  29. data/lib/asciidoctor/iso/isostandard.rnc +176 -0
  30. data/lib/asciidoctor/iso/isostandard.rng +1001 -0
  31. data/lib/asciidoctor/iso/section.rb +72 -0
  32. data/lib/asciidoctor/iso/validate.rb +190 -0
  33. data/lib/asciidoctor/iso/validate_requirements.rb +105 -0
  34. data/lib/asciidoctor/iso/validate_section.rb +214 -0
  35. data/lib/asciidoctor/iso/validate_style.rb +134 -0
  36. data/lib/asciidoctor/iso/version.rb +5 -0
  37. data/lib/isodoc/iso/html/header.html +206 -0
  38. data/lib/isodoc/iso/html/html_iso_intro.html +34 -0
  39. data/lib/isodoc/iso/html/html_iso_titlepage.html +34 -0
  40. data/lib/isodoc/iso/html/htmlstyle.scss +46 -0
  41. data/lib/isodoc/iso/html/isodoc.scss +696 -0
  42. data/lib/isodoc/iso/html/scripts.html +174 -0
  43. data/lib/isodoc/iso/html/style-human.scss +1277 -0
  44. data/lib/isodoc/iso/html/style-iso.scss +1257 -0
  45. data/lib/isodoc/iso/html/word_iso_intro.html +72 -0
  46. data/lib/isodoc/iso/html/word_iso_titlepage.html +62 -0
  47. data/lib/isodoc/iso/html/wordstyle.scss +1175 -0
  48. data/lib/isodoc/iso/html_convert.rb +118 -0
  49. data/lib/isodoc/iso/metadata.rb +107 -0
  50. data/lib/isodoc/iso/word_convert.rb +141 -0
  51. data/lib/metanorma/iso.rb +7 -0
  52. data/lib/metanorma/iso/processor.rb +44 -0
  53. data/spec/asciidoctor-iso/base_spec.rb +350 -0
  54. data/spec/asciidoctor-iso/blocks_spec.rb +469 -0
  55. data/spec/asciidoctor-iso/cleanup_spec.rb +765 -0
  56. data/spec/asciidoctor-iso/inline_spec.rb +162 -0
  57. data/spec/asciidoctor-iso/isobib_cache_spec.rb +332 -0
  58. data/spec/asciidoctor-iso/lists_spec.rb +190 -0
  59. data/spec/asciidoctor-iso/macros_spec.rb +111 -0
  60. data/spec/asciidoctor-iso/refs_spec.rb +643 -0
  61. data/spec/asciidoctor-iso/section_spec.rb +334 -0
  62. data/spec/asciidoctor-iso/table_spec.rb +307 -0
  63. data/spec/asciidoctor-iso/validate_spec.rb +907 -0
  64. data/spec/assets/header.html +7 -0
  65. data/spec/assets/html.css +2 -0
  66. data/spec/assets/htmlcover.html +4 -0
  67. data/spec/assets/htmlintro.html +5 -0
  68. data/spec/assets/i18n.yaml +2 -0
  69. data/spec/assets/iso.doc +1093 -0
  70. data/spec/assets/iso.headless.html +33 -0
  71. data/spec/assets/iso.html +278 -0
  72. data/spec/assets/iso.xml +8 -0
  73. data/spec/assets/rice_image1.png +0 -0
  74. data/spec/assets/scripts.html +3 -0
  75. data/spec/assets/std.css +2 -0
  76. data/spec/assets/word.css +2 -0
  77. data/spec/assets/wordcover.html +3 -0
  78. data/spec/assets/wordintro.html +4 -0
  79. data/spec/examples/103_01_02.html +247 -0
  80. data/spec/examples/english.yaml +69 -0
  81. data/spec/examples/iso_123_.xml +45 -0
  82. data/spec/examples/iso_123_all_parts.xml +45 -0
  83. data/spec/examples/iso_123_no_year_note.xml +46 -0
  84. data/spec/examples/iso_124_.xml +41 -0
  85. data/spec/examples/iso_216_.xml +47 -0
  86. data/spec/examples/iso_iec_12382_.xml +48 -0
  87. data/spec/examples/rice.adoc +715 -0
  88. data/spec/examples/rice.preview.html +1877 -0
  89. data/spec/examples/rice.sh +4 -0
  90. data/spec/examples/rice_images/rice_image1.png +0 -0
  91. data/spec/examples/rice_images/rice_image2.png +0 -0
  92. data/spec/examples/rice_images/rice_image3_1.png +0 -0
  93. data/spec/examples/rice_images/rice_image3_2.png +0 -0
  94. data/spec/examples/rice_images/rice_image3_3.png +0 -0
  95. data/spec/isodoc/i18n_spec.rb +642 -0
  96. data/spec/isodoc/iso_spec.rb +168 -0
  97. data/spec/isodoc/metadata_spec.rb +152 -0
  98. data/spec/isodoc/postproc_spec.rb +405 -0
  99. data/spec/isodoc/section_spec.rb +522 -0
  100. data/spec/isodoc/xref_spec.rb +1337 -0
  101. data/spec/metanorma/processor_spec.rb +70 -0
  102. data/spec/spec_helper.rb +227 -0
  103. metadata +402 -0
@@ -0,0 +1,118 @@
1
+ require "isodoc"
2
+ require_relative "metadata"
3
+
4
+ module IsoDoc
5
+ module Iso
6
+ class HtmlConvert < IsoDoc::HtmlConvert
7
+ def metadata_init(lang, script, labels)
8
+ @meta = Metadata.new(lang, script, labels)
9
+ end
10
+
11
+ def initialize(options)
12
+ @libdir = File.dirname(__FILE__)
13
+ super
14
+ end
15
+
16
+ def default_fonts(options)
17
+ {
18
+ bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : options[:alt] ? '"Lato",sans-serif' : '"Cambria",serif'),
19
+ headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' : options[:alt] ? '"Lato",sans-serif' : '"Cambria",serif'),
20
+ monospacefont: (options[:alt] ? '"Space Mono",monospace' : '"Courier New",monospace'),
21
+ }
22
+ end
23
+
24
+ def default_file_locations(options)
25
+ {
26
+ htmlstylesheet: options[:alt] ? html_doc_path("style-human.scss") : html_doc_path("style-iso.scss"),
27
+ htmlcoverpage: html_doc_path("html_iso_titlepage.html"),
28
+ htmlintropage: html_doc_path("html_iso_intro.html"),
29
+ scripts: html_doc_path("scripts.html"),
30
+ }
31
+ end
32
+
33
+ def implicit_reference(b)
34
+ isocode = b.at(ns("./docidentifier")).text
35
+ isocode == "IEV"
36
+ end
37
+
38
+ def introduction(isoxml, out)
39
+ f = isoxml.at(ns("//introduction")) || return
40
+ num = f.at(ns(".//clause")) ? "0" : nil
41
+ title_attr = { class: "IntroTitle" }
42
+ page_break(out)
43
+ out.div **{ class: "Section3", id: f["id"] } do |div|
44
+ # div.h1 "Introduction", **attr_code(title_attr)
45
+ clause_name(num, @introduction_lbl, div, title_attr)
46
+ f.elements.each do |e|
47
+ if e.name == "patent-notice"
48
+ e.elements.each { |e1| parse(e1, div) }
49
+ else
50
+ parse(e, div) unless e.name == "title"
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ def foreword(isoxml, out)
57
+ f = isoxml.at(ns("//foreword")) || return
58
+ page_break(out)
59
+ out.div **attr_code(id: f["id"]) do |s|
60
+ s.h1(**{ class: "ForewordTitle" }) { |h1| h1 << @foreword_lbl }
61
+ f.elements.each { |e| parse(e, s) unless e.name == "title" }
62
+ end
63
+ end
64
+
65
+ def initial_anchor_names(d)
66
+ super
67
+ introduction_names(d.at(ns("//introduction")))
68
+ end
69
+
70
+ # we can reference 0-number clauses in introduction
71
+ def introduction_names(clause)
72
+ return if clause.nil?
73
+ clause.xpath(ns("./clause")).each_with_index do |c, i|
74
+ section_names1(c, "0.#{i + 1}", 2)
75
+ end
76
+ end
77
+
78
+ # terms not defined in standoc
79
+ def error_parse(node, out)
80
+ case node.name
81
+ when "appendix" then clause_parse(node, out)
82
+ else
83
+ super
84
+ end
85
+ end
86
+
87
+ def annex_names(clause, num)
88
+ appendix_names(clause, num)
89
+ super
90
+ end
91
+
92
+ def appendix_names(clause, num)
93
+ clause.xpath(ns("./appendix")).each_with_index do |c, i|
94
+ @anchors[c["id"]] = anchor_struct(i + 1, nil, @appendix_lbl)
95
+ @anchors[c["id"]][:level] = 2
96
+ @anchors[c["id"]][:container] = clause["id"]
97
+ end
98
+ end
99
+
100
+ def section_names1(clause, num, level)
101
+ @anchors[clause["id"]] =
102
+ { label: num, level: level, xref: num }
103
+ # subclauses are not prefixed with "Clause"
104
+ clause.xpath(ns("./clause | ./terms | ./term | ./definitions")).
105
+ each_with_index do |c, i|
106
+ section_names1(c, "#{num}.#{i + 1}", level + 1)
107
+ end
108
+ end
109
+
110
+ def annex_names1(clause, num, level)
111
+ @anchors[clause["id"]] = { label: num, xref: num, level: level }
112
+ clause.xpath(ns(".//clause")).each_with_index do |c, i|
113
+ annex_names1(c, "#{num}.#{i + 1}", level + 1)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,107 @@
1
+ require "isodoc"
2
+
3
+ module IsoDoc
4
+ module Iso
5
+ class Metadata < IsoDoc::Metadata
6
+ def initialize(lang, script, labels)
7
+ super
8
+ end
9
+
10
+ STAGE_ABBRS = {
11
+ "00": "PWI",
12
+ "10": "NWIP",
13
+ "20": "WD",
14
+ "30": "CD",
15
+ "40": "DIS",
16
+ "50": "FDIS",
17
+ "60": "IS",
18
+ "90": "(Review)",
19
+ "95": "(Withdrawal)",
20
+ }.freeze
21
+
22
+ def stage_abbrev(stage, iter, draft)
23
+ stage = STAGE_ABBRS[stage.to_sym] || "??"
24
+ stage += iter.text if iter
25
+ stage = "Pre" + stage if draft&.text =~ /^0\./
26
+ stage
27
+ end
28
+
29
+ def docstatus(isoxml, _out)
30
+ docstatus = isoxml.at(ns("//status/stage"))
31
+ if docstatus
32
+ set(:stage, docstatus.text)
33
+ set(:stage_int, docstatus.text.to_i)
34
+ abbr = stage_abbrev(docstatus.text, isoxml.at(ns("//status/iteration")),
35
+ isoxml.at(ns("//version/draft")))
36
+ set(:stageabbr, abbr)
37
+ end
38
+ end
39
+
40
+ def docid(isoxml, _out)
41
+ dn = docnumber(isoxml)
42
+ docstatus = get[:stage]
43
+ if docstatus
44
+ abbr = get[:stageabbr]
45
+ docstatus = get[:stage]
46
+ (docstatus.to_i < 60) && dn = abbr + " " + dn
47
+ end
48
+ set(:docnumber, dn)
49
+ end
50
+
51
+ # we don't leave this to i18n.rb, because we have both English and
52
+ # French titles in the same document
53
+ def part_label(lang)
54
+ case lang
55
+ when "en" then "Part"
56
+ when "fr" then "Partie"
57
+ end
58
+ end
59
+
60
+ def part_title(part, partnum, subpartnum, lang)
61
+ return "" unless part
62
+ suffix = @c.encode(part.text, :hexadecimal)
63
+ partnum = "#{partnum}&ndash;#{subpartnum}" if partnum && subpartnum
64
+ suffix = "#{part_label(lang)}&nbsp;#{partnum}: " + suffix if partnum
65
+ suffix
66
+ end
67
+
68
+ def compose_title(main, intro, part, partnum, subpartnum, lang)
69
+ main = main.nil? ? "" : @c.encode(main.text, :hexadecimal)
70
+ intro &&
71
+ main = "#{@c.encode(intro.text, :hexadecimal)}&nbsp;&mdash; #{main}"
72
+ if part
73
+ suffix = part_title(part, partnum, subpartnum, lang)
74
+ main = "#{main}&nbsp;&mdash; #{suffix}"
75
+ end
76
+ main
77
+ end
78
+
79
+ def title(isoxml, _out)
80
+ intro = isoxml.at(ns("//title-intro[@language='en']"))
81
+ main = isoxml.at(ns("//title-main[@language='en']"))
82
+ part = isoxml.at(ns("//title-part[@language='en']"))
83
+ partnumber = isoxml.at(ns("//project-number/@part"))
84
+ subpartnumber = isoxml.at(ns("//project-number/@subpart"))
85
+
86
+ set(:doctitlemain, @c.encode(main ? main.text : "", :hexadecimal))
87
+ main = compose_title(main, intro, part, partnumber, subpartnumber, "en")
88
+ set(:doctitle, main)
89
+ set(:doctitleintro, @c.encode(intro ? intro.text : "", :hexadecimal)) if intro
90
+ set(:doctitlepart, part_title(part, partnumber, subpartnumber, "en"))
91
+ end
92
+
93
+ def subtitle(isoxml, _out)
94
+ intro = isoxml.at(ns("//title-intro[@language='fr']"))
95
+ main = isoxml.at(ns("//title-main[@language='fr']"))
96
+ part = isoxml.at(ns("//title-part[@language='fr']"))
97
+ partnumber = isoxml.at(ns("//project-number/@part"))
98
+ subpartnumber = isoxml.at(ns("//project-number/@subpart"))
99
+ set(:docsubtitlemain, @c.encode(main ? main.text : "", :hexadecimal))
100
+ main = compose_title(main, intro, part, partnumber, subpartnumber, "fr")
101
+ set(:docsubtitle, main)
102
+ set(:docsubtitleintro, @c.encode(intro ? intro.text : "", :hexadecimal)) if intro
103
+ set(:docsubtitlepart, part_title(part, partnumber, subpartnumber, "fr"))
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,141 @@
1
+ require "isodoc"
2
+ require_relative "metadata"
3
+
4
+ module IsoDoc
5
+ module Iso
6
+ class WordConvert < IsoDoc::WordConvert
7
+ def initialize(options)
8
+ @libdir = File.dirname(__FILE__)
9
+ super
10
+ end
11
+
12
+ def default_fonts(options)
13
+ {
14
+ bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : '"Cambria",serif'),
15
+ headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' : '"Cambria",serif'),
16
+ monospacefont: '"Courier New",monospace',
17
+ }
18
+ end
19
+
20
+ def default_file_locations(options)
21
+ {
22
+ htmlstylesheet: options[:alt] ? html_doc_path("style-human.scss") : html_doc_path("style-iso.scss"),
23
+ htmlcoverpage: html_doc_path("html_iso_titlepage.html"),
24
+ htmlintropage: html_doc_path("html_iso_intro.html"),
25
+ scripts: html_doc_path("scripts.html"),
26
+ wordstylesheet: html_doc_path("wordstyle.scss"),
27
+ standardstylesheet: html_doc_path("isodoc.scss"),
28
+ header: html_doc_path("header.html"),
29
+ wordcoverpage: html_doc_path("word_iso_titlepage.html"),
30
+ wordintropage: html_doc_path("word_iso_intro.html"),
31
+ ulstyle: "l3",
32
+ olstyle: "l2",
33
+ }
34
+ end
35
+
36
+ def metadata_init(lang, script, labels)
37
+ @meta = Metadata.new(lang, script, labels)
38
+ end
39
+
40
+ def implicit_reference(b)
41
+ isocode = b.at(ns("./docidentifier")).text
42
+ isocode == "IEV"
43
+ end
44
+
45
+ def make_body(xml, docxml)
46
+ body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" }
47
+ xml.body **body_attr do |body|
48
+ make_body1(body, docxml)
49
+ make_body2(body, docxml)
50
+ make_body3(body, docxml)
51
+ colophon(body, docxml)
52
+ end
53
+ end
54
+
55
+ def colophon(body, docxml)
56
+ body.br **{ clear: "all", style: "page-break-before:left;mso-break-type:section-break" }
57
+ body.div **{ class: "colophon" } do |div|
58
+ end
59
+ end
60
+
61
+ def introduction(isoxml, out)
62
+ f = isoxml.at(ns("//introduction")) || return
63
+ num = f.at(ns(".//clause")) ? "0" : nil
64
+ title_attr = { class: "IntroTitle" }
65
+ page_break(out)
66
+ out.div **{ class: "Section3", id: f["id"] } do |div|
67
+ # div.h1 "Introduction", **attr_code(title_attr)
68
+ clause_name(num, @introduction_lbl, div, title_attr)
69
+ f.elements.each do |e|
70
+ if e.name == "patent-notice"
71
+ e.elements.each { |e1| parse(e1, div) }
72
+ else
73
+ parse(e, div) unless e.name == "title"
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ def foreword(isoxml, out)
80
+ f = isoxml.at(ns("//foreword")) || return
81
+ page_break(out)
82
+ out.div **attr_code(id: f["id"]) do |s|
83
+ s.h1(**{ class: "ForewordTitle" }) { |h1| h1 << @foreword_lbl }
84
+ f.elements.each { |e| parse(e, s) unless e.name == "title" }
85
+ end
86
+ end
87
+
88
+ def initial_anchor_names(d)
89
+ super
90
+ introduction_names(d.at(ns("//introduction")))
91
+ end
92
+
93
+ # we can reference 0-number clauses in introduction
94
+ def introduction_names(clause)
95
+ return if clause.nil?
96
+ clause.xpath(ns("./clause")).each_with_index do |c, i|
97
+ section_names1(c, "0.#{i + 1}", 2)
98
+ end
99
+ end
100
+
101
+ # terms not defined in standoc
102
+ def error_parse(node, out)
103
+ case node.name
104
+ when "appendix" then clause_parse(node, out)
105
+ else
106
+ super
107
+ end
108
+ end
109
+
110
+ def annex_names(clause, num)
111
+ appendix_names(clause, num)
112
+ super
113
+ end
114
+
115
+ def appendix_names(clause, num)
116
+ clause.xpath(ns("./appendix")).each_with_index do |c, i|
117
+ @anchors[c["id"]] = anchor_struct(i + 1, nil, @appendix_lbl)
118
+ @anchors[c["id"]][:level] = 2
119
+ @anchors[c["id"]][:container] = clause["id"]
120
+ end
121
+ end
122
+
123
+ def section_names1(clause, num, level)
124
+ @anchors[clause["id"]] =
125
+ { label: num, level: level, xref: num }
126
+ # subclauses are not prefixed with "Clause"
127
+ clause.xpath(ns("./clause | ./terms | ./term | ./definitions")).
128
+ each_with_index do |c, i|
129
+ section_names1(c, "#{num}.#{i + 1}", level + 1)
130
+ end
131
+ end
132
+
133
+ def annex_names1(clause, num, level)
134
+ @anchors[clause["id"]] = { label: num, xref: num, level: level }
135
+ clause.xpath(ns(".//clause")).each_with_index do |c, i|
136
+ annex_names1(c, "#{num}.#{i + 1}", level + 1)
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,7 @@
1
+ require_relative "./iso/processor"
2
+
3
+ module Metanorma
4
+ module Iso
5
+
6
+ end
7
+ end
@@ -0,0 +1,44 @@
1
+ require "metanorma/processor"
2
+
3
+ module Metanorma
4
+ module Iso
5
+ class Processor < Metanorma::Processor
6
+
7
+ def initialize
8
+ @short = :iso
9
+ @input_format = :asciidoc
10
+ @asciidoctor_backend = :iso
11
+ end
12
+
13
+ def output_formats
14
+ super.merge(
15
+ html: "html",
16
+ html_alt: "alt.html",
17
+ doc: "doc"
18
+ )
19
+ end
20
+
21
+ def version
22
+ "Asciidoctor::ISO #{Asciidoctor::ISO::VERSION}/IsoDoc #{IsoDoc::VERSION}"
23
+ end
24
+
25
+ def input_to_isodoc(file)
26
+ Metanorma::Input::Asciidoc.new.process(file, @asciidoctor_backend)
27
+ end
28
+
29
+ def output(isodoc_node, outname, format, options={})
30
+ case format
31
+ when :html
32
+ IsoDoc::Iso::HtmlConvert.new(options).convert(outname, isodoc_node)
33
+ when :html_alt
34
+ IsoDoc::Iso::HtmlConvert.new(options.merge(alt: true)).convert(outname, isodoc_node)
35
+ when :doc
36
+ IsoDoc::Iso::WordConvert.new(options).convert(outname, isodoc_node)
37
+ else
38
+ super
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,350 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Asciidoctor::ISO do
4
+ it "has a version number" do
5
+ expect(Asciidoctor::ISO::VERSION).not_to be nil
6
+ end
7
+
8
+ =begin
9
+ it "generates output for the Rice document" do
10
+ system "cd spec/examples; rm -f rice.xml; rm -f rice.doc; rm -f rice.html; rm -f rice_alt.html; asciidoctor --trace -b iso -r 'asciidoctor-iso' rice.adoc; cd ../.."
11
+ expect(File.exist?("spec/examples/rice.xml")).to be true
12
+ expect(File.exist?("spec/examples/rice.doc")).to be true
13
+ expect(File.exist?("spec/examples/rice.html")).to be true
14
+ expect(File.exist?("spec/examples/rice_alt.html")).to be true
15
+ end
16
+ =end
17
+
18
+ it "processes a blank document" do
19
+ expect(Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)).to be_equivalent_to <<~"OUTPUT"
20
+ #{ASCIIDOC_BLANK_HDR}
21
+ INPUT
22
+ #{BLANK_HDR}
23
+ <sections/>
24
+ </iso-standard>
25
+ OUTPUT
26
+ end
27
+
28
+ it "converts a blank document" do
29
+ system "rm -f test.doc"
30
+ expect(Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)).to be_equivalent_to <<~"OUTPUT"
31
+ = Document title
32
+ Author
33
+ :docfile: test.adoc
34
+ :novalid:
35
+ INPUT
36
+ #{BLANK_HDR}
37
+ <sections/>
38
+ </iso-standard>
39
+ OUTPUT
40
+ expect(File.exist?("test.doc")).to be true
41
+ expect(File.exist?("htmlstyle.css")).to be false
42
+ end
43
+
44
+ it "processes default metadata" do
45
+ expect(Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)).to be_equivalent_to <<~'OUTPUT'
46
+ = Document title
47
+ Author
48
+ :docfile: test.adoc
49
+ :nodoc:
50
+ :novalid:
51
+ :docnumber: 1000
52
+ :partnumber: 1
53
+ :edition: 2
54
+ :revdate: 2000-01-01
55
+ :draft: 3.4
56
+ :technical-committee: TC
57
+ :technical-committee-number: 1
58
+ :technical-committee-type: A
59
+ :subcommittee: SC
60
+ :subcommittee-number: 2
61
+ :subcommittee-type: B
62
+ :workgroup: WG
63
+ :workgroup-number: 3
64
+ :workgroup-type: C
65
+ :secretariat: SECRETARIAT
66
+ :copyright-year: 2001
67
+ :docstage: 10
68
+ :docsubstage: 20
69
+ :iteration: 3
70
+ :language: en
71
+ :title-intro-en: Introduction
72
+ :title-main-en: Main Title -- Title
73
+ :title-part-en: Title Part
74
+ :title-intro-fr: Introduction Française
75
+ :title-main-fr: Titre Principal
76
+ :title-part-fr: Part du Titre
77
+ :library-ics: 1,2,3
78
+ INPUT
79
+ <?xml version="1.0" encoding="UTF-8"?>
80
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
81
+ <bibdata type="article">
82
+ <title>
83
+ <title-intro language="en" format="text/plain">Introduction</title-intro>
84
+ <title-main language="en" format="text/plain">Main Title — Title</title-main>
85
+ <title-part language="en" format="text/plain">Title Part</title-part>
86
+ </title>
87
+ <title>
88
+ <title-intro language="fr" format="text/plain">Introduction Française</title-intro>
89
+ <title-main language="fr" format="text/plain">Titre Principal</title-main>
90
+ <title-part language="fr" format="text/plain">Part du Titre</title-part>
91
+ </title>
92
+ <docidentifier>
93
+ <project-number part="1">ISO 1000</project-number>
94
+ </docidentifier>
95
+ <contributor>
96
+ <role type="author"/>
97
+ <organization>
98
+ <name>International Organization for Standardization</name>
99
+ <abbreviation>ISO</abbreviation>
100
+ </organization>
101
+ </contributor>
102
+ <contributor>
103
+ <role type="publisher"/>
104
+ <organization>
105
+ <name>International Organization for Standardization</name>
106
+ <abbreviation>ISO</abbreviation>
107
+ </organization>
108
+ </contributor>
109
+ <language>en</language>
110
+ <script>Latn</script>
111
+ <status>
112
+ <stage>10</stage>
113
+ <substage>20</substage>
114
+ <iteration>3</iteration>
115
+ </status>
116
+ <copyright>
117
+ <from>2001</from>
118
+ <owner>
119
+ <organization>
120
+ <name>International Organization for Standardization</name>
121
+ <abbreviation>ISO</abbreviation>
122
+ </organization>
123
+ </owner>
124
+ </copyright>
125
+ <editorialgroup>
126
+ <technical-committee number="1" type="A">TC</technical-committee>
127
+ <subcommittee number="2" type="B">SC</subcommittee>
128
+ <workgroup number="3" type="C">WG</workgroup>
129
+ <secretariat>SECRETARIAT</secretariat>
130
+ </editorialgroup>
131
+ <ics>
132
+ <code>1</code>
133
+ </ics>
134
+ <ics>
135
+ <code>2</code>
136
+ </ics>
137
+ <ics>
138
+ <code>3</code>
139
+ </ics>
140
+ </bibdata><version>
141
+ <edition>2</edition>
142
+ <revision-date>2000-01-01</revision-date>
143
+ <draft>3.4</draft>
144
+ </version>
145
+ <sections/>
146
+ </iso-standard>
147
+ OUTPUT
148
+ end
149
+
150
+
151
+ it "processes complex metadata" do
152
+ expect(Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)).to be_equivalent_to <<~'OUTPUT'
153
+ = Document title
154
+ Author
155
+ :docfile: test.adoc
156
+ :nodoc:
157
+ :novalid:
158
+ :docnumber: 1000
159
+ :partnumber: 1-1
160
+ :tc-docnumber: 2000
161
+ :language: el
162
+ :script: Grek
163
+ :publisher: IEC,IETF,ISO
164
+ INPUT
165
+ <?xml version="1.0" encoding="UTF-8"?>
166
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
167
+ <bibdata type="article">
168
+ <title>
169
+
170
+ </title>
171
+ <title>
172
+
173
+ </title>
174
+ <docidentifier>
175
+ <project-number part="1" subpart="1">ISO/IEC/IETF 1000</project-number>
176
+ <tc-document-number>2000</tc-document-number>
177
+ </docidentifier>
178
+ <contributor>
179
+ <role type="author"/>
180
+ <organization>
181
+ <name>International Electrotechnical Commission</name>
182
+ <abbreviation>IEC</abbreviation>
183
+ </organization>
184
+ </contributor>
185
+ <contributor>
186
+ <role type="author"/>
187
+ <organization>
188
+ <name>IETF</name>
189
+ </organization>
190
+ </contributor>
191
+ <contributor>
192
+ <role type="author"/>
193
+ <organization>
194
+ <name>International Organization for Standardization</name>
195
+ <abbreviation>ISO</abbreviation>
196
+ </organization>
197
+ </contributor>
198
+ <contributor>
199
+ <role type="publisher"/>
200
+ <organization>
201
+ <name>International Electrotechnical Commission</name>
202
+ <abbreviation>IEC</abbreviation>
203
+ </organization>
204
+ </contributor>
205
+ <contributor>
206
+ <role type="publisher"/>
207
+ <organization>
208
+ <name>IETF</name>
209
+ </organization>
210
+ </contributor>
211
+ <contributor>
212
+ <role type="publisher"/>
213
+ <organization>
214
+ <name>International Organization for Standardization</name>
215
+ <abbreviation>ISO</abbreviation>
216
+ </organization>
217
+ </contributor>
218
+ <language>el</language>
219
+ <script>Grek</script>
220
+ <status>
221
+ <stage>60</stage>
222
+ <substage>60</substage>
223
+ </status>
224
+ <copyright>
225
+ <from>2018</from>
226
+ <owner>
227
+ <organization>
228
+ <name>International Electrotechnical Commission</name>
229
+ <abbreviation>IEC</abbreviation>
230
+ </organization>
231
+ </owner>
232
+ </copyright>
233
+ <copyright>
234
+ <from>2018</from>
235
+ <owner>
236
+ <organization>
237
+ <name>IETF</name>
238
+ </organization>
239
+ </owner>
240
+ </copyright>
241
+ <copyright>
242
+ <from>2018</from>
243
+ <owner>
244
+ <organization>
245
+ <name>International Organization for Standardization</name>
246
+ <abbreviation>ISO</abbreviation>
247
+ </organization>
248
+ </owner>
249
+ </copyright>
250
+ <editorialgroup>
251
+ <technical-committee/>
252
+ <subcommittee/>
253
+ <workgroup/>
254
+ </editorialgroup>
255
+ </bibdata>
256
+ <sections/>
257
+ </iso-standard>
258
+ OUTPUT
259
+ end
260
+
261
+ it "reads scripts into blank HTML document" do
262
+ system "rm -f test.html"
263
+ Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
264
+ = Document title
265
+ Author
266
+ :docfile: test.adoc
267
+ :novalid:
268
+ INPUT
269
+ html = File.read("test.html", encoding: "utf-8")
270
+ expect(html).to match(%r{<script>})
271
+ end
272
+
273
+ it "uses default fonts" do
274
+ system "rm -f test.html"
275
+ Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
276
+ = Document title
277
+ Author
278
+ :docfile: test.adoc
279
+ :novalid:
280
+ INPUT
281
+ html = File.read("test.html", encoding: "utf-8")
282
+ expect(html).to match(%r[\.Sourcecode[^{]+\{[^{]+font-family: "Courier New", monospace;]m)
283
+ expect(html).to match(%r[blockquote[^{]+\{[^{]+font-family: "Cambria", serif;]m)
284
+ expect(html).to match(%r[\.h2Annex[^{]+\{[^{]+font-family: "Cambria", serif;]m)
285
+ end
286
+
287
+ it "uses default fonts for alt doc" do
288
+ system "rm -f test_alt.html"
289
+ Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
290
+ = Document title
291
+ Author
292
+ :docfile: test.adoc
293
+ :novalid:
294
+ INPUT
295
+ html = File.read("test_alt.html", encoding: "utf-8")
296
+ expect(html).to match(%r[\.Sourcecode[^{]+\{[^{]+font-family: "Space Mono", monospace;]m)
297
+ expect(html).to match(%r[blockquote[^{]+\{[^{]+font-family: "Lato", sans-serif;]m)
298
+ expect(html).to match(%r[\.h2Annex[^{]+\{[^{]+font-family: "Lato", sans-serif;]m)
299
+ end
300
+
301
+ it "uses Chinese fonts" do
302
+ system "rm -f test.html"
303
+ Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
304
+ = Document title
305
+ Author
306
+ :docfile: test.adoc
307
+ :novalid:
308
+ :script: Hans
309
+ INPUT
310
+ html = File.read("test.html", encoding: "utf-8")
311
+ expect(html).to match(%r[\.Sourcecode[^{]+\{[^{]+font-family: "Courier New", monospace;]m)
312
+ expect(html).to match(%r[blockquote[^{]+\{[^{]+font-family: "SimSun", serif;]m)
313
+ expect(html).to match(%r[\.h2Annex[^{]+\{[^{]+font-family: "SimHei", sans-serif;]m)
314
+ end
315
+
316
+ it "uses specified fonts" do
317
+ system "rm -f test.html"
318
+ Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
319
+ = Document title
320
+ Author
321
+ :docfile: test.adoc
322
+ :novalid:
323
+ :script: Hans
324
+ :body-font: Zapf Chancery
325
+ :header-font: Comic Sans
326
+ :monospace-font: Andale Mono
327
+ INPUT
328
+ html = File.read("test.html", encoding: "utf-8")
329
+ expect(html).to match(%r[\.Sourcecode[^{]+\{[^{]+font-family: Andale Mono;]m)
330
+ expect(html).to match(%r[blockquote[^{]+\{[^{]+font-family: Zapf Chancery;]m)
331
+ expect(html).to match(%r[\.h2Annex[^{]+\{[^{]+font-family: Comic Sans;]m)
332
+ end
333
+
334
+ it "strips MS-specific CSS" do
335
+ system "rm -f test.html"
336
+ system "rm -f test.doc"
337
+ Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
338
+ = Document title
339
+ Author
340
+ :docfile: test.adoc
341
+ :novalid:
342
+ INPUT
343
+ word = File.read("test.doc", encoding: "utf-8")
344
+ html = File.read("test.html", encoding: "utf-8")
345
+ expect(word).to match(%r[mso-style-name: "Intro Title";]m)
346
+ expect(html).not_to match(%r[mso-style-name: "Intro Title";]m)
347
+ end
348
+
349
+
350
+ end