metanorma-standoc 1.10.7 → 1.10.8

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +19 -23
  3. data/lib/asciidoctor/standoc/base.rb +2 -0
  4. data/lib/asciidoctor/standoc/basicdoc.rng +21 -4
  5. data/lib/asciidoctor/standoc/blocks.rb +23 -23
  6. data/lib/asciidoctor/standoc/blocks_notes.rb +17 -22
  7. data/lib/asciidoctor/standoc/cleanup_image.rb +6 -7
  8. data/lib/asciidoctor/standoc/cleanup_inline.rb +25 -0
  9. data/lib/asciidoctor/standoc/cleanup_ref.rb +5 -0
  10. data/lib/asciidoctor/standoc/isodoc.rng +192 -50
  11. data/lib/asciidoctor/standoc/lists.rb +15 -15
  12. data/lib/asciidoctor/standoc/macros_terms.rb +6 -3
  13. data/lib/asciidoctor/standoc/reqt.rng +23 -2
  14. data/lib/asciidoctor/standoc/validate.rb +23 -14
  15. data/lib/asciidoctor/standoc/validate_section.rb +5 -2
  16. data/lib/metanorma/standoc/version.rb +1 -1
  17. data/spec/asciidoctor/blocks_spec.rb +28 -28
  18. data/spec/asciidoctor/cleanup_spec.rb +83 -90
  19. data/spec/asciidoctor/lists_spec.rb +6 -6
  20. data/spec/asciidoctor/macros_spec.rb +1 -1
  21. data/spec/asciidoctor/refs_spec.rb +2 -2
  22. data/spec/asciidoctor/validate_spec.rb +28 -0
  23. data/spec/spec_helper.rb +5 -7
  24. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +41 -41
  25. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +10 -10
  26. data/spec/vcr_cassettes/isobib_get_123.yml +11 -11
  27. data/spec/vcr_cassettes/isobib_get_123_1.yml +21 -21
  28. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +29 -29
  29. data/spec/vcr_cassettes/isobib_get_123_2001.yml +11 -11
  30. data/spec/vcr_cassettes/isobib_get_124.yml +10 -10
  31. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
  32. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +64 -44
  33. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90fb9b89f2c7070b763519843f307f4d3ecebb8ee462d7017afb886a397de8a8
4
- data.tar.gz: b6f2e8253577f05a76e833d3a1e5d9f64fd47a7de48d8ec6703056b04965096a
3
+ metadata.gz: 2cc836755aed6cfff989fdcbc9cf8123ccfda29418247d93fdd75ba71660cee7
4
+ data.tar.gz: d1c051429283a6e4153a6a3453b839786561c0975c2acda0586cb0ca787ae26a
5
5
  SHA512:
6
- metadata.gz: 17eb330f74f079b78db600f8030c15e497b6e0b1251157b9499cf532974280e6d4bb61ebe7d4c52cc443ca4d407371b575f6425783aa384e4c977733de528c5e
7
- data.tar.gz: f3063d8116e77c1e00cf6f9ba12668e5bfbb581d41e02e9d4c4fee2dc21884754f8102a718d7318d3b0619abaf1715528162e9aebcb97895a7ab85bbeb6fccd4
6
+ metadata.gz: 1e17a3351bf46679b587a82498d5f58d97e43743bd2e6906c929aa8dcbb8ca29fdd6e38acb82252375b40e5fff520f7d6a001b023c9c79681ad61fea949c0799
7
+ data.tar.gz: 01dd1e74b7990b44c526616611155067c0725b0b0bcaeebe9d728c341d26acdab64c2c5be7519b22b94fd641015aec504c333c3b3da8cf6067c19999c20ab0ff
data/README.adoc CHANGED
@@ -10,26 +10,24 @@ Gem for serialising the https://github.com/metanorma/metanorma-model-standoc[Met
10
10
 
11
11
  == Functionality
12
12
 
13
- This gem processes Metanorma documents following a template for generating standards documents, according
14
- to a range of standards classes. This gem provides underlying generic functionality; behaviour specific
15
- to each standards class is refined in the gem specific to that standards class (e.g. https://github.com/metanorma/metanorma-iso).
16
- The following outputs are generated.
17
-
18
- * Metanorma XML representation of the document, intended as a document model for
19
- Standards. The Metanorma XML representation is processed in turn, to generate one or more of
20
- the following outputs as end deliverables, depending on each standards class gem:
21
- * Microsoft Word output (`.doc`)
22
- * HTML output (`.html`)
23
- * PDF (`.pdf`)
13
+ This gem processes Metanorma AsciiDoc input into the Metanorma document model.
14
+ This gem provides underlying generic functionality; behaviour specific
15
+ to each standards class is refined in the gem specific to that standards class
16
+ (e.g. https://github.com/metanorma/metanorma-iso[Metanorma ISO]).
17
+
18
+ The following outputs are generated:
19
+
20
+ * Metanorma semantic XML
21
+ * Metanorma presentation XML
22
+
23
+ These Metanorma XML representations are processed downstream by the `isodoc` gem
24
+ to generate other end deliverables, depending on each standards class.
24
25
 
25
26
  The following input formats are supported:
26
27
 
27
- * http://asciidoctor.org/[Asciidoctor]
28
+ * Metanorma AsciiDoc
28
29
 
29
- This README provides an overview of the functionality of the gem; see also
30
- https://github.com/metanorma/metanorma-iso/blob/master/docs/guidance.adoc[Guidance for authoring].
31
- https://github.com/metanorma/metanorma-iso/blob/master/docs/quickstart.adoc[Quickstart guide]
32
- gives a summary overview.
30
+ See the https://www.metanorma.org[Metanorma website] for more information.
33
31
 
34
32
  NOTE: http://asciimath.org[AsciiMathML] is used for mathematical formatting.
35
33
  The gem uses the https://github.com/asciidoctor/asciimath[Ruby AsciiMath parser],
@@ -39,21 +37,19 @@ expressions.
39
37
 
40
38
  === Installation
41
39
 
42
- If you are using a Mac, the https://github.com/metanorma/metanorma-macos-setup
43
- repository has instructions on setting up your machine to run Metanorma
44
- scripts such as this one. You need only run the following in a Terminal console:
40
+ See the https://www.metanorma.org[Metanorma website] for instructions.
41
+
42
+ In the terminal:
45
43
 
46
44
  [source,console]
47
45
  ----
48
- $ bash <(curl -s https://raw.githubusercontent.com/metanorma/metanorma-macos-setup/master/metanorma-setup)
49
46
  $ gem install metanorma-standoc
50
47
  $ gem install metanorma-cli
51
48
  ----
52
49
 
53
- The metanorma-cli gem is the command-line interface for the Metanorma tool suite
50
+ `metanorma-cli` is the command-line interface for the Metanorma suite
54
51
  (incorporating the `metanorma` executable seen above).
55
52
 
56
53
  == Documentation
57
54
 
58
- See http://metanorma.com[]
59
-
55
+ See the https://www.metanorma.org[Metanorma website] for details.
@@ -46,6 +46,7 @@ module Asciidoctor
46
46
  bare: node.attr("bare"),
47
47
  sectionsplit: node.attr("sectionsplit"),
48
48
  baseassetpath: node.attr("base-asset-path"),
49
+ aligncrosselements: node.attr("align-cross-elements"),
49
50
  }
50
51
  end
51
52
 
@@ -81,6 +82,7 @@ module Asciidoctor
81
82
  suppressasciimathdup: node.attr("suppress-asciimath-dup"),
82
83
  bare: node.attr("bare"),
83
84
  baseassetpath: node.attr("base-asset-path"),
85
+ aligncrosselements: node.attr("align-cross-elements"),
84
86
  }
85
87
 
86
88
  if font_manifest_file = node.attr("mn2pdf-font-manifest-file")
@@ -624,6 +624,9 @@
624
624
  <choice>
625
625
  <ref name="PureTextElement"/>
626
626
  <ref name="stem"/>
627
+ <ref name="eref"/>
628
+ <ref name="xref"/>
629
+ <ref name="hyperlink"/>
627
630
  </choice>
628
631
  </zeroOrMore>
629
632
  </element>
@@ -634,6 +637,9 @@
634
637
  <choice>
635
638
  <ref name="PureTextElement"/>
636
639
  <ref name="stem"/>
640
+ <ref name="eref"/>
641
+ <ref name="xref"/>
642
+ <ref name="hyperlink"/>
637
643
  </choice>
638
644
  </zeroOrMore>
639
645
  </element>
@@ -641,7 +647,12 @@
641
647
  <define name="tt">
642
648
  <element name="tt">
643
649
  <zeroOrMore>
644
- <ref name="PureTextElement"/>
650
+ <choice>
651
+ <ref name="PureTextElement"/>
652
+ <ref name="eref"/>
653
+ <ref name="xref"/>
654
+ <ref name="hyperlink"/>
655
+ </choice>
645
656
  </zeroOrMore>
646
657
  </element>
647
658
  </define>
@@ -822,7 +833,9 @@
822
833
  <attribute name="alt"/>
823
834
  </optional>
824
835
  <ref name="CitationType"/>
825
- <text/>
836
+ <oneOrMore>
837
+ <ref name="PureTextElement"/>
838
+ </oneOrMore>
826
839
  </define>
827
840
  <define name="hyperlink">
828
841
  <element name="link">
@@ -835,7 +848,9 @@
835
848
  <optional>
836
849
  <attribute name="alt"/>
837
850
  </optional>
838
- <text/>
851
+ <oneOrMore>
852
+ <ref name="PureTextElement"/>
853
+ </oneOrMore>
839
854
  </element>
840
855
  </define>
841
856
  <define name="xref">
@@ -849,7 +864,9 @@
849
864
  <optional>
850
865
  <attribute name="alt"/>
851
866
  </optional>
852
- <text/>
867
+ <oneOrMore>
868
+ <ref name="PureTextElement"/>
869
+ </oneOrMore>
853
870
  </element>
854
871
  </define>
855
872
  <define name="fn">
@@ -6,14 +6,17 @@ module Asciidoctor
6
6
  module Standoc
7
7
  module Blocks
8
8
  def id_attr(node = nil)
9
- { id: Metanorma::Utils::anchor_or_uuid(node) }
9
+ { id: Metanorma::Utils::anchor_or_uuid(node),
10
+ tag: node&.attr("tag"),
11
+ "multilingual-rendering": node&.attr("multilingual-rendering") }
10
12
  end
11
13
 
12
14
  def id_unnum_attrs(node)
13
- attr_code(id: Metanorma::Utils::anchor_or_uuid(node),
14
- unnumbered: node.option?("unnumbered") ? "true" : nil,
15
- number: node.attr("number"),
16
- subsequence: node.attr("subsequence"))
15
+ attr_code(id_attr(node).merge(
16
+ unnumbered: node.option?("unnumbered") ? "true" : nil,
17
+ number: node.attr("number"),
18
+ subsequence: node.attr("subsequence"),
19
+ ))
17
20
  end
18
21
 
19
22
  def formula_attrs(node)
@@ -43,10 +46,9 @@ module Asciidoctor
43
46
 
44
47
  def form(node)
45
48
  noko do |xml|
46
- xml.form **attr_code(
47
- id: Metanorma::Utils::anchor_or_uuid, class: node.attr("class"),
48
- name: node.attr("name"), action: node.attr("action")
49
- ) do |f|
49
+ xml.form **attr_code(id_attr(node)
50
+ .merge(class: node.attr("class"),
51
+ name: node.attr("name"), action: node.attr("action"))) do |f|
50
52
  f << node.content
51
53
  end
52
54
  end
@@ -78,7 +80,7 @@ module Asciidoctor
78
80
 
79
81
  def term_example(node)
80
82
  noko do |xml|
81
- xml.termexample **id_attr(node) do |ex|
83
+ xml.termexample **attr_code(id_attr(node)) do |ex|
82
84
  wrap_in_para(node, ex)
83
85
  end
84
86
  end.join("\n")
@@ -100,10 +102,11 @@ module Asciidoctor
100
102
  end
101
103
 
102
104
  def svgmap_attrs(node)
103
- attr_code({ id: node.id,
104
- unnumbered: node.option?("unnumbered") ? "true" : nil,
105
- number: node.attr("number"),
106
- subsequence: node.attr("subsequence") }
105
+ attr_code(id_attr(node)
106
+ .merge(id: node.id,
107
+ unnumbered: node.option?("unnumbered") ? "true" : nil,
108
+ number: node.attr("number"),
109
+ subsequence: node.attr("subsequence"))
107
110
  .merge(keep_attrs(node)))
108
111
  end
109
112
 
@@ -162,11 +165,10 @@ module Asciidoctor
162
165
  end
163
166
 
164
167
  def para_attrs(node)
165
- attr_code(keep_attrs(node)
168
+ attr_code(id_attr(node).merge(keep_attrs(node)
166
169
  .merge(align: node.attr("align"),
167
170
  variant_title: node.role == "variant-title" ? true : nil,
168
- type: node.attr("type"),
169
- id: Metanorma::Utils::anchor_or_uuid(node)))
171
+ type: node.attr("type"))))
170
172
  end
171
173
 
172
174
  def paragraph(node)
@@ -180,9 +182,8 @@ module Asciidoctor
180
182
  end
181
183
 
182
184
  def quote_attrs(node)
183
- attr_code(keep_attrs(node)
184
- .merge(align: node.attr("align"),
185
- id: Metanorma::Utils::anchor_or_uuid(node)))
185
+ attr_code(id_attr(node).merge(keep_attrs(node))
186
+ .merge(align: node.attr("align")))
186
187
  end
187
188
 
188
189
  def quote_attribution(node, out)
@@ -206,12 +207,11 @@ module Asciidoctor
206
207
  end
207
208
 
208
209
  def listing_attrs(node)
209
- attr_code(keep_attrs(node)
210
+ attr_code(id_attr(node).merge(keep_attrs(node)
210
211
  .merge(lang: node.attr("language"),
211
- id: Metanorma::Utils::anchor_or_uuid(node),
212
212
  unnumbered: node.option?("unnumbered") ? "true" : nil,
213
213
  number: node.attr("number"),
214
- filename: node.attr("filename")))
214
+ filename: node.attr("filename"))))
215
215
  end
216
216
 
217
217
  # NOTE: html escaping is performed by Nokogiri
@@ -2,24 +2,21 @@ module Asciidoctor
2
2
  module Standoc
3
3
  module Blocks
4
4
  def termnote_attrs(node)
5
- attr_code(
6
- id_attr(node).merge(
5
+ attr_code(id_attr(node).merge(keep_attrs(node)
6
+ .merge(
7
7
  unnumbered: node.attr("unnumbered"),
8
8
  number: node.attr("number"),
9
9
  subsequence: node.attr("subsequence"),
10
- "keep-with-next": node.attr("keep-with-next"),
11
- "keep-lines-together": node.attr("keep-with-next"),
12
- "keep-separate": node.attr("keep-separate")
13
- )
14
- )
10
+ "keep-separate": node.attr("keep-separate"),
11
+ )))
15
12
  end
16
13
 
17
14
  def note_attrs(node)
18
15
  attr_code(
19
16
  termnote_attrs(node).merge(
20
17
  type: node.attr("type"),
21
- beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil
22
- )
18
+ beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil,
19
+ ),
23
20
  )
24
21
  end
25
22
 
@@ -27,8 +24,8 @@ module Asciidoctor
27
24
  todo_attrs(node).merge(
28
25
  attr_code(
29
26
  from: node.attr("from"),
30
- to: node.attr("to") || node.attr("from")
31
- )
27
+ to: node.attr("to") || node.attr("from"),
28
+ ),
32
29
  )
33
30
  end
34
31
 
@@ -45,11 +42,10 @@ module Asciidoctor
45
42
  def todo_attrs(node)
46
43
  date = node.attr("date") || Date.today.iso8601.gsub(/\+.*$/, "")
47
44
  date += "T00:00:00Z" unless /T/.match? date
48
- attr_code(
49
- id: ::Metanorma::Utils::anchor_or_uuid(node),
50
- reviewer: node.attr("reviewer") || node.attr("source") || "(Unknown)",
51
- date: date
52
- )
45
+ attr_code(id_attr(node)
46
+ .merge(reviewer: node.attr("reviewer") || node.attr("source") ||
47
+ "(Unknown)",
48
+ date: date))
53
49
  end
54
50
 
55
51
  def todo(node)
@@ -81,12 +77,11 @@ module Asciidoctor
81
77
  a = node.attr("type") and ["danger", "safety precautions"].each do |t|
82
78
  name = t if a.casecmp(t).zero?
83
79
  end
84
- attr_code(
85
- keep_attrs(node).merge(
86
- id: Metanorma::Utils::anchor_or_uuid(node), type: name,
87
- beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil
88
- )
89
- )
80
+ attr_code(keep_attrs(node).merge(id_attr(node)
81
+ .merge(
82
+ type: name,
83
+ beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil,
84
+ )))
90
85
  end
91
86
 
92
87
  def admonition(node)
@@ -15,9 +15,8 @@ module Asciidoctor
15
15
  def svgmap_moveattrs(xmldoc)
16
16
  xmldoc.xpath("//svgmap").each do |s|
17
17
  f = s.at(".//figure") or next
18
- if (t = s.at("./name")) && !f.at("./name")
18
+ (t = s.at("./name")) && !f.at("./name") and
19
19
  f.children.first.previous = t.remove
20
- end
21
20
  if s["id"] && guid?(f["id"])
22
21
  f["id"] = s["id"]
23
22
  s.delete("id")
@@ -26,13 +25,13 @@ module Asciidoctor
26
25
  end
27
26
  end
28
27
 
29
- def svgmap_moveattrs1(s, f)
28
+ def svgmap_moveattrs1(svgmap, figure)
30
29
  %w(unnumbered number subsequence keep-with-next
31
- keep-lines-together).each do |a|
32
- next if f[a] || !s[a]
30
+ keep-lines-together tag multilingual-rendering).each do |a|
31
+ next if figure[a] || !svgmap[a]
33
32
 
34
- f[a] = s[a]
35
- s.delete(a)
33
+ figure[a] = svgmap[a]
34
+ svgmap.delete(a)
36
35
  end
37
36
  end
38
37
 
@@ -1,4 +1,5 @@
1
1
  require "metanorma-utils"
2
+ require "digest"
2
3
 
3
4
  module Asciidoctor
4
5
  module Standoc
@@ -112,6 +113,7 @@ module Asciidoctor
112
113
  def anchor_cleanup(elem)
113
114
  anchor_cleanup1(elem)
114
115
  xreftarget_cleanup(elem)
116
+ contenthash_id_cleanup(elem)
115
117
  end
116
118
 
117
119
  def anchor_cleanup1(elem)
@@ -137,6 +139,29 @@ module Asciidoctor
137
139
  end
138
140
  end
139
141
  end
142
+
143
+ def guid?(str)
144
+ /^_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
145
+ .match?(str)
146
+ end
147
+
148
+ def contenthash_id_cleanup(doc)
149
+ ids = doc.xpath("//*[@id]").each_with_object({}) do |x, m|
150
+ next unless guid?(x["id"])
151
+
152
+ m[x["id"]] = contenthash(x)
153
+ x["id"] = m[x["id"]]
154
+ end
155
+ [%w(review from), %(review to), %(callout target), %(eref bibitemid),
156
+ %(citation bibitemid), %(xref target), %(xref to)].each do |a|
157
+ doc.xpath("//#{a[0]}").each { |x| ids[a[1]] and x[a[1]] = ids[a[1]] }
158
+ end
159
+ end
160
+
161
+ def contenthash(elem)
162
+ Digest::MD5.hexdigest("#{elem.path}////#{elem.text}")
163
+ .sub(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "_\\1-\\2-\\3-\\4-\\5")
164
+ end
140
165
  end
141
166
  end
142
167
  end
@@ -84,6 +84,11 @@ module Asciidoctor
84
84
  biblio_reorder(xmldoc)
85
85
  biblio_nested(xmldoc)
86
86
  biblio_renumber(xmldoc)
87
+ biblio_no_ext(xmldoc)
88
+ end
89
+
90
+ def biblio_no_ext(xmldoc)
91
+ xmldoc.xpath("//bibitem/ext").each(&:remove)
87
92
  end
88
93
 
89
94
  def biblio_nested(xmldoc)