metanorma-itu 0.2.8 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc42b5f0ce3f11b23b8bcd171e19342c3f2c237742e8084cb6545af5a56e954f
4
- data.tar.gz: 73ae3b1e5cf914b8e715e1ccb14b0492819cbe811334cbfe7c5b24787490f5bd
3
+ metadata.gz: e18def3906b392a164e0fc200836e95217ec2c0689d4721bc64ef4e8c3a7cc0d
4
+ data.tar.gz: 1d0ca7d8a3840c579f554fe32208a5b12fa7b9de960e68d2aca824ca103ab030
5
5
  SHA512:
6
- metadata.gz: 8f72656f8c80c6bff4e48aba41f45d0342fb6fc5e542eb0410908efb465862ba7f3b9dee3cc6ef4ef5175fa60fdb05570339d9718b99193f56d6b2e4818734b0
7
- data.tar.gz: 13071d691ced638d57cb4085835b359e00a7851c6198739159ccb5e675b491e34983fba7a89c16e6a090a3172a9e6ef577b46c2df4948125b279d7b510223c61
6
+ metadata.gz: d38ceb1119b8a45cad531b4fdad23b3186c1a0765c3f263e6daebdb1632020549c8838fb89a9d9f73983dfe7cadc71facdaec6d5d334df76f5e5eb80c219f2ab
7
+ data.tar.gz: 015be0de1ece74eb7efb1edda36282cf1979eab4b08a9bb5eed74d28ca9ed288ce1b68fdf9547bef8932b64d5cb222d7a271d5972615e9b994b51bcc9ea7b6bb
@@ -2,13 +2,14 @@
2
2
  # use ci-master https://github.com/metanorma/metanorma-build-scripts
3
3
  name: macos
4
4
 
5
- on: [push]
5
+ on: [push, pull_request]
6
6
 
7
7
  jobs:
8
8
  test-macos:
9
9
  name: Test on Ruby ${{ matrix.ruby }} macOS
10
10
  runs-on: macos-latest
11
11
  strategy:
12
+ fail-fast: false
12
13
  matrix:
13
14
  ruby: [ '2.6', '2.5', '2.4' ]
14
15
  steps:
@@ -20,7 +21,7 @@ jobs:
20
21
  architecture: 'x64'
21
22
  - name: Update gems
22
23
  run: |
23
- sudo gem install bundler -v "~> 2" --force
24
+ sudo gem install bundler --force
24
25
  bundle install --jobs 4 --retry 3
25
26
  - name: Use Node
26
27
  uses: actions/setup-node@v1
@@ -2,13 +2,14 @@
2
2
  # use ci-master https://github.com/metanorma/metanorma-build-scripts
3
3
  name: ubuntu
4
4
 
5
- on: [push]
5
+ on: [push, pull_request]
6
6
 
7
7
  jobs:
8
8
  test-linux:
9
9
  name: Test on Ruby ${{ matrix.ruby }} Ubuntu
10
10
  runs-on: ubuntu-latest
11
11
  strategy:
12
+ fail-fast: false
12
13
  matrix:
13
14
  ruby: [ '2.6', '2.5', '2.4' ]
14
15
  steps:
@@ -20,7 +21,7 @@ jobs:
20
21
  architecture: 'x64'
21
22
  - name: Update gems
22
23
  run: |
23
- gem install bundler -v "~> 2"
24
+ gem install bundler
24
25
  bundle install --jobs 4 --retry 3
25
26
  - name: Use Node
26
27
  uses: actions/setup-node@v1
@@ -2,13 +2,14 @@
2
2
  # use ci-master https://github.com/metanorma/metanorma-build-scripts
3
3
  name: windows
4
4
 
5
- on: [push]
5
+ on: [push, pull_request]
6
6
 
7
7
  jobs:
8
8
  test-windows:
9
9
  name: Test on Ruby ${{ matrix.ruby }} Windows
10
10
  runs-on: windows-latest
11
11
  strategy:
12
+ fail-fast: false
12
13
  matrix:
13
14
  ruby: [ '2.6', '2.5', '2.4' ]
14
15
  steps:
@@ -21,7 +22,7 @@ jobs:
21
22
  - name: Update gems
22
23
  shell: pwsh
23
24
  run: |
24
- gem install bundler -v "~> 2"
25
+ gem install bundler
25
26
  bundle config --local path vendor/bundle
26
27
  bundle update
27
28
  bundle install --jobs 4 --retry 3
@@ -1,11 +1,11 @@
1
1
  = metanorma-itu: Asciidoctor processor for ITU
2
2
 
3
3
  image:https://img.shields.io/gem/v/metanorma-itu.svg["Gem Version", link="https://rubygems.org/gems/metanorma-itu"]
4
- image:https://travis-ci.com/metanorma/metanorma-itu.svg?branch=master["Build Status", link="https://travis-ci.com/metanorma/metanorma-itu"]
4
+ image:https://travis-ci.com/metanorma/metanorma-itu.svg["Build Status", link="https://travis-ci.com/metanorma/metanorma-itu"]
5
+ image:https://ci.appveyor.com/api/projects/status/pl6lh4a9224ijbe1?svg=true["Appveyor Build Status", link="https://ci.appveyor.com/project/metanorma/metanorma-itu"]
5
6
  image:https://codeclimate.com/github/metanorma/metanorma-itu/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/metanorma-itu"]
6
- image:https://ci.appveyor.com/api/projects/status/lo05dblngrgx2tlq?svg=true["Appveyor Build Status", link="https://ci.appveyor.com/project/ribose/metanorma-itu"]
7
-
8
- WARNING: This gem is still under development.
7
+ image:https://img.shields.io/github/issues-pr-raw/metanorma/metanorma-itu.svg["Pull Requests", link="https://github.com/metanorma/metanorma-itu/pulls"]
8
+ image:https://img.shields.io/github/commits-since/metanorma/metanorma-itu/latest.svg["Commits since latest",link="https://github.com/metanorma/metanorma-itu/releases"]
9
9
 
10
10
  == Functionality
11
11
 
@@ -66,7 +66,6 @@ See https://www.metanorma.com/author/itu/[Write ITU-T documents with Metanorma].
66
66
 
67
67
  == Examples
68
68
 
69
- * link:spec/examples/rfc6350.adoc[] is an Metanorma Asciidoctor version of https://tools.ietf.org/html/rfc6350[RFC 6350].
70
- * link:spec/examples/rfc6350.html[] is an HTML file generated from the Asciidoctor.
71
- * link:spec/examples/rfc6350.doc[] is a Word document generated from the Asciidoctor.
69
+ * Example documents are avalable at the https://github.com/metanorma/mn-samples-itu[mn-samples-itu] repository.
70
+ * Document templates are available at the https://github.com/metanorma/mn-templates-itu[mn-templates-itu] repository.
72
71
 
@@ -1,9 +1,10 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
3
- <include href="biblio.rng"/>
4
- <start>
5
- <ref name="document"/>
6
- </start>
3
+ <include href="biblio.rng">
4
+ <start>
5
+ <ref name="document"/>
6
+ </start>
7
+ </include>
7
8
  <define name="document">
8
9
  <element name="document">
9
10
  <optional>
@@ -51,9 +52,9 @@
51
52
  <optional>
52
53
  <ref name="section-title"/>
53
54
  </optional>
54
- <optional>
55
+ <zeroOrMore>
55
56
  <ref name="BasicBlock"/>
56
- </optional>
57
+ </zeroOrMore>
57
58
  <zeroOrMore>
58
59
  <ref name="note"/>
59
60
  </zeroOrMore>
@@ -283,6 +284,9 @@
283
284
  <attribute name="id">
284
285
  <data type="ID"/>
285
286
  </attribute>
287
+ <optional>
288
+ <attribute name="alt"/>
289
+ </optional>
286
290
  <optional>
287
291
  <ref name="tname"/>
288
292
  </optional>
@@ -341,11 +345,6 @@
341
345
  </oneOrMore>
342
346
  </element>
343
347
  </define>
344
- <define name="tclass">
345
- <element name="name">
346
- <text/>
347
- </element>
348
- </define>
349
348
  <define name="thead">
350
349
  <element name="thead">
351
350
  <ref name="tr"/>
@@ -515,19 +514,22 @@
515
514
  <attribute name="subsequence"/>
516
515
  </optional>
517
516
  <optional>
518
- <ref name="source"/>
517
+ <attribute name="class"/>
519
518
  </optional>
520
519
  <optional>
521
- <ref name="tname"/>
520
+ <ref name="source"/>
522
521
  </optional>
523
522
  <optional>
524
- <ref name="tclass"/>
523
+ <ref name="tname"/>
525
524
  </optional>
526
525
  <choice>
527
526
  <ref name="image"/>
528
527
  <ref name="video"/>
529
528
  <ref name="audio"/>
530
529
  <ref name="pre"/>
530
+ <oneOrMore>
531
+ <ref name="paragraph-with-footnote"/>
532
+ </oneOrMore>
531
533
  <zeroOrMore>
532
534
  <ref name="figure"/>
533
535
  </zeroOrMore>
@@ -565,6 +567,7 @@
565
567
  <ref name="pagebreak"/>
566
568
  <ref name="bookmark"/>
567
569
  <ref name="image"/>
570
+ <ref name="index"/>
568
571
  </choice>
569
572
  </define>
570
573
  <define name="PureTextElement">
@@ -689,6 +692,17 @@
689
692
  <empty/>
690
693
  </element>
691
694
  </define>
695
+ <define name="index">
696
+ <element name="index">
697
+ <attribute name="primary"/>
698
+ <optional>
699
+ <attribute name="secondary"/>
700
+ </optional>
701
+ <optional>
702
+ <attribute name="tertiary"/>
703
+ </optional>
704
+ </element>
705
+ </define>
692
706
  <!-- bare ID element, used for referencing arbitrary spans of text -->
693
707
  <define name="bookmark">
694
708
  <element name="bookmark">
@@ -33,6 +33,9 @@
33
33
  <param name="pattern">([\+\-]?\d{4})((-?)((0[1-9]|1[0-2])((-?)([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6]))))?</param>
34
34
  </data>
35
35
  </define>
36
+ <start>
37
+ <ref name="bibitem"/>
38
+ </start>
36
39
  <define name="status">
37
40
  <element name="status">
38
41
  <ref name="stage"/>
@@ -275,10 +278,12 @@
275
278
  </define>
276
279
  <define name="organization">
277
280
  <element name="organization">
278
- <ref name="orgname"/>
279
- <optional>
281
+ <oneOrMore>
282
+ <ref name="orgname"/>
283
+ </oneOrMore>
284
+ <zeroOrMore>
280
285
  <ref name="subdivision"/>
281
- </optional>
286
+ </zeroOrMore>
282
287
  <optional>
283
288
  <ref name="abbreviation"/>
284
289
  </optional>
@@ -354,6 +359,9 @@
354
359
  </define>
355
360
  <define name="phone">
356
361
  <element name="phone">
362
+ <optional>
363
+ <attribute name="type"/>
364
+ </optional>
357
365
  <text/>
358
366
  </element>
359
367
  </define>
@@ -1021,6 +1029,8 @@
1021
1029
  <value>correctedBy</value>
1022
1030
  <value>revises</value>
1023
1031
  <value>revisedBy</value>
1032
+ <value>describes</value>
1033
+ <value>describedBy</value>
1024
1034
  </choice>
1025
1035
  </define>
1026
1036
  <define name="docrelation">
@@ -0,0 +1,118 @@
1
+ module Asciidoctor
2
+ module ITU
3
+ class Converter < Standoc::Converter
4
+ def sections_cleanup(x)
5
+ super
6
+ x.xpath("//*[@inline-header]").each do |h|
7
+ h.delete("inline-header")
8
+ end
9
+ end
10
+
11
+ def cleanup(xmldoc)
12
+ symbols_cleanup(xmldoc)
13
+ super
14
+ end
15
+
16
+ def smartquotes_cleanup(xmldoc)
17
+ return super if @smartquotes
18
+ xmldoc.traverse do |n|
19
+ next unless n.text?
20
+ n.replace(HTMLEntities.new.encode(
21
+ n.text.gsub(/\u2019|\u2018|\u201a|\u201b/, "'").
22
+ gsub(/\u201c|\u201d|\u201e|\u201f/, '"'), :basic))
23
+ end
24
+ xmldoc
25
+ end
26
+
27
+ def termdef_cleanup(xmldoc)
28
+ xmldoc.xpath("//term/preferred").each do |p|
29
+ if ["terms defined elsewhere",
30
+ "terms defined in this recommendation"].include? p.text.downcase
31
+ p.name = "title"
32
+ p.parent.name = "terms"
33
+ end
34
+ end
35
+ super
36
+ end
37
+
38
+ def termdef_boilerplate_cleanup(xmldoc)
39
+ end
40
+
41
+ def symbols_cleanup(xmldoc)
42
+ sym = xmldoc.at("//definitions/title")
43
+ sym and sym&.next_element&.name == "dl" and
44
+ sym.next = "<p>#{@symbols_boilerplate}</p>"
45
+ end
46
+
47
+ PUBLISHER = "./contributor[role/@type = 'publisher']/organization".freeze
48
+
49
+ def pub_class(bib)
50
+ return 1 if bib.at("#{PUBLISHER}[abbreviation = 'ITU']")
51
+ return 1 if bib.at("#{PUBLISHER}[name = 'International Telecommunication Union']")
52
+ return 2 if bib.at("#{PUBLISHER}[abbreviation = 'ISO']")
53
+ return 2 if bib.at("#{PUBLISHER}[name = 'International Organization "\
54
+ "for Standardization']")
55
+ return 3 if bib.at("#{PUBLISHER}[abbreviation = 'IEC']")
56
+ return 3 if bib.at("#{PUBLISHER}[name = 'International "\
57
+ "Electrotechnical Commission']")
58
+ return 4 if bib.at("./docidentifier[@type][not(@type = 'DOI' or "\
59
+ "@type = 'metanorma' or @type = 'ISSN' or @type = 'ISBN')]")
60
+ 5
61
+ end
62
+
63
+ def sort_biblio(bib)
64
+ bib.sort do |a, b|
65
+ sort_biblio_key(a) <=> sort_biblio_key(b)
66
+ end
67
+ end
68
+
69
+ # sort by: doc class (ITU, ISO, IEC, other standard (not DOI &c), other
70
+ # then standard class (docid class other than DOI &c)
71
+ # then alphanumeric doc id (not DOI &c)
72
+ # then title
73
+ def sort_biblio_key(bib)
74
+ pubclass = pub_class(bib)
75
+ num = bib&.at("./docnumber")&.text
76
+ id = bib&.at("./docidentifier[not(@type = 'DOI' or "\
77
+ "@type = 'metanorma' or @type = 'ISSN' or @type = 'ISBN')]")
78
+ metaid = bib&.at("./docidentifier[@type = 'metanorma']")&.text
79
+ abbrid = metaid unless /^\[\d+\]$/.match(metaid)
80
+ type = id['type'] if id
81
+ title = bib&.at("./title[@type = 'main']")&.text ||
82
+ bib&.at("./title")&.text || bib&.at("./formattedref")&.text
83
+ "#{pubclass} :: #{type} :: #{id&.text || metaid} :: #{title}"
84
+ end
85
+
86
+ def biblio_reorder(xmldoc)
87
+ xmldoc.xpath("//references").each do |r|
88
+ biblio_reorder1(r)
89
+ end
90
+ end
91
+
92
+ def boilerplate_cleanup(xmldoc)
93
+ super
94
+ initial_boilerplate(xmldoc)
95
+ end
96
+
97
+ def initial_boilerplate(x)
98
+ return if x.at("//boilerplate")
99
+ preface = x.at("//preface") || x.at("//sections") || x.at("//annex") ||
100
+ x.at("//references") || return
101
+ preface.previous = boilerplate(x)
102
+ end
103
+
104
+ def boilerplate(x_orig)
105
+ x = x_orig.dup
106
+ # TODO variable
107
+ x.root.add_namespace(nil, Metanorma::ITU::DOCUMENT_NAMESPACE)
108
+ x = Nokogiri::XML(x.to_xml)
109
+ conv = IsoDoc::ITU::HtmlConvert.new({})
110
+ conv.metadata_init("en", "Latn", {})
111
+ conv.info(x, nil)
112
+ file = @boilerplateauthority ? "#{@localdir}/#{@boilerplateauthority}" :
113
+ File.join(File.dirname(__FILE__), "itu_intro.xml")
114
+ conv.populate_template((File.read(file, encoding: "UTF-8")), nil)
115
+ end
116
+ end
117
+ end
118
+ end
@@ -3,6 +3,7 @@ require "asciidoctor/standoc/converter"
3
3
  require "fileutils"
4
4
  require_relative "./front.rb"
5
5
  require_relative "./validate.rb"
6
+ require_relative "./cleanup.rb"
6
7
  require_relative "./macros.rb"
7
8
 
8
9
  module Asciidoctor
@@ -12,16 +13,22 @@ module Asciidoctor
12
13
  # schema encapsulation of the document for validation
13
14
  #
14
15
  class Converter < Standoc::Converter
16
+ register_for "itu"
17
+
15
18
  Asciidoctor::Extensions.register do
16
- block PseudocodeBlockMacro
19
+ inline_macro AddMacro
20
+ inline_macro DelMacro
17
21
  end
18
22
 
19
- register_for "itu"
20
-
21
23
  def title_validate(root)
22
24
  nil
23
25
  end
24
26
 
27
+ def init(node)
28
+ super
29
+ @smartquotes = node.attr("smartquotes") == "true"
30
+ end
31
+
25
32
  def makexml(node)
26
33
  result = ["<?xml version='1.0' encoding='UTF-8'?>\n<itu-standard>"]
27
34
  @draft = node.attributes.has_key?("draft")
@@ -36,31 +43,20 @@ module Asciidoctor
36
43
  end
37
44
 
38
45
  def doctype(node)
39
- node.attr("doctype") || "recommendation"
40
- end
41
-
42
- def example(node)
43
- role = node.role || node.attr("style")
44
- return pseudocode_example(node) if role == "pseudocode"
45
- super
46
+ ret = node.attr("doctype") || "recommendation"
47
+ ret = "recommendation" if ret == "article"
48
+ ret
46
49
  end
47
50
 
48
- def pseudocode_example(node)
51
+ def olist(node)
49
52
  noko do |xml|
50
- xml.figure **{id: Asciidoctor::Standoc::Utils::anchor_or_uuid(node),
51
- type: "pseudocode"} do |ex|
52
- figure_title(node, ex)
53
- wrap_in_para(node, ex)
53
+ xml.ol **attr_code(id: Asciidoctor::Standoc::Utils::anchor_or_uuid(node),
54
+ class: node.attr("class")) do |xml_ol|
55
+ node.items.each { |item| li(xml_ol, item) }
54
56
  end
55
57
  end.join("\n")
56
58
  end
57
59
 
58
- def init_indent(s)
59
- /^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~ s
60
- prefix = prefix.gsub(/\t/, "&#xa0;&#xa0;&#xa0;&#xa0;").gsub(/ /, "&#xa0;")
61
- prefix + suffix
62
- end
63
-
64
60
  def clause_parse(attrs, xml, node)
65
61
  attrs[:preface] = true if node.attr("style") == "preface"
66
62
  super
@@ -101,18 +97,6 @@ module Asciidoctor
101
97
  File.join(File.dirname(__FILE__), "itu.rng"))
102
98
  end
103
99
 
104
- def sections_cleanup(x)
105
- super
106
- x.xpath("//*[@inline-header]").each do |h|
107
- h.delete("inline-header")
108
- end
109
- end
110
-
111
- def cleanup(xmldoc)
112
- symbols_cleanup(xmldoc)
113
- super
114
- end
115
-
116
100
  def style(n, t)
117
101
  return
118
102
  end
@@ -170,20 +154,6 @@ module Asciidoctor
170
154
  "Definitions"
171
155
  end
172
156
 
173
- def termdef_cleanup(xmldoc)
174
- xmldoc.xpath("//term/preferred").each do |p|
175
- if ["terms defined elsewhere",
176
- "terms defined in this recommendation"].include? p.text.downcase
177
- p.name = "title"
178
- p.parent.name = "terms"
179
- end
180
- end
181
- super
182
- end
183
-
184
- def termdef_boilerplate_cleanup(xmldoc)
185
- end
186
-
187
157
  def terms_extract(div)
188
158
  internal = nil
189
159
  external = nil
@@ -213,12 +183,6 @@ module Asciidoctor
213
183
 
214
184
  NORM_REF = "//bibliography/references[title = 'References']".freeze
215
185
 
216
- def symbols_cleanup(xmldoc)
217
- sym = xmldoc.at("//definitions/title")
218
- sym and sym&.next_element&.name == "dl" and
219
- sym.next = "<p>#{@symbols_boilerplate}</p>"
220
- end
221
-
222
186
  def load_yaml(lang, script)
223
187
  y = if @i18nyaml then YAML.load_file(@i18nyaml)
224
188
  elsif lang == "en"