metanorma-standoc 3.0.2 → 3.0.3
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 +4 -4
- data/Gemfile.devel +1 -0
- data/lib/metanorma/standoc/cleanup_footnotes.rb +12 -0
- data/lib/metanorma/standoc/cleanup_maths.rb +6 -6
- data/lib/metanorma/standoc/cleanup_section_names.rb +1 -5
- data/lib/metanorma/standoc/inline.rb +2 -2
- data/lib/metanorma/standoc/isodoc.rng +9 -0
- data/lib/metanorma/standoc/macros_plantuml.rb +10 -7
- data/lib/metanorma/standoc/utils.rb +9 -0
- data/lib/metanorma/standoc/validate.rb +2 -1
- data/lib/metanorma/standoc/validate_term.rb +33 -1
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +2 -3
- metadata +19 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da7d2f716300883df02cd6bcb01d5cfbb36390d6dfa355be0a41e55c9eeb10aa
|
4
|
+
data.tar.gz: 341e8403521c9bf5709593425e29317dd80c73f2c078afa2df481b9656c5b7d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfbbce08097ed466ff9e0253f1c07769acd6384fca6688394495e488a14cf20ca239e668c03c106e969cf60afbccd88f0e197052dad9a5a32962f5b816e558cc
|
7
|
+
data.tar.gz: 889e1eabbe45186cd1814c99fe0b6f97317beedcb26c676c4a637ec3242b25d3b9f4e353238cbf1bd2bde8a3d18416e6774a674051c210465f36e34b729cfa81
|
data/Gemfile.devel
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gem "html2doc", git: "https://github.com/metanorma/html2doc", branch: "main"
|
@@ -118,9 +118,21 @@ module Metanorma
|
|
118
118
|
fnote.children = "[ERROR]"
|
119
119
|
end
|
120
120
|
|
121
|
+
def process_hidden_footnotes(xmldoc)
|
122
|
+
xmldoc.xpath("//fn").each do |fn|
|
123
|
+
first_text = fn.xpath(".//text()")
|
124
|
+
.find { |node| !node.text.strip.empty? } or return
|
125
|
+
if first_text.text.strip.start_with?("hiddenref%")
|
126
|
+
first_text.content = first_text.text.sub(/^hiddenref%/, "")
|
127
|
+
fn["hiddenref"] = true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
121
132
|
def footnote_cleanup(xmldoc)
|
122
133
|
footnote_block_cleanup(xmldoc)
|
123
134
|
title_footnote_move(xmldoc)
|
135
|
+
process_hidden_footnotes(xmldoc)
|
124
136
|
table_footnote_renumber(xmldoc)
|
125
137
|
other_footnote_renumber(xmldoc)
|
126
138
|
xmldoc.xpath("//fn").each do |fn|
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require "asciimath2unitsml"
|
2
1
|
require_relative "cleanup_mathvariant"
|
3
2
|
|
4
3
|
module Metanorma
|
@@ -39,9 +38,12 @@ module Metanorma
|
|
39
38
|
<math xmlns='#{MATHML_NS}'><mstyle displaystyle='false'><mn>#{expr}</mn></mstyle></math>
|
40
39
|
MATH
|
41
40
|
else
|
41
|
+
unitsml = if expr.include?("unitsml")
|
42
|
+
{ unitsml: { xml: true,
|
43
|
+
multiplier: :space } }
|
44
|
+
else {} end
|
42
45
|
Plurimath::Math.parse(expr, "asciimath")
|
43
|
-
.to_mathml(display_style: elem["block"]
|
44
|
-
unitsml_xml: expr.include?("unitsml"))
|
46
|
+
.to_mathml(**{ display_style: elem["block"] }.merge(unitsml))
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
@@ -115,7 +117,7 @@ module Metanorma
|
|
115
117
|
def gather_unitsml(unitsml, xmldoc, tag)
|
116
118
|
tags = xmldoc.xpath(".//m:#{tag}", "m" => UNITSML_NS)
|
117
119
|
.each_with_object({}) do |x, m|
|
118
|
-
m[x["
|
120
|
+
m[x["id"]] = x.remove
|
119
121
|
end
|
120
122
|
tags.empty? and return
|
121
123
|
set = unitsml.add_child("<#{tag}Set/>").first
|
@@ -180,11 +182,9 @@ module Metanorma
|
|
180
182
|
end
|
181
183
|
|
182
184
|
def mathml_cleanup(xmldoc)
|
183
|
-
a2u = Asciimath2UnitsML::Conv.new(asciimath2unitsml_options)
|
184
185
|
xmldoc.xpath("//stem[@type = 'MathML'][not(@validate = 'false')]")
|
185
186
|
.each do |x|
|
186
187
|
mathml_xml_cleanup(x)
|
187
|
-
a2u.MathML2UnitsML(x)
|
188
188
|
mathml_mathvariant(x)
|
189
189
|
end
|
190
190
|
xmldoc.xpath("//stem[@type = 'MathML']")
|
@@ -144,12 +144,8 @@ module Metanorma
|
|
144
144
|
sym and m[sym] += 1
|
145
145
|
end
|
146
146
|
|
147
|
-
SECTION_CONTAINERS = %w(foreword introduction acknowledgements abstract
|
148
|
-
clause clause references terms definitions annex
|
149
|
-
appendix).freeze
|
150
|
-
|
151
147
|
def sections_variant_title_cleanup(xml)
|
152
|
-
path =
|
148
|
+
path = section_containers.map { |x| "./ancestor::#{x}" }.join(" | ")
|
153
149
|
xml.xpath("//p[@variant_title]").each do |p|
|
154
150
|
p.name = "variant-title"
|
155
151
|
p.delete("id")
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require "unicode2latex"
|
2
1
|
require "mime/types"
|
3
2
|
require "base64"
|
4
3
|
require "English"
|
@@ -27,7 +26,8 @@ module Metanorma
|
|
27
26
|
end
|
28
27
|
|
29
28
|
def latex_parse1(text, block)
|
30
|
-
lxm_input = Unicode2LaTeX.unicode2latex(@c.decode(text))
|
29
|
+
#lxm_input = Unicode2LaTeX.unicode2latex(@c.decode(text))
|
30
|
+
lxm_input = @c.decode(text)
|
31
31
|
results = Plurimath::Math.parse(lxm_input, "latex")
|
32
32
|
.to_mathml(display_style: block)
|
33
33
|
if results.nil?
|
@@ -33,6 +33,15 @@
|
|
33
33
|
</zeroOrMore>
|
34
34
|
</element>
|
35
35
|
</define>
|
36
|
+
<define name="fn" combine="interleave">
|
37
|
+
<optional>
|
38
|
+
<attribute name="hiddenref">
|
39
|
+
<a:documentation>If true, number the footnote as normal, but suppress display of the footnote reference in the document body.
|
40
|
+
This is done if the footnote reference is already presented in some other form, e.g. within a figure image.</a:documentation>
|
41
|
+
<data type="boolean"/>
|
42
|
+
</attribute>
|
43
|
+
</optional>
|
44
|
+
</define>
|
36
45
|
<define name="index-primary">
|
37
46
|
<element name="primary">
|
38
47
|
<oneOrMore>
|
@@ -34,24 +34,27 @@ module Metanorma
|
|
34
34
|
# Windows Ruby 2.4 will crash if a Tempfile is "mv"ed.
|
35
35
|
# This is why we need to copy and then unlink.
|
36
36
|
def self.generate_file(parent, reader)
|
37
|
-
|
37
|
+
ldir = localdir(parent)
|
38
38
|
imagesdir = parent.document.attr("imagesdir")
|
39
|
-
umlfile, outfile = save_plantuml parent, reader,
|
39
|
+
umlfile, outfile = save_plantuml parent, reader, ldir
|
40
40
|
run(umlfile, outfile) or
|
41
41
|
raise "No image output from PlantUML (#{umlfile}, #{outfile})!"
|
42
42
|
umlfile.unlink
|
43
|
-
|
44
|
-
path = path_prep(localdir, imagesdir)
|
43
|
+
path = path_prep(ldir, imagesdir)
|
45
44
|
filename = File.basename(outfile.to_s)
|
46
45
|
FileUtils.cp(outfile, path) and outfile.unlink
|
47
|
-
|
48
46
|
imagesdir ? filename : File.join(path, filename)
|
49
47
|
end
|
50
48
|
|
49
|
+
def self.localdir(parent)
|
50
|
+
ret = Metanorma::Utils::localdir(parent.document)
|
51
|
+
File.writable?(ret) or
|
52
|
+
raise "Destination directory #{ret} not writable for PlantUML!"
|
53
|
+
ret
|
54
|
+
end
|
55
|
+
|
51
56
|
def self.path_prep(localdir, imagesdir)
|
52
57
|
path = Pathname.new(localdir) + (imagesdir || "plantuml")
|
53
|
-
File.writable?(localdir) or
|
54
|
-
raise "Destination path #{path} not writable for PlantUML!"
|
55
58
|
path.mkpath
|
56
59
|
File.writable?(path) or
|
57
60
|
raise "Destination path #{path} not writable for PlantUML!"
|
@@ -108,6 +108,15 @@ module Metanorma
|
|
108
108
|
.gsub("'", "'")
|
109
109
|
end
|
110
110
|
|
111
|
+
SECTION_CONTAINERS =
|
112
|
+
%w(foreword introduction acknowledgements abstract
|
113
|
+
clause references terms definitions annex appendix indexsect
|
114
|
+
executivesummary).freeze
|
115
|
+
|
116
|
+
def section_containers
|
117
|
+
SECTION_CONTAINERS
|
118
|
+
end
|
119
|
+
|
111
120
|
# wrapped in <sections>
|
112
121
|
def adoc2xml(text, flavour)
|
113
122
|
Nokogiri::XML(text).root and return text
|
@@ -21,13 +21,14 @@ module Metanorma
|
|
21
21
|
concept_validate(doc, "concept", "refterm")
|
22
22
|
concept_validate(doc, "related", "preferred//name")
|
23
23
|
preferred_validate(doc)
|
24
|
+
termsect_validate(doc)
|
24
25
|
table_validate(doc)
|
25
26
|
requirement_validate(doc)
|
26
27
|
image_validate(doc)
|
27
28
|
math_validate(doc)
|
28
29
|
fatalerrors = @log.abort_messages
|
29
30
|
fatalerrors.empty? or
|
30
|
-
clean_abort(fatalerrors.join("\n"), doc)
|
31
|
+
clean_abort("\n\nFATAL ERRROS:\n\n#{fatalerrors.join("\n\n")}", doc)
|
31
32
|
end
|
32
33
|
|
33
34
|
MATHML_NS = "http://www.w3.org/1998/Math/MathML".freeze
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "iev"
|
2
|
+
|
1
3
|
module Metanorma
|
2
4
|
module Standoc
|
3
5
|
module Validate
|
@@ -7,7 +9,7 @@ module Metanorma
|
|
7
9
|
def init_iev
|
8
10
|
@no_isobib and return nil
|
9
11
|
@iev and return @iev
|
10
|
-
@iev = Iev::Db.new(@iev_globalname, @iev_localname) unless @no_isobib
|
12
|
+
@iev = ::Iev::Db.new(@iev_globalname, @iev_localname) unless @no_isobib
|
11
13
|
@iev
|
12
14
|
end
|
13
15
|
|
@@ -82,6 +84,36 @@ module Metanorma
|
|
82
84
|
@log.add("Terms", v.first, err, severity: 1)
|
83
85
|
end
|
84
86
|
end
|
87
|
+
|
88
|
+
def find_illegal_designations(xmldoc)
|
89
|
+
xmldoc.xpath("//preferred | //admitted | //deprecates")
|
90
|
+
.each_with_object({}) do |d, m|
|
91
|
+
d.ancestors.detect { |x| x.name == "terms" } and next
|
92
|
+
c = d.ancestors.detect do |x|
|
93
|
+
section_containers.include?(x.name)
|
94
|
+
end
|
95
|
+
c["id"] ||= "_#{UUIDTools::UUID.random_create}"
|
96
|
+
m[c["id"]] ||= { clause: c, designations: [] }
|
97
|
+
m[c["id"]][:designations] << d
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def termsect_validate(xmldoc)
|
102
|
+
errors = find_illegal_designations(xmldoc)
|
103
|
+
errors.each_value do |v|
|
104
|
+
desgns = v[:designations].map do |x|
|
105
|
+
@c.encode(x.text.strip, :basic, :hexadecimal)
|
106
|
+
end.join(", ")
|
107
|
+
err = <<~ERROR
|
108
|
+
Clause not recognised as a term clause, but contains designation markup
|
109
|
+
(preferred:[], admitted:[], alt:[], deprecated:[]):<br/>
|
110
|
+
#{desgns}</br>
|
111
|
+
Ensure the parent clause is recognised as a terms clause by inserting <code>[heading=terms and definitions]</code> above the title,
|
112
|
+
in case the heading is not automatically recognised. See also <a href="https://www.metanorma.org/author/topics/sections/concepts/#clause-title">Metanorma documentation</a>.
|
113
|
+
ERROR
|
114
|
+
@log.add("Terms", v[:clause], err, severity: 0)
|
115
|
+
end
|
116
|
+
end
|
85
117
|
end
|
86
118
|
end
|
87
119
|
end
|
data/metanorma-standoc.gemspec
CHANGED
@@ -40,12 +40,10 @@ Gem::Specification.new do |spec|
|
|
40
40
|
spec.add_dependency "metanorma-utils", "~> 1.10.0"
|
41
41
|
spec.add_dependency "ruby-jing"
|
42
42
|
# relaton-cli not just relaton, to avoid circular reference in metanorma
|
43
|
-
spec.add_dependency "asciimath2unitsml", "~> 0.4.0"
|
44
43
|
spec.add_dependency "concurrent-ruby"
|
45
44
|
spec.add_dependency "pngcheck"
|
46
45
|
spec.add_dependency "relaton-cli", "~> 1.20.0"
|
47
46
|
spec.add_dependency "relaton-iev", "~> 1.2.0"
|
48
|
-
spec.add_dependency "unicode2latex", "~> 0.0.1"
|
49
47
|
|
50
48
|
spec.add_development_dependency "debug"
|
51
49
|
spec.add_development_dependency "equivalent-xml", "~> 0.6"
|
@@ -53,7 +51,8 @@ Gem::Specification.new do |spec|
|
|
53
51
|
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
54
52
|
spec.add_development_dependency "rake", "~> 13.0"
|
55
53
|
spec.add_development_dependency "rspec", "~> 3.6"
|
56
|
-
spec.add_development_dependency "rubocop", "~> 1
|
54
|
+
spec.add_development_dependency "rubocop", "~> 1"
|
55
|
+
spec.add_development_dependency "rubocop-performance"
|
57
56
|
spec.add_development_dependency "sassc-embedded", "~> 1"
|
58
57
|
spec.add_development_dependency "simplecov", "~> 0.15"
|
59
58
|
spec.add_development_dependency "timecop", "~> 0.9"
|
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.
|
4
|
+
version: 3.0.3
|
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-
|
11
|
+
date: 2025-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -164,20 +164,6 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: asciimath2unitsml
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - "~>"
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: 0.4.0
|
174
|
-
type: :runtime
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - "~>"
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: 0.4.0
|
181
167
|
- !ruby/object:Gem::Dependency
|
182
168
|
name: concurrent-ruby
|
183
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -234,20 +220,6 @@ dependencies:
|
|
234
220
|
- - "~>"
|
235
221
|
- !ruby/object:Gem::Version
|
236
222
|
version: 1.2.0
|
237
|
-
- !ruby/object:Gem::Dependency
|
238
|
-
name: unicode2latex
|
239
|
-
requirement: !ruby/object:Gem::Requirement
|
240
|
-
requirements:
|
241
|
-
- - "~>"
|
242
|
-
- !ruby/object:Gem::Version
|
243
|
-
version: 0.0.1
|
244
|
-
type: :runtime
|
245
|
-
prerelease: false
|
246
|
-
version_requirements: !ruby/object:Gem::Requirement
|
247
|
-
requirements:
|
248
|
-
- - "~>"
|
249
|
-
- !ruby/object:Gem::Version
|
250
|
-
version: 0.0.1
|
251
223
|
- !ruby/object:Gem::Dependency
|
252
224
|
name: debug
|
253
225
|
requirement: !ruby/object:Gem::Requirement
|
@@ -338,14 +310,28 @@ dependencies:
|
|
338
310
|
requirements:
|
339
311
|
- - "~>"
|
340
312
|
- !ruby/object:Gem::Version
|
341
|
-
version: 1
|
313
|
+
version: '1'
|
342
314
|
type: :development
|
343
315
|
prerelease: false
|
344
316
|
version_requirements: !ruby/object:Gem::Requirement
|
345
317
|
requirements:
|
346
318
|
- - "~>"
|
347
319
|
- !ruby/object:Gem::Version
|
348
|
-
version: 1
|
320
|
+
version: '1'
|
321
|
+
- !ruby/object:Gem::Dependency
|
322
|
+
name: rubocop-performance
|
323
|
+
requirement: !ruby/object:Gem::Requirement
|
324
|
+
requirements:
|
325
|
+
- - ">="
|
326
|
+
- !ruby/object:Gem::Version
|
327
|
+
version: '0'
|
328
|
+
type: :development
|
329
|
+
prerelease: false
|
330
|
+
version_requirements: !ruby/object:Gem::Requirement
|
331
|
+
requirements:
|
332
|
+
- - ">="
|
333
|
+
- !ruby/object:Gem::Version
|
334
|
+
version: '0'
|
349
335
|
- !ruby/object:Gem::Dependency
|
350
336
|
name: sassc-embedded
|
351
337
|
requirement: !ruby/object:Gem::Requirement
|
@@ -448,6 +434,7 @@ files:
|
|
448
434
|
- ".tex"
|
449
435
|
- CODE_OF_CONDUCT.md
|
450
436
|
- Gemfile
|
437
|
+
- Gemfile.devel
|
451
438
|
- LICENSE
|
452
439
|
- Makefile
|
453
440
|
- README.adoc
|