metanorma-standoc 2.2.1.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90287c74936b7e6fa5c54537833e425fdc78deb260ce3a9f083cc53530ad66fc
4
- data.tar.gz: 273eb7dcaf62e8b9a8578f932b3ab45377bdf0b57ad254cab80b16b10e584586
3
+ metadata.gz: e1259358ae365bba52ab94c40d88b6cc9d4b1eb9b65a9f7fc8edef4bd77138e0
4
+ data.tar.gz: 6c348c7e3b1706287332368251d90fa277fee7e9a54a0fc0cd11e19f5464506b
5
5
  SHA512:
6
- metadata.gz: 167db30a6cbf87a30f2e1d97eeaafffb63e94699a7f077556ec23604de443fcfabc1a1de091e7fbb93ddf528482e980e0b23c976abbf2e7aae8ebbfbddbb686c
7
- data.tar.gz: 1925f23438f2cc30fcd898c4ceeb8aea39442a8b0575d2cf8fa91954e229a2384b954670e75a66fe052486ff12a6b3394512d49ae84d38ac5f5253cde3591715
6
+ metadata.gz: 602f12339e31a98c061ce7dc46d9fad6888b18e962942f110ebeea86f6739311b093578dbc8886a795bfcd01de790c40c134072449ff1e701779f2e29139a743
7
+ data.tar.gz: 39b93eb600aa0f18e21982174fc204eb36a9f28ae7e1e3b5a4a78ddfa9a05a440e6e3d6b94cdf7824dbd71b62880a193d5c88028ecd78d074c7c9361961966f6
@@ -10,6 +10,6 @@ on:
10
10
 
11
11
  jobs:
12
12
  rake:
13
- uses: metanorma/metanorma-build-scripts/.github/workflows/plantuml-rake.yml@main
13
+ uses: metanorma/ci/.github/workflows/plantuml-rake.yml@main
14
14
  secrets:
15
15
  pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
@@ -0,0 +1,24 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ name: release
4
+
5
+ on:
6
+ workflow_dispatch:
7
+ inputs:
8
+ next_version:
9
+ description: |
10
+ Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
11
+ required: true
12
+ default: 'skip'
13
+ push:
14
+ tags: [ v* ]
15
+
16
+ jobs:
17
+ release:
18
+ uses: metanorma/ci/.github/workflows/rubygems-release.yml@main
19
+ with:
20
+ next_version: ${{ github.event.inputs.next_version }}
21
+ secrets:
22
+ rubygems-api-key: ${{ secrets.METANORMA_CI_RUBYGEMS_API_KEY }}
23
+ pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
24
+
@@ -71,7 +71,7 @@ module Metanorma
71
71
  def init_reqt(node)
72
72
  @default_requirement_model = (node.attr("requirements-model") ||
73
73
  default_requirement_model)
74
- @reqt_models = Metanorma::Requirements
74
+ @reqt_models = requirements_processor
75
75
  .new({ default: @default_requirement_model })
76
76
  end
77
77
 
@@ -112,6 +112,10 @@ module Metanorma
112
112
  init_iev_caches(node)
113
113
  end
114
114
 
115
+ def requirements_processor
116
+ Metanorma::Requirements
117
+ end
118
+
115
119
  def document(node)
116
120
  ret = document1(node)
117
121
  clean_exit
@@ -225,9 +225,9 @@
225
225
  <zeroOrMore>
226
226
  <ref name="forename"/>
227
227
  </zeroOrMore>
228
- <zeroOrMore>
229
- <ref name="initial"/>
230
- </zeroOrMore>
228
+ <optional>
229
+ <ref name="formatted-initials"/>
230
+ </optional>
231
231
  <ref name="surname"/>
232
232
  <zeroOrMore>
233
233
  <ref name="addition"/>
@@ -247,8 +247,8 @@
247
247
  <ref name="LocalizedString"/>
248
248
  </element>
249
249
  </define>
250
- <define name="initial">
251
- <element name="initial">
250
+ <define name="formatted-initials">
251
+ <element name="formatted-initials">
252
252
  <ref name="LocalizedString"/>
253
253
  </element>
254
254
  </define>
@@ -264,6 +264,9 @@
264
264
  </define>
265
265
  <define name="forename">
266
266
  <element name="forename">
267
+ <optional>
268
+ <attribute name="initial"/>
269
+ </optional>
267
270
  <ref name="LocalizedString"/>
268
271
  </element>
269
272
  </define>
@@ -84,8 +84,8 @@ module Metanorma
84
84
  dl = clause.at("./dl") or return
85
85
  key = ""
86
86
  bib = dl.xpath("./dt | ./dd").each_with_object({}) do |dtd, m|
87
- (dtd.name == "dt" and key = dtd.text.sub(/:+$/, "")) or
88
- add_to_hash(m, key, dd_bib_extract(dtd))
87
+ (dtd.name == "dt" and key = dtd.text.sub(/:+$/, "")) and next
88
+ add_to_hash(m, key, dd_bib_extract(dtd))
89
89
  end
90
90
  clause.xpath("./clause").each do |c1|
91
91
  key = c1&.at("./title")&.text&.downcase&.strip
@@ -3,7 +3,7 @@ module Metanorma
3
3
  module Cleanup
4
4
  def requirement_cleanup(xmldoc)
5
5
  @reqt_models ||=
6
- Metanorma::Requirements.new({ default: @default_requirement_model })
6
+ requirements_processor.new({ default: @default_requirement_model })
7
7
  @reqt_models.requirement_cleanup(xmldoc)
8
8
  end
9
9
  end
@@ -25,9 +25,6 @@ module Metanorma
25
25
  preprocessor Metanorma::Standoc::Datamodel::DiagramPreprocessor
26
26
  preprocessor Metanorma::Plugin::Datastruct::Json2TextPreprocessor
27
27
  preprocessor Metanorma::Plugin::Datastruct::Yaml2TextPreprocessor
28
- preprocessor Metanorma::Plugin::Lutaml::LutamlPreprocessor
29
- preprocessor Metanorma::Plugin::Lutaml::LutamlUmlAttributesTablePreprocessor
30
- preprocessor Metanorma::Plugin::Lutaml::LutamlUmlDatamodelDescriptionPreprocessor
31
28
  inline_macro Metanorma::Standoc::PreferredTermInlineMacro
32
29
  inline_macro Metanorma::Standoc::SpanInlineMacro
33
30
  inline_macro Metanorma::Standoc::AltTermInlineMacro
@@ -56,15 +53,11 @@ module Metanorma
56
53
  inline_macro Metanorma::Standoc::ToCInlineMacro
57
54
  inline_macro Metanorma::Standoc::PassInlineMacro
58
55
  inline_macro Metanorma::Standoc::StdLinkInlineMacro
59
- inline_macro Metanorma::Plugin::Lutaml::LutamlFigureInlineMacro
60
- inline_macro Metanorma::Plugin::Lutaml::LutamlTableInlineMacro
61
- block_macro Metanorma::Plugin::Lutaml::LutamlDiagramBlockMacro
62
56
  block Metanorma::Standoc::ToDoAdmonitionBlock
63
57
  block Metanorma::Standoc::EditorAdmonitionBlock
64
58
  treeprocessor Metanorma::Standoc::EditorInlineAdmonitionBlock
65
59
  treeprocessor Metanorma::Standoc::ToDoInlineAdmonitionBlock
66
60
  block Metanorma::Standoc::PlantUMLBlockMacro
67
- block Metanorma::Plugin::Lutaml::LutamlDiagramBlock
68
61
  block Metanorma::Standoc::PseudocodeBlockMacro
69
62
  preprocessor Metanorma::Standoc::EmbedIncludeProcessor
70
63
  preprocessor Metanorma::Standoc::NamedEscapePreprocessor
@@ -103,16 +103,16 @@ module Metanorma
103
103
  class ConceptInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
104
104
  use_dsl
105
105
  named :concept
106
- match /\{\{(?<content>|.*?[^\\])\}\}/
106
+ match /\{\{(?<content>|.*?[^\\])\}\}/m
107
107
  using_format :short
108
108
 
109
109
  def preprocess_attrs(target)
110
- m = /^(?<id>&lt;&lt;.+?&gt;&gt;)?(?<rest>.*)$/.match(target)
110
+ m = /^(?<id>&lt;&lt;.+?&gt;&gt;)?(?<rest>.*)$/m.match(target)
111
111
  ret = { id: m[:id]&.sub(/^&lt;&lt;/, "")&.sub(/&gt;&gt;$/, "") }
112
- if m2 = /^(?<rest>.*?)(?<opt>,opt(?:ion)?s=.+)$/
112
+ if m2 = /^(?<rest>.*?)(?<opt>,opt(?:ion)?s=.+)$/m
113
113
  .match(m[:rest].sub(/^,/, ""))
114
114
  ret[:opt] = CSV.parse_line(m2[:opt].sub(/^,opt(ion)?s=/, "")
115
- .sub(/^"(.+)"$/, "\\1").sub(/^'(.+)'$/, "\\1"))
115
+ .sub(/^"(.+)"$/m, "\\1").sub(/^'(.+)'$/m, "\\1"))
116
116
  begin
117
117
  attrs = CSV.parse_line(m2[:rest]) || []
118
118
  rescue StandardError
@@ -125,6 +125,7 @@ module Metanorma
125
125
  raise "error processing #{m[:rest]} as CSV"
126
126
  end
127
127
  end
128
+ attrs.map! { |x| x.gsub(/\s+/, " ") }
128
129
  ret.merge(term: attrs[0], word: attrs[1] || attrs[0],
129
130
  render: attrs[2])
130
131
  end
@@ -31,6 +31,13 @@ module Metanorma
31
31
  @reqt_model = nil unless nested
32
32
  ret
33
33
  end
34
+
35
+ def requirement_validate(docxml)
36
+ docxml.xpath("//requirement | //recommendation | //permission")
37
+ .each do |r|
38
+ @reqt_models.model(r["model"]).validate(r, @log)
39
+ end
40
+ end
34
41
  end
35
42
  end
36
43
  end
@@ -56,17 +56,23 @@ module Metanorma
56
56
  return nonterm_term_def_subclause_parse(attrs, xml, node)
57
57
  node.role == "boilerplate" and
58
58
  return terms_boilerplate_parse(attrs, xml, node)
59
- st = sectiontype(node, false)
60
- return symbols_parse(attrs, xml, node) if @definitions
61
-
62
- sub = node.find_by(context: :section) { |s| s.level == node.level + 1 }
63
- sub.empty? || (return term_def_parse(attrs, xml, node, false))
64
- st == "symbols and abbreviated terms" and
59
+ @definitions and return symbols_parse(attrs, xml, node)
60
+ term_contains_subclauses(node) and
61
+ return term_def_parse(attrs, xml, node, false)
62
+ case sectiontype(node, false)
63
+ when "symbols and abbreviated terms"
65
64
  return symbols_parse(attrs, xml, node)
66
- st == "terms and definitions" and return clause_parse(attrs, xml, node)
65
+ when "terms and definitions"
66
+ return clause_parse(attrs, xml, node)
67
+ end
67
68
  term_def_subclause_parse1(attrs, xml, node)
68
69
  end
69
70
 
71
+ def term_contains_subclauses(node)
72
+ sub = node.find_by(context: :section) { |s| s.level == node.level + 1 }
73
+ !sub.empty?
74
+ end
75
+
70
76
  def term_def_subclause_parse1(attrs, xml, node)
71
77
  xml.term **attr_code(attrs) do |xml_section|
72
78
  term_designation(xml_section, node, "preferred", node.title)
@@ -4,6 +4,8 @@ require_relative "./validate_table"
4
4
  require "nokogiri"
5
5
  require "jing"
6
6
  require "iev"
7
+ require "pngcheck"
8
+ require "png"
7
9
 
8
10
  module Metanorma
9
11
  module Standoc
@@ -51,6 +53,8 @@ module Metanorma
51
53
  concept_validate(doc, "concept", "refterm")
52
54
  concept_validate(doc, "related", "preferred//name")
53
55
  table_validate(doc)
56
+ requirement_validate(doc)
57
+ image_validate(doc)
54
58
  @fatalerror.empty? or clean_abort(@fatalerror.join("\n"), doc.to_xml)
55
59
  end
56
60
 
@@ -154,6 +158,20 @@ module Metanorma
154
158
  end
155
159
  end
156
160
 
161
+ def image_validate(doc)
162
+ doc.xpath("//image[@mimetype = 'image/png']").each do |i|
163
+ d = Metanorma::Utils::datauri(i["src"], @localdir)
164
+ png_validate1(i, Base64.strict_decode64(d.sub(/^.+?base64,/, "")))
165
+ end
166
+ end
167
+
168
+ def png_validate1(img, buffer)
169
+ PngCheck.check_buffer(buffer)
170
+ rescue PngCheck::CorruptPngError => e
171
+ @log.add("Images", img.parent, "Corrupt PNG image")
172
+ @fatalerror << "Exception #{e.message}"
173
+ end
174
+
157
175
  def validate(doc)
158
176
  content_validate(doc)
159
177
  schema_validate(formattedstr_strip(doc.dup),
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "2.2.1.1".freeze
22
+ VERSION = "2.2.2".freeze
23
23
  end
24
24
  end
@@ -4,7 +4,7 @@ require_relative "metanorma/standoc/converter"
4
4
  require_relative "metanorma/standoc/version"
5
5
  require "asciidoctor/extensions"
6
6
 
7
- if defined? Metanorma
7
+ if defined? Metanorma::Registry
8
8
  require_relative "metanorma/standoc"
9
9
  Metanorma::Registry.instance.register(Metanorma::Standoc::Processor)
10
10
  end
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.add_dependency "asciidoctor", "~> 2.0.0"
29
29
  spec.add_dependency "iev", "~> 0.3.0"
30
- spec.add_dependency "isodoc", "~> 2.2.0"
30
+ spec.add_dependency "isodoc", "~> 2.2.3"
31
31
  spec.add_dependency "metanorma-plugin-datastruct", "~> 0.2.0"
32
32
  spec.add_dependency "metanorma-plugin-lutaml"
33
33
  spec.add_dependency "ruby-jing"
@@ -36,7 +36,9 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "concurrent-ruby"
37
37
  spec.add_dependency "latexmath"
38
38
  spec.add_dependency "mathml2asciimath"
39
- spec.add_dependency "mn-requirements", "~> 0.0.1"
39
+ spec.add_dependency "mn-requirements", "~> 0.1.3"
40
+ spec.add_dependency "png"
41
+ spec.add_dependency "pngcheck"
40
42
  spec.add_dependency "relaton-cli", "~> 1.13.0"
41
43
  spec.add_dependency "relaton-iev", "~> 1.1.0"
42
44
  spec.add_dependency "unicode2latex", "~> 0.0.1"
@@ -45,7 +47,6 @@ Gem::Specification.new do |spec|
45
47
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
46
48
  spec.add_development_dependency "guard", "~> 2.14"
47
49
  spec.add_development_dependency "guard-rspec", "~> 4.7"
48
- spec.add_development_dependency "metanorma-iso", "~>2.1.2"
49
50
  spec.add_development_dependency "rake", "~> 13.0"
50
51
  spec.add_development_dependency "rspec", "~> 3.6"
51
52
  spec.add_development_dependency "rubocop", "~> 1.5.2"
Binary file
Binary file
@@ -222,7 +222,7 @@ RSpec.describe Metanorma::Standoc do
222
222
  :iteration: 3
223
223
  :language: en
224
224
  :title: Main Title -- Title
225
- :library-ics: 1,2,3
225
+ :library-ics: 01.040.11,11.060.01
226
226
  :fullname: Fred Flintstone
227
227
  :role: author
228
228
  :affiliation: Slate Rock and Gravel Company
@@ -509,14 +509,13 @@ RSpec.describe Metanorma::Standoc do
509
509
  <technical-committee number="1" type="A">TC</technical-committee>
510
510
  <technical-committee number="11" type="A1">TC1</technical-committee>
511
511
  </editorialgroup>
512
- <ics>
513
- <code>1</code>
514
- </ics>
515
- <ics>
516
- <code>2</code>
512
+ <ics>
513
+ <code>01.040.11</code>
514
+ <text>Health care technology (Vocabularies)</text>
517
515
  </ics>
518
516
  <ics>
519
- <code>3</code>
517
+ <code>11.060.01</code>
518
+ <text>Dentistry in general</text>
520
519
  </ics>
521
520
  </ext>
522
521
  </bibdata>
@@ -6,6 +6,9 @@ RSpec.describe Metanorma::Standoc do
6
6
  #{ASCIIDOC_BLANK_HDR}
7
7
 
8
8
  {{clause1}}
9
+ {{clause two}}
10
+ {{clause
11
+ two}}
9
12
  term:[clause1]
10
13
  {{clause1,w\[o\]rd}}
11
14
  term:[clause1,w[o&#93;rd]
@@ -39,6 +42,22 @@ RSpec.describe Metanorma::Standoc do
39
42
  <tt>clause1</tt>
40
43
  </strong>
41
44
  </concept>
45
+ <concept>
46
+ <strong>
47
+ term
48
+ <tt>clause two</tt>
49
+ not resolved via ID
50
+ <tt>clause-two</tt>
51
+ </strong>
52
+ </concept>
53
+ <concept>
54
+ <strong>
55
+ term
56
+ <tt>clause two</tt>
57
+ not resolved via ID
58
+ <tt>clause-two</tt>
59
+ </strong>
60
+ </concept>
42
61
  <concept>
43
62
  <strong>
44
63
  term
@@ -933,102 +933,6 @@ RSpec.describe Metanorma::Standoc do
933
933
  .to be_equivalent_to xmlpp(output)
934
934
  end
935
935
 
936
- it "processes embed macro with document in a different flavour" do
937
- require "metanorma-iso"
938
- input = <<~INPUT
939
- #{ASCIIDOC_BLANK_HDR}
940
-
941
- [[clause1]]
942
- == Clause 1
943
-
944
- embed::spec/assets/iso.adoc[]
945
- INPUT
946
- output = <<~OUTPUT
947
- <standard-document xmlns='https://www.metanorma.org/ns/standoc' type='semantic' version='#{Metanorma::Standoc::VERSION}'>
948
- <bibdata type='standard'>
949
- <title language='en' format='text/plain'>Document title</title>
950
- <language>en</language>
951
- <script>Latn</script>
952
- <status>
953
- <stage>published</stage>
954
- </status>
955
- <copyright>
956
- <from>2022</from>
957
- </copyright>
958
- <ext>
959
- <doctype>standard</doctype>
960
- </ext>
961
- <relation type='derivedFrom'>
962
- <bibitem>
963
- <title language='en' format='text/plain' type='main'>
964
- Medical devices — Quality management systems — Requirements for
965
- regulatory purposes
966
- </title>
967
- <title language='en' format='text/plain' type='title-main'>
968
- Medical devices — Quality management systems — Requirements for
969
- regulatory purposes
970
- </title>
971
- <title language='fr' format='text/plain' type='main'>
972
- Dispositifs médicaux — Systèmes de management de la qualité —
973
- Exigences à des fins réglementaires
974
- </title>
975
- <title language='fr' format='text/plain' type='title-main'>
976
- Dispositifs médicaux — Systèmes de management de la qualité —
977
- Exigences à des fins réglementaires
978
- </title>
979
- <contributor>
980
- <role type='author'/>
981
- <organization>
982
- <name>International Organization for Standardization</name>
983
- <abbreviation>ISO</abbreviation>
984
- </organization>
985
- </contributor>
986
- <contributor>
987
- <role type='publisher'/>
988
- <organization>
989
- <name>International Organization for Standardization</name>
990
- <abbreviation>ISO</abbreviation>
991
- </organization>
992
- </contributor>
993
- <language>en</language>
994
- <script>Latn</script>
995
- <status>
996
- <stage abbreviation='IS'>60</stage>
997
- <substage>60</substage>
998
- </status>
999
- <copyright>
1000
- <from>2022</from>
1001
- <owner>
1002
- <organization>
1003
- <name>International Organization for Standardization</name>
1004
- <abbreviation>ISO</abbreviation>
1005
- </organization>
1006
- </owner>
1007
- </copyright>
1008
- <ext>
1009
- <doctype>standard</doctype>
1010
- <editorialgroup>
1011
- <agency>ISO</agency>
1012
- </editorialgroup>
1013
- <approvalgroup>
1014
- <agency>ISO</agency>
1015
- </approvalgroup>
1016
- <stagename>International standard</stagename>
1017
- </ext>
1018
- </bibitem>
1019
- </relation>
1020
- </bibdata>
1021
- <sections>
1022
- <clause id='clause1' inline-header='false' obligation='normative'>
1023
- <title>Clause 1</title>
1024
- </clause>
1025
- </sections>
1026
- </standard-document>
1027
- OUTPUT
1028
- expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
1029
- .to be_equivalent_to xmlpp(output)
1030
- end
1031
-
1032
936
  it "processes std-link macro" do
1033
937
  VCR.use_cassette("std-link", match_requests_on: %i[method uri body]) do
1034
938
  input = <<~INPUT
@@ -782,4 +782,53 @@ RSpec.describe Metanorma::Standoc do
782
782
  expect(File.read("test.err"))
783
783
  .not_to include "Symbol reference in `symbol[xyz]` missing:"
784
784
  end
785
+
786
+ it "warns and aborts if corrupt PNG" do
787
+ FileUtils.rm_f "test.xml"
788
+ FileUtils.rm_f "test.err"
789
+ begin
790
+ input = <<~INPUT
791
+ = Document title
792
+ Author
793
+ :docfile: test.adoc
794
+ :no-pdf:
795
+
796
+ == Clause
797
+ image::spec/assets/corrupt.png[]
798
+
799
+ INPUT
800
+ expect do
801
+ Asciidoctor.convert(input, *OPTIONS)
802
+ end.to raise_error(SystemExit)
803
+ rescue SystemExit, RuntimeError
804
+ end
805
+ warn File.read("test.err")
806
+ expect(File.read("test.err"))
807
+ .to include "Corrupt PNG image"
808
+ expect(File.exist?("test.xml")).to be false
809
+ end
810
+
811
+ it "does not warn and abort if not corrupt PNG" do
812
+ FileUtils.rm_f "test.xml"
813
+ FileUtils.rm_f "test.err"
814
+ begin
815
+ input = <<~INPUT
816
+ = Document title
817
+ Author
818
+ :docfile: test.adoc
819
+ :no-pdf:
820
+
821
+ == Clause
822
+ image::spec/assets/correct.png[]
823
+
824
+ INPUT
825
+ expect do
826
+ Asciidoctor.convert(input, *OPTIONS)
827
+ end.not_to raise_error
828
+ rescue SystemExit, RuntimeError
829
+ end
830
+ expect(File.read("test.err"))
831
+ .not_to include "Corrupt PNG image"
832
+ expect(File.exist?("test.xml")).to be true
833
+ end
785
834
  end