asciidoctor-iso 0.10.1 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,55 +1,19 @@
1
1
  require "asciidoctor"
2
+ require "metanorma-standoc"
2
3
  require "asciidoctor/iso/version"
3
4
  require "asciidoctor/iso/base"
4
5
  require "asciidoctor/iso/front"
5
- require "asciidoctor/iso/lists"
6
- require "asciidoctor/iso/ref"
7
- require "asciidoctor/iso/inline"
8
- require "asciidoctor/iso/blocks"
9
6
  require "asciidoctor/iso/section"
10
- require "asciidoctor/iso/table"
11
7
  require "asciidoctor/iso/validate"
12
- require "asciidoctor/iso/utils"
13
8
  require "asciidoctor/iso/cleanup"
14
- require_relative "./macros.rb"
15
9
 
16
10
  module Asciidoctor
17
11
  module ISO
18
12
  # A {Converter} implementation that generates ISO output, and a document
19
13
  # schema encapsulation of the document for validation
20
- class Converter
21
- include ::Asciidoctor::Converter
22
- include ::Asciidoctor::Writer
23
-
24
- include ::Asciidoctor::ISO::Base
25
- include ::Asciidoctor::ISO::Front
26
- include ::Asciidoctor::ISO::Lists
27
- include ::Asciidoctor::ISO::Inline
28
- include ::Asciidoctor::ISO::Blocks
29
- include ::Asciidoctor::ISO::Section
30
- include ::Asciidoctor::ISO::Table
31
- include ::Asciidoctor::ISO::Utils
32
- include ::Asciidoctor::ISO::Cleanup
33
- include ::Asciidoctor::ISO::Validate
34
-
14
+ class Converter < ::Asciidoctor::Standoc::Converter
35
15
  register_for "iso"
36
16
 
37
- $xreftext = {}
38
-
39
- def initialize(backend, opts)
40
- super
41
- basebackend "html"
42
- outfilesuffix ".xml"
43
- end
44
-
45
- alias_method :embedded, :content
46
- alias_method :verse, :quote
47
- alias_method :audio, :skip
48
- alias_method :video, :skip
49
- alias_method :inline_button, :skip
50
- alias_method :inline_kbd, :skip
51
- alias_method :inline_menu, :skip
52
- alias_method :inline_image, :skip
53
17
  end
54
18
  end
55
19
  end
@@ -8,7 +8,7 @@ require "pp"
8
8
 
9
9
  module Asciidoctor
10
10
  module ISO
11
- module Front
11
+ class Converter < Standoc::Converter
12
12
  def metadata_id(node, xml)
13
13
  part, subpart = node&.attr("partnumber")&.split(/-/)
14
14
  xml.docidentifier do |i|
@@ -20,20 +20,6 @@ module Asciidoctor
20
20
  end
21
21
  end
22
22
 
23
- def metadata_version(node, xml)
24
- xml.version do |v|
25
- v.edition node.attr("edition") if node.attr("edition")
26
- v.revision_date node.attr("revdate") if node.attr("revdate")
27
- v.draft node.attr("draft") if node.attr("draft")
28
- end
29
- end
30
-
31
- def committee_component(compname, node, out)
32
- out.send compname.gsub(/-/, "_"), node.attr(compname),
33
- **attr_code(number: node.attr("#{compname}-number"),
34
- type: node.attr("#{compname}-type"))
35
- end
36
-
37
23
  def organization(org, orgname)
38
24
  if ["ISO",
39
25
  "International Organization for Standardization"].include? orgname
@@ -97,21 +83,12 @@ module Asciidoctor
97
83
  end
98
84
  end
99
85
 
100
- def metadata_ics(node, xml)
101
- ics = node.attr("library-ics")
102
- ics && ics.split(/,\s*/).each do |i|
103
- xml.ics do |ics|
104
- ics.code i
105
- end
106
- end
107
- end
108
-
109
86
  def metadata(node, xml)
110
87
  title node, xml
111
88
  metadata_id(node, xml)
112
89
  metadata_author(node, xml)
113
90
  metadata_publisher(node, xml)
114
- xml.language node.attr("language")
91
+ xml.language (node.attr("language") || "en")
115
92
  xml.script (node.attr("script") || "Latn")
116
93
  metadata_status(node, xml)
117
94
  metadata_copyright(node, xml)
@@ -119,13 +96,6 @@ module Asciidoctor
119
96
  metadata_ics(node, xml)
120
97
  end
121
98
 
122
- def asciidoc_sub(x)
123
- return nil if x.nil?
124
- d = Asciidoctor::Document.new(x.lines.entries, {header_footer: false})
125
- b = d.parse.blocks.first
126
- b.apply_subs(b.source)
127
- end
128
-
129
99
  def title_intro(node, t, lang, at)
130
100
  return unless node.attr("title-intro-#{lang}")
131
101
  t.title_intro(**attr_code(at)) do |t1|
@@ -18,7 +18,21 @@
18
18
  of this.
19
19
  -->
20
20
  <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
21
- <include href="biblio.rng"/>
21
+ <include href="biblio.rng">
22
+ <define name="status">
23
+ <element name="status">
24
+ <choice>
25
+ <value>proposal</value>
26
+ <value>working_draft</value>
27
+ <value>committee_draft</value>
28
+ <value>draft_standard</value>
29
+ <value>final_draft</value>
30
+ <value>published</value>
31
+ <value>withdrawn</value>
32
+ </choice>
33
+ </element>
34
+ </define>
35
+ </include>
22
36
  <start>
23
37
  <ref name="standard-document"/>
24
38
  </start>
@@ -28,9 +42,10 @@
28
42
  <optional>
29
43
  <ref name="version"/>
30
44
  </optional>
31
- <oneOrMore>
32
- <ref name="sections"/>
33
- </oneOrMore>
45
+ <optional>
46
+ <ref name="preface"/>
47
+ </optional>
48
+ <ref name="sections"/>
34
49
  <zeroOrMore>
35
50
  <ref name="annex"/>
36
51
  </zeroOrMore>
@@ -44,11 +59,6 @@
44
59
  <ref name="BibData"/>
45
60
  </element>
46
61
  </define>
47
- <define name="status">
48
- <element name="status">
49
- <ref name="FormattedString"/>
50
- </element>
51
- </define>
52
62
  <define name="version">
53
63
  <element name="version">
54
64
  <optional>
@@ -77,6 +87,13 @@
77
87
  <text/>
78
88
  </element>
79
89
  </define>
90
+ <define name="preface">
91
+ <element name="preface">
92
+ <oneOrMore>
93
+ <ref name="content"/>
94
+ </oneOrMore>
95
+ </element>
96
+ </define>
80
97
  <define name="sections">
81
98
  <element name="sections">
82
99
  <oneOrMore>
@@ -104,7 +121,9 @@
104
121
  </define>
105
122
  <define name="section-title">
106
123
  <element name="title">
107
- <text/>
124
+ <zeroOrMore>
125
+ <ref name="TextElement"/>
126
+ </zeroOrMore>
108
127
  </element>
109
128
  </define>
110
129
  <define name="content">
@@ -324,7 +343,7 @@
324
343
  <attribute name="id">
325
344
  <data type="ID"/>
326
345
  </attribute>
327
- <ref name="BasicBlock"/>
346
+ <ref name="paragraph"/>
328
347
  </element>
329
348
  </define>
330
349
  <define name="termsource">
@@ -423,7 +442,7 @@
423
442
  <data type="ID"/>
424
443
  </attribute>
425
444
  <oneOrMore>
426
- <ref name="paragraph-with-footnote"/>
445
+ <ref name="paragraph"/>
427
446
  </oneOrMore>
428
447
  </element>
429
448
  </define>
@@ -690,21 +709,20 @@
690
709
  <ref name="tname"/>
691
710
  </optional>
692
711
  <choice>
693
- <oneOrMore>
712
+ <ref name="image"/>
713
+ <zeroOrMore>
694
714
  <ref name="figure"/>
695
- </oneOrMore>
696
- <group>
697
- <zeroOrMore>
698
- <ref name="TextElement"/>
699
- </zeroOrMore>
700
- <zeroOrMore>
701
- <ref name="note"/>
702
- </zeroOrMore>
703
- <optional>
704
- <ref name="dl"/>
705
- </optional>
706
- </group>
715
+ </zeroOrMore>
707
716
  </choice>
717
+ <zeroOrMore>
718
+ <ref name="fn"/>
719
+ </zeroOrMore>
720
+ <optional>
721
+ <ref name="dl"/>
722
+ </optional>
723
+ <zeroOrMore>
724
+ <ref name="note"/>
725
+ </zeroOrMore>
708
726
  </element>
709
727
  </define>
710
728
  <define name="TextElement">
@@ -681,6 +681,14 @@
681
681
  <ref name="paragraph"/>
682
682
  </element>
683
683
  </define>
684
+ <define name="preface">
685
+ <element name="preface">
686
+ <ref name="foreword"/>
687
+ <optional>
688
+ <ref name="introduction"/>
689
+ </optional>
690
+ </element>
691
+ </define>
684
692
  </include>
685
693
  <!-- end overrides -->
686
694
  <!--
@@ -706,14 +714,6 @@
706
714
  <ref name="bibliography"/>
707
715
  </element>
708
716
  </define>
709
- <define name="preface">
710
- <element name="preface">
711
- <ref name="foreword"/>
712
- <optional>
713
- <ref name="introduction"/>
714
- </optional>
715
- </element>
716
- </define>
717
717
  <define name="bibliography">
718
718
  <element name="bibliography">
719
719
  <oneOrMore>
@@ -3,29 +3,9 @@ require "uri"
3
3
 
4
4
  module Asciidoctor
5
5
  module ISO
6
- module Section
7
- @biblio = false
8
- @term_def = false
9
- @norm_ref = false
10
-
11
- def in_biblio?
12
- @biblio
13
- end
14
-
15
- def in_terms?
16
- @term_def
17
- end
18
-
19
- def in_norm_ref?
20
- @norm_ref
21
- end
22
-
23
- def sectiontype(node)
24
- node&.attr("heading")&.downcase || node.title.downcase
25
- end
26
-
6
+ class Converter < Standoc::Converter
27
7
  def section(node)
28
- a = { id: Utils::anchor_or_uuid(node) }
8
+ a = { id: Standoc::Utils::anchor_or_uuid(node) }
29
9
  noko do |xml|
30
10
  case sectiontype(node)
31
11
  when "introduction" then
@@ -64,35 +44,6 @@ module Asciidoctor
64
44
  end.join("\n")
65
45
  end
66
46
 
67
- def set_obligation(attrs, node)
68
- attrs[:obligation] = if node.attributes.has_key?("obligation")
69
- node.attr("obligation")
70
- elsif node.parent.attributes.has_key?("obligation")
71
- node.parent.attr("obligation")
72
- else
73
- "normative"
74
- end
75
- end
76
-
77
- def clause_parse(attrs, xml, node)
78
- attrs["inline-header".to_sym] = node.option? "inline-header"
79
- attrs[:level] = node.attr("level")
80
- set_obligation(attrs, node)
81
- xml.send "clause", **attr_code(attrs) do |xml_section|
82
- xml_section.title { |n| n << node.title } unless node.title.nil?
83
- xml_section << node.content
84
- end
85
- end
86
-
87
- def annex_parse(attrs, xml, node)
88
- attrs["inline-header".to_sym] = node.option? "inline-header"
89
- set_obligation(attrs, node)
90
- xml.annex **attr_code(attrs) do |xml_section|
91
- xml_section.title { |name| name << node.title }
92
- xml_section << node.content
93
- end
94
- end
95
-
96
47
  def appendix_parse(attrs, xml, node)
97
48
  attrs["inline-header".to_sym] = node.option? "inline-header"
98
49
  set_obligation(attrs, node)
@@ -102,72 +53,6 @@ module Asciidoctor
102
53
  end
103
54
  end
104
55
 
105
- def bibliography_parse(attrs, xml, node)
106
- node.attr("style") == "bibliography" or
107
- warn "Section not marked up as [bibliography]!"
108
- @biblio = true
109
- xml.references **attr_code(attrs) do |xml_section|
110
- title = node.level == 1 ? "Bibliography" : node.title
111
- xml_section.title { |t| t << title }
112
- xml_section << node.content
113
- end
114
- @biblio = false
115
- end
116
-
117
- def symbols_parse(attrs, xml, node)
118
- xml.definitions **attr_code(attrs) do |xml_section|
119
- xml_section << node.content
120
- end
121
- end
122
-
123
- # subclause contains subclauses
124
- def term_def_subclause_parse(attrs, xml, node)
125
- sub = node.find_by(context: :section) { |s| s.level == node.level + 1 }
126
- sub.empty? || (return term_def_parse(attrs, xml, node, false))
127
- node.title.casecmp("symbols and abbreviated terms").zero? &&
128
- (return symbols_parse(attrs, xml, node))
129
- xml.term **attr_code(attrs) do |xml_section|
130
- xml_section.preferred { |name| name << node.title }
131
- xml_section << node.content
132
- end
133
- end
134
-
135
- def term_def_title(toplevel, node)
136
- return node.title unless toplevel
137
- sub = node.find_by(context: :section) do |s|
138
- s.title.casecmp("symbols and abbreviated terms").zero?
139
- end
140
- return "Terms and definitions" if sub.empty?
141
- "Terms, definitions, symbols and abbreviated terms"
142
- end
143
-
144
- def term_def_parse(attrs, xml, node, toplevel)
145
- xml.terms **attr_code(attrs) do |section|
146
- section.title { |t| t << term_def_title(toplevel, node) }
147
- (s = node.attr("source")) && s.split(/,/).each do |s1|
148
- section.termdocsource(nil, **attr_code(bibitemid: s1, type: "inline"))
149
- end
150
- section << node.content
151
- end
152
- end
153
-
154
- def norm_ref_parse(attrs, xml, node)
155
- @norm_ref = true
156
- xml.references **attr_code(attrs) do |xml_section|
157
- xml_section.title { |t| t << "Normative References" }
158
- xml_section << node.content
159
- end
160
- @norm_ref = false
161
- end
162
-
163
- def introduction_parse(attrs, xml, node)
164
- xml.introduction **attr_code(attrs) do |xml_section|
165
- xml_section.title = "Introduction"
166
- content = node.content
167
- xml_section << content
168
- end
169
- end
170
-
171
56
  def patent_notice_parse(xml, node)
172
57
  # xml.patent_notice do |xml_section|
173
58
  # xml_section << node.content
@@ -1,4 +1,4 @@
1
- require "asciidoctor/iso/utils"
1
+ require "metanorma-standoc"
2
2
  require_relative "./validate_style.rb"
3
3
  require_relative "./validate_requirements.rb"
4
4
  require_relative "./validate_section.rb"
@@ -9,7 +9,7 @@ require "iev"
9
9
 
10
10
  module Asciidoctor
11
11
  module ISO
12
- module Validate
12
+ class Converter < Standoc::Converter
13
13
  def title_intro_validate(root)
14
14
  title_intro_en = root.at("//title-intro[@language='en']")
15
15
  title_intro_fr = root.at("//title-intro[@language='fr']")
@@ -98,7 +98,7 @@ module Asciidoctor
98
98
  end
99
99
 
100
100
  def onlychild_clause_validate(root)
101
- root.xpath(Utils::SUBCLAUSE_XPATH).each do |c|
101
+ root.xpath(Standoc::Utils::SUBCLAUSE_XPATH).each do |c|
102
102
  next unless c.xpath("../clause").size == 1
103
103
  title = c.at("./title")
104
104
  location = c["id"] || c.text[0..60] + "..."
@@ -168,23 +168,10 @@ module Asciidoctor
168
168
  end
169
169
  end
170
170
 
171
- SOURCELOCALITY = ".//locality[@type = 'clause']/referenceFrom".freeze
172
-
173
- def iev_validate(xmldoc)
174
- xmldoc.xpath("//term").each do |t|
175
- /^IEV($|\s|:)/.match(t&.at(".//origin/@citeas")&.text) or next
176
- pref = t.xpath("./preferred").inject([]) { |m, x| m << x&.text&.downcase }
177
- locality = t.xpath(SOURCELOCALITY)&.text or next
178
- iev = @iev.fetch(locality, xmldoc&.at("//language")&.text || "en") or next
179
- pref.include?(iev.downcase) or
180
- warn %(Term "#{pref[0]}" does not match IEV #{locality} "#{iev}")
181
- end
182
- end
183
-
184
171
  def content_validate(doc)
172
+ super
185
173
  title_validate(doc.root)
186
174
  isosubgroup_validate(doc.root)
187
- section_validate(doc)
188
175
  onlychild_clause_validate(doc.root)
189
176
  termdef_style(doc.root)
190
177
  iev_validate(doc.root)
@@ -193,34 +180,6 @@ module Asciidoctor
193
180
  locality_erefs_validate(doc.root)
194
181
  end
195
182
 
196
- def schema_validate(doc, filename)
197
- File.open(".tmp.xml", "w:UTF-8") { |f| f.write(doc.to_xml) }
198
- begin
199
- errors = Jing.new(filename).validate(".tmp.xml")
200
- rescue Jing::Error => e
201
- abort "what what what #{e}"
202
- end
203
- warn "Valid!" if errors.none?
204
- errors.each do |error|
205
- warn "#{error[:message]} @ #{error[:line]}:#{error[:column]}"
206
- end
207
- end
208
-
209
- # RelaxNG cannot cope well with wildcard attributes. So we strip
210
- # any attributes from FormattedString instances (which can contain
211
- # xs:any markup, and are signalled with @format) before validation.
212
- def formattedstr_strip(doc)
213
- doc.xpath("//*[@format]").each do |n|
214
- n.elements.each do |e|
215
- e.traverse do |e1|
216
- next unless e1.element?
217
- e1.each { |k, _v| e.delete(k) }
218
- end
219
- end
220
- end
221
- doc
222
- end
223
-
224
183
  def validate(doc)
225
184
  content_validate(doc)
226
185
  schema_validate(formattedstr_strip(doc.dup),