metanorma-standoc 3.0.3 → 3.0.5

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 (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/isodoc/html/htmlstyle.css +7 -0
  3. data/lib/metanorma/standoc/base.rb +5 -7
  4. data/lib/metanorma/standoc/basicdoc.rng +48 -35
  5. data/lib/metanorma/standoc/biblio-standoc.rng +37 -7
  6. data/lib/metanorma/standoc/biblio.rng +30 -18
  7. data/lib/metanorma/standoc/blocks.rb +21 -1
  8. data/lib/metanorma/standoc/cleanup.rb +2 -0
  9. data/lib/metanorma/standoc/cleanup_bibdata.rb +17 -5
  10. data/lib/metanorma/standoc/cleanup_block.rb +1 -1
  11. data/lib/metanorma/standoc/cleanup_inline.rb +7 -6
  12. data/lib/metanorma/standoc/cleanup_maths.rb +2 -3
  13. data/lib/metanorma/standoc/cleanup_review.rb +60 -0
  14. data/lib/metanorma/standoc/cleanup_section.rb +3 -38
  15. data/lib/metanorma/standoc/cleanup_section_names.rb +25 -0
  16. data/lib/metanorma/standoc/cleanup_table.rb +22 -0
  17. data/lib/metanorma/standoc/cleanup_text.rb +11 -31
  18. data/lib/metanorma/standoc/cleanup_xref.rb +2 -37
  19. data/lib/metanorma/standoc/converter.rb +2 -0
  20. data/lib/metanorma/standoc/front.rb +6 -3
  21. data/lib/metanorma/standoc/init.rb +1 -0
  22. data/lib/metanorma/standoc/inline.rb +0 -1
  23. data/lib/metanorma/standoc/isodoc.rng +126 -80
  24. data/lib/metanorma/standoc/macros_inline.rb +27 -1
  25. data/lib/metanorma/standoc/macros_note.rb +0 -1
  26. data/lib/metanorma/standoc/ref.rb +4 -26
  27. data/lib/metanorma/standoc/regex.rb +78 -0
  28. data/lib/metanorma/standoc/reqt.rng +7 -6
  29. data/lib/metanorma/standoc/section.rb +1 -1
  30. data/lib/metanorma/standoc/terms.rb +2 -9
  31. data/lib/metanorma/standoc/utils.rb +8 -0
  32. data/lib/metanorma/standoc/validate.rb +2 -46
  33. data/lib/metanorma/standoc/validate_schema.rb +104 -0
  34. data/lib/metanorma/standoc/version.rb +1 -1
  35. data/metanorma-standoc.gemspec +2 -2
  36. metadata +9 -7
  37. data/Gemfile.devel +0 -1
@@ -0,0 +1,78 @@
1
+ module Metanorma
2
+ module Standoc
3
+ module Regex
4
+ # https://medium.com/@rickwang_wxc/in-ruby-given-a-string-detect-if-it-is-valid-numeric-c58275eace60
5
+ NUMERIC_REGEX = %r{^((\+|-)?\d*\.?\d+)([eE](\+|-){1}\d+)?$}
6
+
7
+ # extending localities to cover ISO referencing
8
+ CONN_REGEX_STR = "(?<conn>and|or|from|to)!".freeze
9
+
10
+ LOCALITIES = "section|clause|part|paragraph|chapter|page|line|" \
11
+ "table|annex|figure|example|note|formula|list|time|anchor|" \
12
+ "locality:[^ \\t\\n\\r:,;=]+".freeze
13
+
14
+ LOCALITY_REGEX_STR = <<~REGEXP.freeze
15
+ ^((#{CONN_REGEX_STR})?
16
+ (?<locality>#{LOCALITIES})(\\s+|=)
17
+ (?<ref>[^"][^ \\t\\n,:;-]*|"[^"]+")
18
+ (-(?<to>[^"][^ \\t\\n,:;-]*|"[^"]"))?|
19
+ (?<locality2>whole|title|locality:[^ \\t\\n\\r:,;=]+))(?<punct>[,:;]?)\\s*
20
+ (?<text>.*)$
21
+ REGEXP
22
+
23
+ def to_regex(str)
24
+ Regexp.new(str.gsub(/\s/, ""), Regexp::IGNORECASE | Regexp::MULTILINE)
25
+ end
26
+
27
+ LOCALITY_REGEX_VALUE_ONLY_STR = <<~REGEXP.freeze
28
+ ^(?<conn0>(#{CONN_REGEX_STR}))
29
+ (?!whole|title|locality:)
30
+ (?<value>[^=,;:\\t\\n\\r]+)
31
+ (?<punct>[,;\\t\\n\\r]|$)
32
+ REGEXP
33
+
34
+ LOCALITY_REGEX_STR_TRIPLEDASH = <<~REGEXP.freeze
35
+ ^(?<locality>(#{CONN_REGEX_STR})?
36
+ (#{LOCALITIES})(\\s+|=))
37
+ (?<ref>[^"][^ \\t\\n,:;-]*
38
+ -[^ \\t\\n,:;"-]+
39
+ -[^ \\t\\n,:;"]+)
40
+ (?<text>[,:;]?\\s*
41
+ .*)$
42
+ REGEXP
43
+
44
+ TERM_REFERENCE_RE_STR = <<~REGEXP.freeze
45
+ ^(?<xref><(xref|concept)[^>]+>(.*?</(xref|concept)>)?)
46
+ (,\s(?<text>.*))?
47
+ $
48
+ REGEXP
49
+ TERM_REFERENCE_RE =
50
+ Regexp.new(TERM_REFERENCE_RE_STR.gsub(/\s/, "").gsub(/_/, "\\s"),
51
+ Regexp::IGNORECASE | Regexp::MULTILINE)
52
+
53
+ ISO_REF =
54
+ %r{^<ref\sid="(?<anchor>[^"]+)">
55
+ \[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9-]+|IEV)
56
+ (?::(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm
57
+
58
+ ISO_REF_NO_YEAR =
59
+ %r{^<ref\sid="(?<anchor>[^"]+)">
60
+ \[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9-]+):
61
+ (?:--|–|—|&\#821[12];)\]</ref>,?\s*
62
+ (?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?,?\s?(?<text>.*)$}xm
63
+
64
+ ISO_REF_ALL_PARTS =
65
+ %r{^<ref\sid="(?<anchor>[^"]+)">
66
+ \[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9]+)
67
+ (?::(?<year>--|–|—|&\#821[12];|[0-9][0-9-]+))?\s
68
+ \(all\sparts\)\]</ref>,?\s*
69
+ (?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm
70
+
71
+ NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
72
+ \[(?<usrlbl>\([^)]+\))?(?<code>.+?)\]</ref>,?\s*(?<text>.*)$}xm
73
+
74
+ NON_ISO_REF1 = %r{^<ref\sid="(?<anchor>[^"]+)">
75
+ (?<usrlbl>\([^)]+\))?(?<code>.+?)</ref>,?\s*(?<text>.*)$}xm
76
+ end
77
+ end
78
+ end
@@ -1,5 +1,11 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <grammar xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
3
+ <define name="requirement">
4
+ <element name="requirement">
5
+ <ref name="RequirementType"/>
6
+ </element>
7
+ </define>
8
+ <!-- ALERT: cannot have root comments, because of https://github.com/metanorma/metanorma/issues/437 -->
3
9
  <!--
4
10
  Presupposes isodoc.rnc, is included in it
5
11
  include "isodoc.rnc" { }
@@ -7,14 +13,9 @@
7
13
  This is the Metanorma default provisions model; it is overridden by other provisions models,
8
14
  such as Modspec
9
15
  -->
10
- <define name="requirement">
16
+ <define name="recommendation">
11
17
  <a:documentation>Specification of an attribute of a subject that is required.
12
18
  NOTE: A requirement can contain other requirements</a:documentation>
13
- <element name="requirement">
14
- <ref name="RequirementType"/>
15
- </element>
16
- </define>
17
- <define name="recommendation">
18
19
  <a:documentation>Specification of an attribute of a subject that is recommended</a:documentation>
19
20
  <element name="recommendation">
20
21
  <ref name="RequirementType"/>
@@ -52,7 +52,7 @@ module Metanorma
52
52
 
53
53
  PREFACE_CLAUSE_NAMES =
54
54
  %w(abstract foreword introduction metanorma-extension termdocsource
55
- misc-container acknowledgements).freeze
55
+ misc-container metanorma-extension acknowledgements).freeze
56
56
 
57
57
  MAIN_CLAUSE_NAMES =
58
58
  ["normative references", "terms and definitions", "scope",
@@ -140,15 +140,6 @@ module Metanorma
140
140
  end
141
141
  end
142
142
 
143
- TERM_REFERENCE_RE_STR = <<~REGEXP.freeze
144
- ^(?<xref><(xref|concept)[^>]+>(.*?</(xref|concept)>)?)
145
- (,\s(?<text>.*))?
146
- $
147
- REGEXP
148
- TERM_REFERENCE_RE =
149
- Regexp.new(TERM_REFERENCE_RE_STR.gsub(/\s/, "").gsub(/_/, "\\s"),
150
- Regexp::IGNORECASE | Regexp::MULTILINE)
151
-
152
143
  def extract_termsource_refs(text, node)
153
144
  matched = TERM_REFERENCE_RE.match text
154
145
  matched.nil? and @log.add("AsciiDoc Input", node,
@@ -180,6 +171,8 @@ module Metanorma
180
171
  end
181
172
  end
182
173
  end
174
+
175
+ include ::Metanorma::Standoc::Regex
183
176
  end
184
177
  end
185
178
  end
@@ -100,6 +100,14 @@ module Metanorma
100
100
  para
101
101
  end
102
102
 
103
+ def insert_before(xmldoc, xpath)
104
+ unless ins = xmldoc.at(xpath).children.first
105
+ xmldoc.at(xpath) << " "
106
+ ins = xmldoc.at(xpath).children.first
107
+ end
108
+ ins
109
+ end
110
+
103
111
  def xml_encode(text)
104
112
  @c.encode(text, :basic, :hexadecimal)
105
113
  .gsub("&amp;gt;", ">").gsub("&amp;lt;", "<").gsub("&amp;amp;", "&")
@@ -2,8 +2,8 @@ require "metanorma/standoc/utils"
2
2
  require_relative "validate_section"
3
3
  require_relative "validate_table"
4
4
  require_relative "validate_term"
5
+ require_relative "validate_schema"
5
6
  require "nokogiri"
6
- require "jing"
7
7
  require "iev"
8
8
  require "pngcheck"
9
9
 
@@ -98,49 +98,6 @@ module Metanorma
98
98
  @log.add("Style", i, err2)
99
99
  end
100
100
 
101
- def schema_validate(doc, schema)
102
- Tempfile.open(["tmp", ".xml"], encoding: "UTF-8") do |f|
103
- schema_validate1(f, doc, schema)
104
- rescue Jing::Error => e
105
- clean_abort("Jing failed with error: #{e}", doc)
106
- ensure
107
- f.close!
108
- end
109
- end
110
-
111
- def schema_validate1(file, doc, schema)
112
- file.write(to_xml(doc))
113
- file.close
114
- errors = Jing.new(schema, encoding: "UTF-8").validate(file.path)
115
- warn "Syntax Valid!" if errors.none?
116
- errors.each do |e|
117
- @log.add("Metanorma XML Syntax",
118
- "XML Line #{'%06d' % e[:line]}:#{e[:column]}", e[:message])
119
- end
120
- end
121
-
122
- SVG_NS = "http://www.w3.org/2000/svg".freeze
123
-
124
- WILDCARD_ATTRS =
125
- "//*[@format] | //stem | //bibdata//description | " \
126
- "//formattedref | //bibdata//note | //bibdata/abstract | " \
127
- "//bibitem/abstract | //bibitem/note | //metanorma-extension".freeze
128
-
129
- # RelaxNG cannot cope well with wildcard attributes. So we strip
130
- # any attributes from FormattedString instances (which can contain
131
- # xs:any markup, and are signalled with @format) before validation.
132
- def formattedstr_strip(doc)
133
- doc.xpath(WILDCARD_ATTRS, "m" => SVG_NS).each do |n|
134
- n.elements.each do |e|
135
- e.traverse do |e1|
136
- e1.element? and e1.each { |k, _v| e1.delete(k) } # rubocop:disable Style/HashEachMethods
137
- end
138
- end
139
- end
140
- doc.xpath("//m:svg", "m" => SVG_NS).each { |n| n.replace("<svg/>") }
141
- doc
142
- end
143
-
144
101
  def image_validate(doc)
145
102
  image_exists(doc)
146
103
  image_toobig(doc)
@@ -198,8 +155,7 @@ module Metanorma
198
155
 
199
156
  def validate(doc)
200
157
  content_validate(doc)
201
- schema_validate(formattedstr_strip(doc.dup),
202
- File.join(File.dirname(__FILE__), "isodoc-compile.rng"))
158
+ schema_validate(formattedstr_strip(doc.dup), schema_location)
203
159
  end
204
160
 
205
161
  def repeat_id_validate1(elem)
@@ -0,0 +1,104 @@
1
+ require "jing"
2
+
3
+ module Metanorma
4
+ module Standoc
5
+ module Validate
6
+ def schema_location
7
+ self.class.respond_to?(:_file) and ret = self.class::_file
8
+ ret ||= caller_locations(1..1).first.absolute_path
9
+ ret ||= __FILE__
10
+ File.join(File.dirname(ret), schema_file)
11
+ end
12
+
13
+ def schema_file
14
+ "isodoc-compile.rng"
15
+ end
16
+
17
+ def schema_validate(doc, schema)
18
+ Tempfile.open(["tmp", ".xml"], encoding: "UTF-8") do |f|
19
+ schema_validate1(f, doc, schema)
20
+ rescue Jing::Error => e
21
+ clean_abort("Jing failed with error: #{e}", doc)
22
+ ensure
23
+ f.close!
24
+ end
25
+ end
26
+
27
+ def schema_validate1(file, doc, schema)
28
+ file.write(to_xml(doc))
29
+ file.close
30
+ errors = Jing.new(schema, encoding: "UTF-8").validate(file.path)
31
+ warn "Syntax Valid!" if errors.none?
32
+ errors.each do |e|
33
+ @log.add("Metanorma XML Syntax",
34
+ "XML Line #{'%06d' % e[:line]}:#{e[:column]}", e[:message])
35
+ end
36
+ end
37
+
38
+ def validate_document_fragment(xml_fragment)
39
+ f = add_ns_to_fragment(xml_fragment) or
40
+ return [true,
41
+ "Fragment is not well-formed XML, not validating"]
42
+ begin
43
+ temp_schema, schema = fragment_schema(f.root.name)
44
+ schema or return [false, "Did not expect element #{f.root.name}"]
45
+ validation_errors = schema.validate(f)
46
+ [validation_errors.none? do |x|
47
+ x.to_s.include?("Did not expect element")
48
+ end, validation_errors]
49
+ ensure
50
+ temp_schema.unlink
51
+ end
52
+ end
53
+
54
+ def add_ns_to_fragment(xml_fragment)
55
+ f = Nokogiri::XML(xml_fragment, &:strict)
56
+ f.errors.any? || f.root.nil? and return nil
57
+ root_tag = f.root.name
58
+ f.root.namespace or
59
+ f = Nokogiri::XML(xml_fragment
60
+ .sub(/<#{root_tag}([^>]*)>/,
61
+ "<#{root_tag}\\1 xmlns='#{xml_namespace}'>"))
62
+ f
63
+ rescue StandardError
64
+ nil
65
+ end
66
+
67
+ def fragment_schema(root_element)
68
+ temp_schema = Tempfile.new(["dynamic_schema", ".rng"])
69
+ temp_schema.write(<<~SCHEMA)
70
+ <grammar xmlns="http://relaxng.org/ns/structure/1.0">
71
+ <include href="#{schema_location}">
72
+ <start combine="choice">
73
+ <ref name="#{root_element}"/>
74
+ </start>
75
+ </include>
76
+ </grammar>
77
+ SCHEMA
78
+ temp_schema.close
79
+ [temp_schema, Nokogiri::XML::RelaxNG(File.open(temp_schema.path))]
80
+ rescue StandardError # error because root_element is not in schema
81
+ [temp_schema, nil]
82
+ end
83
+
84
+ SVG_NS = "http://www.w3.org/2000/svg".freeze
85
+
86
+ WILDCARD_ATTRS = "//stem | //metanorma-extension".freeze
87
+
88
+ # RelaxNG cannot cope well with wildcard attributes. So we strip
89
+ # any attributes from FormattedString instances (which can contain
90
+ # xs:any markup, and are signalled with @format) before validation.
91
+ def formattedstr_strip(doc)
92
+ doc.xpath(WILDCARD_ATTRS, "m" => SVG_NS).each do |n|
93
+ n.elements.each do |e|
94
+ e.traverse do |e1|
95
+ e1.element? and e1.each { |k, _v| e1.delete(k) } # rubocop:disable Style/HashEachMethods
96
+ end
97
+ end
98
+ end
99
+ doc.xpath("//m:svg", "m" => SVG_NS).each { |n| n.replace("<svg/>") }
100
+ doc
101
+ end
102
+ end
103
+ end
104
+ end
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "3.0.3".freeze
22
+ VERSION = "3.0.5".freeze
23
23
  end
24
24
  end
@@ -32,10 +32,10 @@ Gem::Specification.new do |spec|
32
32
  spec.add_dependency "asciidoctor", "~> 2.0.0"
33
33
  spec.add_dependency "crass", "~> 1.0.0"
34
34
  spec.add_dependency "iev", "~> 0.3.5"
35
- spec.add_dependency "isodoc", "~> 3.1.0"
35
+ spec.add_dependency "isodoc", "~> 3.1.4"
36
36
  spec.add_dependency "metanorma", ">= 1.6.0"
37
37
  spec.add_dependency "metanorma-plugin-datastruct", "~> 0.3.0"
38
- spec.add_dependency "metanorma-plugin-glossarist", "~> 0.2.0"
38
+ spec.add_dependency "metanorma-plugin-glossarist", "~> 0.2.3"
39
39
  spec.add_dependency "metanorma-plugin-lutaml", "~> 0.7.0"
40
40
  spec.add_dependency "metanorma-utils", "~> 1.10.0"
41
41
  spec.add_dependency "ruby-jing"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-standoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-17 00:00:00.000000000 Z
11
+ date: 2025-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 3.1.0
75
+ version: 3.1.4
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 3.1.0
82
+ version: 3.1.4
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: metanorma
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.2.0
117
+ version: 0.2.3
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.2.0
124
+ version: 0.2.3
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: metanorma-plugin-lutaml
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -434,7 +434,6 @@ files:
434
434
  - ".tex"
435
435
  - CODE_OF_CONDUCT.md
436
436
  - Gemfile
437
- - Gemfile.devel
438
437
  - LICENSE
439
438
  - Makefile
440
439
  - README.adoc
@@ -518,6 +517,7 @@ files:
518
517
  - lib/metanorma/standoc/cleanup_mathvariant.rb
519
518
  - lib/metanorma/standoc/cleanup_ref.rb
520
519
  - lib/metanorma/standoc/cleanup_reqt.rb
520
+ - lib/metanorma/standoc/cleanup_review.rb
521
521
  - lib/metanorma/standoc/cleanup_section.rb
522
522
  - lib/metanorma/standoc/cleanup_section_names.rb
523
523
  - lib/metanorma/standoc/cleanup_symbols.rb
@@ -555,6 +555,7 @@ files:
555
555
  - lib/metanorma/standoc/ref_queue.rb
556
556
  - lib/metanorma/standoc/ref_sect.rb
557
557
  - lib/metanorma/standoc/ref_utility.rb
558
+ - lib/metanorma/standoc/regex.rb
558
559
  - lib/metanorma/standoc/render.rb
559
560
  - lib/metanorma/standoc/reqt.rb
560
561
  - lib/metanorma/standoc/reqt.rng
@@ -566,6 +567,7 @@ files:
566
567
  - lib/metanorma/standoc/terms.rb
567
568
  - lib/metanorma/standoc/utils.rb
568
569
  - lib/metanorma/standoc/validate.rb
570
+ - lib/metanorma/standoc/validate_schema.rb
569
571
  - lib/metanorma/standoc/validate_section.rb
570
572
  - lib/metanorma/standoc/validate_table.rb
571
573
  - lib/metanorma/standoc/validate_term.rb
data/Gemfile.devel DELETED
@@ -1 +0,0 @@
1
- gem "html2doc", git: "https://github.com/metanorma/html2doc", branch: "main"