metanorma-standoc 2.0.7 → 2.1.0

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: 9e678173d52fd8197d0127f397b7f65349b72d26242d62c3cee8005e3057068b
4
- data.tar.gz: 4a5548452c906db7df68ead74453f49d484fe601791a35aeb22360e9abb0b2ea
3
+ metadata.gz: 1e7285f74dd3b2b9ab155b8bf7e334aeb45f453a20f1d4eaf94f39f42b9251d3
4
+ data.tar.gz: fdbad7c4cd96de56faacf360fdedaa0a0a5d24313c34b68ec2ab8e152db6a7c2
5
5
  SHA512:
6
- metadata.gz: 3b28ce6e459d29a0b457179ad2f97282ccf26109358ed8ab933d42e080d8ad1e4511d68c1470d16437c8dd71338ed8951f2a021335f135cf0d3d467d432e715a
7
- data.tar.gz: d54fc63c669aa31fc728d35f3761c4a853d1ef345d9010988157550073ff2e38feb6ad123be562ee323219d812fa3f414da17102d0c462801bd31aa0be50405d
6
+ metadata.gz: ce9033847b44804a9ba150db5e4840e1d3dafef077a9c5af52defd74321333c66a3053abc589ae02ee3c28d6fe42afbd568cdef8b1a529e5b2a97ea46ec95ae0
7
+ data.tar.gz: 6f498786e8222646f72fe88193797b0b0a23c30d1478cf78fad27862f19ece9c054ebe72c891ad671f5c03b4c8f06a659195cc77f359f517b1ffea02203ad22b
@@ -851,17 +851,46 @@
851
851
  </define>
852
852
  <define name="bplace">
853
853
  <element name="place">
854
- <optional>
855
- <attribute name="uri">
856
- <data type="anyURI"/>
857
- </attribute>
858
- </optional>
859
- <optional>
860
- <attribute name="region"/>
861
- </optional>
854
+ <choice>
855
+ <text/>
856
+ <group>
857
+ <ref name="bibliocity"/>
858
+ <zeroOrMore>
859
+ <ref name="biblioregion"/>
860
+ </zeroOrMore>
861
+ <zeroOrMore>
862
+ <ref name="bibliocountry"/>
863
+ </zeroOrMore>
864
+ </group>
865
+ </choice>
866
+ </element>
867
+ </define>
868
+ <define name="bibliocity">
869
+ <element name="city">
862
870
  <text/>
863
871
  </element>
864
872
  </define>
873
+ <define name="biblioregion">
874
+ <element name="region">
875
+ <ref name="RegionType"/>
876
+ </element>
877
+ </define>
878
+ <define name="bibliocountry">
879
+ <element name="country">
880
+ <ref name="RegionType"/>
881
+ </element>
882
+ </define>
883
+ <define name="RegionType">
884
+ <optional>
885
+ <attribute name="iso"/>
886
+ </optional>
887
+ <optional>
888
+ <attribute name="recommended">
889
+ <data type="boolean"/>
890
+ </attribute>
891
+ </optional>
892
+ <text/>
893
+ </define>
865
894
  <define name="bprice">
866
895
  <element name="price">
867
896
  <attribute name="currency"/>
@@ -12,12 +12,8 @@ module Metanorma
12
12
  end
13
13
 
14
14
  def note_attrs(node)
15
- attr_code(
16
- termnote_attrs(node).merge(
17
- type: node.attr("type"),
18
- beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil,
19
- ),
20
- )
15
+ attr_code(termnote_attrs(node).merge(admonition_core_attrs(node)
16
+ .merge(type: node.attr("type"))))
21
17
  end
22
18
 
23
19
  def sidebar_attrs(node)
@@ -73,15 +69,25 @@ module Metanorma
73
69
  end
74
70
 
75
71
  def admonition_attrs(node)
72
+ attr_code(keep_attrs(node).merge(id_attr(node)
73
+ .merge(admonition_core_attrs(node)
74
+ .merge(type: admonition_name(node)))))
75
+ end
76
+
77
+ def admonition_core_attrs(node)
78
+ { notag: node.attr("notag") == "true" ? "true" : nil,
79
+ coverpage: node.attr("coverpage") == "true" ? "true" : nil,
80
+ beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil,
81
+ unnumbered: node.attr("unnumbered") ||
82
+ (node.attr("notag") == "true") || nil }
83
+ end
84
+
85
+ def admonition_name(node)
76
86
  name = node.attr("name")
77
87
  a = node.attr("type") and ["danger", "safety precautions"].each do |t|
78
88
  name = t if a.casecmp(t).zero?
79
89
  end
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
+ name
85
91
  end
86
92
 
87
93
  def admonition(node)
@@ -73,11 +73,21 @@ module Metanorma
73
73
  end
74
74
  end
75
75
 
76
+ def single_subfigure_cleanup(xmldoc)
77
+ xmldoc.xpath("//figure[figure]").each do |e|
78
+ s = e.xpath("./figure")
79
+ return unless s.size == 1
80
+
81
+ s[0].replace(s[0].children)
82
+ end
83
+ end
84
+
76
85
  def figure_cleanup(xmldoc)
77
86
  figure_footnote_cleanup(xmldoc)
78
87
  figure_dl_cleanup1(xmldoc)
79
88
  figure_dl_cleanup2(xmldoc)
80
89
  subfigure_cleanup(xmldoc)
90
+ single_subfigure_cleanup(xmldoc)
81
91
  end
82
92
 
83
93
  ELEMS_ALLOW_NOTES = %w[p formula ul ol dl figure].freeze
@@ -20,8 +20,8 @@ module Metanorma
20
20
  text = text.gsub(%r{<stem type="AsciiMath">(.+?)</stem>}m) do
21
21
  "<amathstem>#{HTMLEntities.new.decode($1)}</amathstem>"
22
22
  end
23
- text = Html2Doc.asciimath_to_mathml(text,
24
- ["<amathstem>", "</amathstem>"])
23
+ text = Html2Doc.new({})
24
+ .asciimath_to_mathml(text, ["<amathstem>", "</amathstem>"])
25
25
  x = Nokogiri::XML(text)
26
26
  x.xpath("//*[local-name() = 'math'][not(parent::stem)]").each do |y|
27
27
  y.wrap("<stem type='MathML'></stem>")
@@ -68,10 +68,11 @@ module Metanorma
68
68
  def mi_italicise?(char)
69
69
  return false if char.length > 1
70
70
 
71
- if /\p{Greek}/.match?(char)
71
+ case char
72
+ when /\p{Greek}/
72
73
  (/\p{Lower}/.match(char) && !mathml_mi_italics[:lowergreek]) ||
73
74
  (/\p{Upper}/.match(char) && !mathml_mi_italics[:uppergreek])
74
- elsif /\p{Latin}/.match?(char)
75
+ when /\p{Latin}/
75
76
  (/\p{Lower}/.match(char) && !mathml_mi_italics[:lowerroman]) ||
76
77
  (/\p{Upper}/.match(char) && !mathml_mi_italics[:upperroman])
77
78
  else false
@@ -125,11 +125,8 @@ module Metanorma
125
125
  end
126
126
 
127
127
  def obligations_cleanup_info(xml)
128
- s = xml.at("//foreword") and s["obligation"] = "informative"
129
- s = xml.at("//introduction") and s["obligation"] = "informative"
130
- s = xml.at("//acknowledgements") and s["obligation"] = "informative"
131
- xml.xpath("//references").each { |r| r["obligation"] = "informative" }
132
- xml.xpath("//preface//clause").each do |r|
128
+ xml.xpath("//foreword | //introduction | //acknowledgements | "\
129
+ "//references | //preface//clause").each do |r|
133
130
  r["obligation"] = "informative"
134
131
  end
135
132
  end
@@ -158,29 +155,34 @@ module Metanorma
158
155
  def preface_clausebefore_cleanup(xmldoc)
159
156
  return unless xmldoc.at("//preface")
160
157
 
161
- unless ins = xmldoc.at("//preface").children.first
162
- xmldoc.at("//preface") << " "
163
- ins = xmldoc.at("//preface").children.first
164
- end
158
+ ins = insert_before(xmldoc, "//preface")
165
159
  xmldoc.xpath("//preface//*[@beforeclauses = 'true']").each do |x|
166
160
  x.delete("beforeclauses")
167
161
  ins.previous = x.remove
168
162
  end
163
+ xmldoc.xpath("//*[@coverpage = 'true']").each do |x|
164
+ ins.previous = x.remove
165
+ end
169
166
  end
170
167
 
171
168
  def sections_clausebefore_cleanup(xmldoc)
172
169
  return unless xmldoc.at("//sections")
173
170
 
174
- unless ins = xmldoc.at("//sections").children.first
175
- xmldoc.at("//sections") << " "
176
- ins = xmldoc.at("//sections").children.first
177
- end
171
+ ins = insert_before(xmldoc, "//sections")
178
172
  xmldoc.xpath("//sections//*[@beforeclauses = 'true']").each do |x|
179
173
  x.delete("beforeclauses")
180
174
  ins.previous = x.remove
181
175
  end
182
176
  end
183
177
 
178
+ def insert_before(xmldoc, xpath)
179
+ unless ins = xmldoc.at(xpath).children.first
180
+ xmldoc.at(xpath) << " "
181
+ ins = xmldoc.at(xpath).children.first
182
+ end
183
+ ins
184
+ end
185
+
184
186
  def floatingtitle_cleanup(xmldoc)
185
187
  pop_floating_title(xmldoc)
186
188
  floating_title_preface2sections(xmldoc)
@@ -32,6 +32,43 @@
32
32
  <ref name="DocumentType"/>
33
33
  </element>
34
34
  </define>
35
+ <define name="admonition">
36
+ <element name="admonition">
37
+ <attribute name="type">
38
+ <ref name="AdmonitionType"/>
39
+ </attribute>
40
+ <optional>
41
+ <attribute name="class"/>
42
+ </optional>
43
+ <attribute name="id">
44
+ <data type="ID"/>
45
+ </attribute>
46
+ <optional>
47
+ <attribute name="uri">
48
+ <data type="anyURI"/>
49
+ </attribute>
50
+ </optional>
51
+ <optional>
52
+ <attribute name="coverpage">
53
+ <data type="boolean"/>
54
+ </attribute>
55
+ </optional>
56
+ <optional>
57
+ <attribute name="notag">
58
+ <data type="boolean"/>
59
+ </attribute>
60
+ </optional>
61
+ <optional>
62
+ <ref name="tname"/>
63
+ </optional>
64
+ <zeroOrMore>
65
+ <ref name="paragraph-with-footnote"/>
66
+ </zeroOrMore>
67
+ <zeroOrMore>
68
+ <ref name="note"/>
69
+ </zeroOrMore>
70
+ </element>
71
+ </define>
35
72
  <define name="index">
36
73
  <element name="index">
37
74
  <optional>
@@ -851,6 +888,16 @@
851
888
  <ref name="MultilingualRenderingType"/>
852
889
  </attribute>
853
890
  </optional>
891
+ <optional>
892
+ <attribute name="coverpage">
893
+ <data type="boolean"/>
894
+ </attribute>
895
+ </optional>
896
+ <optional>
897
+ <attribute name="notag">
898
+ <data type="boolean"/>
899
+ </attribute>
900
+ </optional>
854
901
  <oneOrMore>
855
902
  <choice>
856
903
  <ref name="paragraph"/>
@@ -1178,6 +1225,7 @@
1178
1225
  <ref name="concept"/>
1179
1226
  <ref name="add"/>
1180
1227
  <ref name="del"/>
1228
+ <ref name="span"/>
1181
1229
  </choice>
1182
1230
  </define>
1183
1231
  <define name="add">
@@ -1204,6 +1252,14 @@
1204
1252
  </choice>
1205
1253
  </element>
1206
1254
  </define>
1255
+ <define name="span">
1256
+ <element name="span">
1257
+ <attribute name="class"/>
1258
+ <oneOrMore>
1259
+ <ref name="TextElement"/>
1260
+ </oneOrMore>
1261
+ </element>
1262
+ </define>
1207
1263
  <define name="concept">
1208
1264
  <element name="concept">
1209
1265
  <optional>
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "2.0.7".freeze
22
+ VERSION = "2.1.0".freeze
23
23
  end
24
24
  end
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_dependency "asciidoctor", "~> 2.0.0"
30
30
  spec.add_dependency "iev", "~> 0.3.0"
31
- spec.add_dependency "isodoc", "~> 2.0.0"
31
+ spec.add_dependency "isodoc", "~> 2.1.0"
32
32
  spec.add_dependency "metanorma-plugin-datastruct", "~> 0.2.0"
33
33
  spec.add_dependency "metanorma-plugin-lutaml"
34
34
  spec.add_dependency "ruby-jing"
@@ -658,7 +658,7 @@ RSpec.describe Metanorma::Standoc do
658
658
  #{ASCIIDOC_BLANK_HDR}
659
659
 
660
660
  [[ABC]]
661
- [CAUTION,type=Safety Precautions,keep-with-next="true",keep-lines-together="true",tag=X,multilingual-rendering=common]
661
+ [CAUTION,type=Safety Precautions,keep-with-next="true",keep-lines-together="true",tag=X,multilingual-rendering=common,notag=true]
662
662
  .Precautions
663
663
  ====
664
664
  While werewolves are hardy community members, keep in mind the following dietary concerns:
@@ -671,7 +671,7 @@ RSpec.describe Metanorma::Standoc do
671
671
  output = <<~OUTPUT
672
672
  #{BLANK_HDR}
673
673
  <sections>
674
- <admonition id="ABC" type="safety precautions" keep-with-next="true" keep-lines-together="true" tag='X' multilingual-rendering='common'>
674
+ <admonition id="ABC" type="safety precautions" keep-with-next="true" keep-lines-together="true" tag='X' multilingual-rendering='common' notag="true" unnumbered="true">
675
675
  <name>Precautions</name><p id="_">While werewolves are hardy community members, keep in mind the following dietary concerns:</p>
676
676
  <ol id="_" type="arabic">
677
677
  <li>
@@ -907,6 +907,29 @@ RSpec.describe Metanorma::Standoc do
907
907
  .to be_equivalent_to xmlpp(output)
908
908
  end
909
909
 
910
+ it "does not create subfigures if there is only one nested figure" do
911
+ input = <<~INPUT
912
+ #{ASCIIDOC_BLANK_HDR}
913
+ [[figureC-2]]
914
+ [.figure]
915
+ .Stages of gelatinization
916
+ ====
917
+ image::spec/examples/rice_images/rice_image3_1.png[]
918
+ ====
919
+ INPUT
920
+ output = <<~OUTPUT
921
+ #{BLANK_HDR}
922
+ <sections>
923
+ <figure id="figureC-2"><name>Stages of gelatinization</name>
924
+ <image src="spec/examples/rice_images/rice_image3_1.png" id="_" mimetype="image/png" height="auto" width="auto"/>
925
+ </figure>
926
+ </sections>
927
+ </standard-document>
928
+ OUTPUT
929
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
930
+ .to be_equivalent_to xmlpp(output)
931
+ end
932
+
910
933
  it "processes figures within examples" do
911
934
  input = <<~INPUT
912
935
  #{ASCIIDOC_BLANK_HDR}
@@ -985,6 +985,12 @@ RSpec.describe Metanorma::Standoc do
985
985
  ====
986
986
  Notice which is very important
987
987
  ====
988
+
989
+ [IMPORTANT,coverpage=true]
990
+ ====
991
+ Notice which is also very important
992
+ ====
993
+
988
994
  INPUT
989
995
  output = <<~OUTPUT
990
996
  #{BLANK_HDR}
@@ -992,6 +998,9 @@ RSpec.describe Metanorma::Standoc do
992
998
  <note id='_'>
993
999
  <p id='_'>Note which is very important</p>
994
1000
  </note>
1001
+ <admonition id='_' type='important' coverpage='true'>
1002
+ <p id='_'>Notice which is also very important</p>
1003
+ </admonition>
995
1004
  <foreword id='_' obligation='informative'>
996
1005
  <title>Foreword</title>
997
1006
  <p id='_'>Foreword</p>
@@ -2,8 +2,8 @@ require "spec_helper"
2
2
  require "relaton_iso"
3
3
 
4
4
  RSpec.describe Metanorma::Standoc do
5
- it "processes simple dl reference" do
6
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", *OPTIONS)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
5
+ it "processes simple dl reference" do
6
+ input = <<~INPUT
7
7
  #{ASCIIDOC_BLANK_HDR}
8
8
  [bibliography]
9
9
  == Normative References
@@ -36,6 +36,7 @@ RSpec.describe Metanorma::Standoc do
36
36
  completename::::: Jack
37
37
 
38
38
  INPUT
39
+ output = <<~OUTPUT
39
40
  #{BLANK_HDR}
40
41
  <sections>
41
42
  </sections><bibliography><references id="_" obligation="informative" normative="true">
@@ -69,10 +70,12 @@ RSpec.describe Metanorma::Standoc do
69
70
  </bibliography>
70
71
  </standard-document>
71
72
  OUTPUT
73
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
74
+ .to be_equivalent_to xmlpp(output)
72
75
  end
73
76
 
74
77
  it "processes complex dl reference" do
75
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", *OPTIONS)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
78
+ input = <<~INPUT
76
79
  #{ASCIIDOC_BLANK_HDR}
77
80
 
78
81
  == Clause
@@ -292,6 +295,7 @@ RSpec.describe Metanorma::Standoc do
292
295
  script::: Latn
293
296
 
294
297
  INPUT
298
+ output = <<~OUTPUT
295
299
  #{BLANK_HDR}
296
300
  <sections>
297
301
  <clause id='_' inline-header='false' obligation='normative'>
@@ -455,10 +459,12 @@ RSpec.describe Metanorma::Standoc do
455
459
  </bibitem></references></bibliography>
456
460
  </standard-document>
457
461
  OUTPUT
462
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
463
+ .to be_equivalent_to xmlpp(output)
458
464
  end
459
465
 
460
466
  it "processes complex dl reference with dot path keys" do
461
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", *OPTIONS)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
467
+ input = <<~INPUT
462
468
  #{ASCIIDOC_BLANK_HDR}
463
469
  [bibliography]
464
470
  == Normative References
@@ -621,6 +627,7 @@ RSpec.describe Metanorma::Standoc do
621
627
  series.formattedref.script:: Latn
622
628
 
623
629
  INPUT
630
+ output = <<~OUTPUT
624
631
  #{BLANK_HDR}
625
632
  <sections>
626
633
  </sections><bibliography><references id="_" obligation="informative" normative="true">
@@ -775,10 +782,12 @@ RSpec.describe Metanorma::Standoc do
775
782
  </bibitem></references></bibliography>
776
783
  </standard-document>
777
784
  OUTPUT
785
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
786
+ .to be_equivalent_to xmlpp(output)
778
787
  end
779
788
 
780
789
  it "processes mix of dl and default references" do
781
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", *OPTIONS)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
790
+ input = <<~INPUT
782
791
  #{ASCIIDOC_BLANK_HDR}
783
792
 
784
793
  == Section
@@ -818,6 +827,7 @@ RSpec.describe Metanorma::Standoc do
818
827
  completename::::: Jack
819
828
 
820
829
  INPUT
830
+ output = <<~OUTPUT
821
831
  #{BLANK_HDR}
822
832
  <sections>
823
833
  <clause id='_' inline-header='false' obligation='normative'>
@@ -864,5 +874,7 @@ RSpec.describe Metanorma::Standoc do
864
874
  </sections>
865
875
  </standard-document>
866
876
  OUTPUT
877
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
878
+ .to be_equivalent_to xmlpp(output)
867
879
  end
868
880
  end
@@ -1665,9 +1665,6 @@ RSpec.describe Metanorma::Standoc do
1665
1665
  <bibitem id='iso123' type='standard'>
1666
1666
  <fetched/>
1667
1667
  <title format='text/plain' language='en' script='Latn'>Network Configuration Access Control Model</title>
1668
- <uri type='xml'>
1669
- https://raw.githubusercontent.com/relaton/relaton-data-ietf/master/data/reference.RFC.8341.xml
1670
- </uri>
1671
1668
  <uri type='src'>https://www.rfc-editor.org/info/rfc8341</uri>
1672
1669
  <docidentifier type='RFC' primary="true">RFC 8341</docidentifier>
1673
1670
  <docidentifier type='RFC' scope='anchor'>RFC8341</docidentifier>
@@ -1725,9 +1722,6 @@ RSpec.describe Metanorma::Standoc do
1725
1722
  <bibitem id='iso124' type='standard'>
1726
1723
  <fetched/>
1727
1724
  <title format='text/plain' language='en' script='Latn'>Network Configuration Access Control Model</title>
1728
- <uri type='xml'>
1729
- https://raw.githubusercontent.com/relaton/relaton-data-ietf/master/data/reference.RFC.8341.xml
1730
- </uri>
1731
1725
  <uri type='src'>https://www.rfc-editor.org/info/rfc8341</uri>
1732
1726
  <docidentifier type='RFC' primary="true">RFC 8341</docidentifier>
1733
1727
  <docidentifier type='metanorma'>[1]</docidentifier>