metanorma-standoc 3.0.15 → 3.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 +4 -4
- data/lib/isodoc/html/htmlstyle.css +7 -1
- data/lib/metanorma/standoc/cleanup_boilerplate.rb +4 -14
- data/lib/metanorma/standoc/cleanup_maths.rb +3 -2
- data/lib/metanorma/standoc/front.rb +9 -1
- data/lib/metanorma/standoc/macros.rb +0 -5
- data/lib/metanorma/standoc/macros_inline.rb +3 -21
- data/lib/metanorma/standoc/merge_bibitems.rb +17 -0
- data/lib/metanorma/standoc/utils.rb +2 -0
- data/lib/metanorma/standoc/validate.rb +35 -57
- data/lib/metanorma/standoc/validate_image.rb +62 -0
- data/lib/metanorma/standoc/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c1ea7078b1b5abbb7f7db93972c6efd1d55e076faa631ae25e351dd5ce48fb5
|
4
|
+
data.tar.gz: 509b11d44c11d9facc4985bcff19b0333d863585af462fef0fdca80017235881
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5936e1fb18c00b4bb9201f77b7bc26c0ec213163710bbe542c659237abc2f9209209a2fa2445fd5fb9e8dc81f3dc7b8b84c7ff38ff2c4caa20ca6f75967a5e1d
|
7
|
+
data.tar.gz: e70ccf305e69b6af130afb0d903bfb509df06c659ed96d961a4204f22e7a265a64da19b1dd23336c434ac3df300028edb04e8175a2fa81876c25b678888b1960
|
@@ -318,9 +318,15 @@ h6:hover > a.anchor,
|
|
318
318
|
padding: 0;
|
319
319
|
}
|
320
320
|
|
321
|
+
.svg-container {
|
322
|
+
width: 100%; /* or any desired width */
|
323
|
+
display: block; /* ← removes unwanted inline spacing */
|
324
|
+
}
|
325
|
+
|
321
326
|
svg {
|
322
327
|
width: 100%;
|
323
|
-
|
328
|
+
height: auto; /* ← key to maintaining aspect ratio */
|
329
|
+
display: block; /* ← removes unwanted inline spacing */
|
324
330
|
}
|
325
331
|
|
326
332
|
#standard-band {
|
@@ -48,8 +48,11 @@ module Metanorma
|
|
48
48
|
x = xmldoc.dup
|
49
49
|
x.root.add_namespace(nil, xml_namespace)
|
50
50
|
xml = Nokogiri::XML(x.to_xml)
|
51
|
+
#require "debug"; binding.b
|
51
52
|
@isodoc ||= isodoc(@lang, @script, @locale)
|
52
|
-
@isodoc.
|
53
|
+
# initialise @isodoc.xrefs, for @isodoc.xrefs.info
|
54
|
+
@isodoc.bibdata(xml) # do i18n
|
55
|
+
#@isodoc.info(xml, nil)
|
53
56
|
@isodoc
|
54
57
|
end
|
55
58
|
|
@@ -76,19 +79,6 @@ module Metanorma
|
|
76
79
|
initial_boilerplate(xmldoc, isodoc)
|
77
80
|
end
|
78
81
|
|
79
|
-
# KILL
|
80
|
-
# escape < > & to &gt; etc,
|
81
|
-
# for passthrough insertion into boilerplate
|
82
|
-
def boilerplate_isodoc_values(isodoc)
|
83
|
-
isodoc.meta.get.each do |k, v|
|
84
|
-
if v.is_a?(String)
|
85
|
-
isodoc.meta.set(k, v.gsub("&", "&&&&&&&")
|
86
|
-
.gsub("<", "&lt;").gsub(">", "&gt;")
|
87
|
-
.gsub("&&&&&&&", "&amp;"))
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
82
|
def initial_boilerplate(xml, isodoc)
|
93
83
|
xml.at("//boilerplate") and return
|
94
84
|
preface = xml.at("//preface | //sections | //annex | //references") or
|
@@ -19,6 +19,7 @@ module Metanorma
|
|
19
19
|
def asciimath2mathml_indiv(elem)
|
20
20
|
elem["type"] = "MathML"
|
21
21
|
expr = @c.decode(elem.text)
|
22
|
+
expr.strip.empty? and return
|
22
23
|
ret = asciimath_parse(expr, elem)&.strip
|
23
24
|
ret += "<asciimath>#{@c.encode(expr, :basic)}</asciimath>"
|
24
25
|
elem.children = ret
|
@@ -35,9 +36,9 @@ module Metanorma
|
|
35
36
|
<math xmlns='#{MATHML_NS}'><mstyle displaystyle='false'><mn>#{expr}</mn></mstyle></math>
|
36
37
|
MATH
|
37
38
|
else
|
39
|
+
expr.strip.empty? and return
|
38
40
|
unitsml = if expr.include?("unitsml")
|
39
|
-
{ unitsml: { xml: true,
|
40
|
-
multiplier: :space } }
|
41
|
+
{ unitsml: { xml: true, multiplier: :space } }
|
41
42
|
else {} end
|
42
43
|
Plurimath::Math.parse(expr, "asciimath")
|
43
44
|
.to_mathml(**{ display_style: elem["block"] }.merge(unitsml))
|
@@ -30,13 +30,21 @@ module Metanorma
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def metadata_version(node, xml)
|
33
|
+
draft = metadata_version_value(node)
|
33
34
|
xml.edition node.attr("edition") if node.attr("edition")
|
34
35
|
xml.version do |v|
|
35
36
|
v.revision_date node.attr("revdate") if node.attr("revdate")
|
36
|
-
v.draft
|
37
|
+
v.draft draft if draft
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
41
|
+
def metadata_version_value(node)
|
42
|
+
draft = node.attr("version") and return draft
|
43
|
+
draft = node.attr("draft") or return nil
|
44
|
+
draft.empty? and return nil
|
45
|
+
draft
|
46
|
+
end
|
47
|
+
|
40
48
|
def metadata_status(node, xml)
|
41
49
|
xml.status do |s|
|
42
50
|
s.stage (node.attr("status") || node.attr("docstage") || "published")
|
@@ -124,11 +124,6 @@ module Metanorma
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
-
# KILL
|
128
|
-
def pass_convert(text)
|
129
|
-
text.sub(/^pass:\[(.+)$/, "pass-format:metanorma[\\1")
|
130
|
-
end
|
131
|
-
|
132
127
|
# InlineLinkRx = %r((^|link:|#{CG_BLANK}|<|[>\(\)\[\];"'])(\\?(?:https?|file|ftp|irc)://)(?:([^\s\[\]]+)\[(|#{CC_ALL}*?[^\\])\]|([^\s\[\]<]*([^\s,.?!\[\]<\)]))))m
|
133
128
|
#
|
134
129
|
InlineLinkRx = %r((^|(?<![-\\])\blink:(?!\+)|\p{Blank}|<|[<>\(\)\[\];"'])((?:https?|file|ftp|irc)://)(?:([^\s\[\]]+)(?:(\[(|.*?[^\\])\])|([^\s\[\]<]*([^\s,.?!\[\]<\)])))))m
|
@@ -134,7 +134,6 @@ module Metanorma
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
-
# inject ZWNJ to prevent Asciidoctor from attempting regex substitutions
|
138
137
|
class PassFormatInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
139
138
|
use_dsl
|
140
139
|
named :"pass-format"
|
@@ -143,29 +142,12 @@ module Metanorma
|
|
143
142
|
def process(parent, target, attrs)
|
144
143
|
format = target || "metanorma"
|
145
144
|
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"],
|
146
|
-
type: :pass, attributes: {
|
145
|
+
type: :pass, attributes: { "subs" => [] })
|
146
|
+
.convert
|
147
147
|
<<~XML.strip
|
148
|
-
<passthrough-inline formats="#{format}">#{
|
148
|
+
<passthrough-inline formats="#{format}">#{out}</passthrough-inline>
|
149
149
|
XML
|
150
150
|
end
|
151
|
-
|
152
|
-
# KILL
|
153
|
-
# Split content into XML tags (including XML-escaped instances),
|
154
|
-
# XML escapes, and text segments
|
155
|
-
# Then only apply ZWNJ to punctuation in text segments
|
156
|
-
def xml_process(out)
|
157
|
-
processed_out = ""
|
158
|
-
segments = out.split(/(<[^>]*>|<[^&]*>|&[^;]*;)/)
|
159
|
-
segments.each_with_index do |segment, index|
|
160
|
-
processed_out += if index.even? # Text segment (not a tag or escape)
|
161
|
-
#segment.gsub(/([[:punct:]])/, "\\1‌")
|
162
|
-
segment
|
163
|
-
else # XML tag or escape
|
164
|
-
segment
|
165
|
-
end
|
166
|
-
end
|
167
|
-
processed_out
|
168
|
-
end
|
169
151
|
end
|
170
152
|
|
171
153
|
class IdentifierInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
@@ -13,6 +13,23 @@ module Metanorma
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
class ::Hash
|
17
|
+
def deep_merge(second)
|
18
|
+
merger = proc { |_, v1, v2|
|
19
|
+
if ::Hash === v1 && ::Hash === v2
|
20
|
+
v1.merge(v2, &merger)
|
21
|
+
elsif ::Array === v1 && ::Array === v2
|
22
|
+
v2 # overwrite old with new
|
23
|
+
elsif [:undefined].include?(v2)
|
24
|
+
v1
|
25
|
+
else
|
26
|
+
v2
|
27
|
+
end
|
28
|
+
}
|
29
|
+
merge(second.to_h, &merger)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
16
33
|
def initialize(old, new)
|
17
34
|
@old = load_bibitem(old)
|
18
35
|
@new = load_bibitem(new)
|
@@ -87,6 +87,8 @@ module Metanorma
|
|
87
87
|
conv = presentation_xml_converter(EmptyAttr.new)
|
88
88
|
i18n = conv.i18n_init(lang, script, locale, i18nyaml)
|
89
89
|
conv.metadata_init(lang, script, locale, i18n)
|
90
|
+
conv.xref_init(lang, script, nil, i18n, {})
|
91
|
+
conv.xrefs.klass.meta = conv.meta
|
90
92
|
conv
|
91
93
|
end
|
92
94
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require "metanorma/standoc/utils"
|
2
|
+
require_relative "validate_image"
|
2
3
|
require_relative "validate_section"
|
3
4
|
require_relative "validate_table"
|
4
5
|
require_relative "validate_term"
|
5
6
|
require_relative "validate_schema"
|
6
7
|
require "nokogiri"
|
7
8
|
require "iev"
|
8
|
-
require "pngcheck"
|
9
9
|
|
10
10
|
module Metanorma
|
11
11
|
module Standoc
|
@@ -14,7 +14,6 @@ module Metanorma
|
|
14
14
|
@doctype = doc.at("//bibdata/ext/doctype")&.text
|
15
15
|
repeat_id_validate(doc.root) # feeds xref_validate, termsect_validate
|
16
16
|
xref_validate(doc) # feeds nested_asset_validate
|
17
|
-
nested_asset_validate(doc)
|
18
17
|
section_validate(doc)
|
19
18
|
norm_ref_validate(doc)
|
20
19
|
iev_validate(doc.root)
|
@@ -25,6 +24,7 @@ module Metanorma
|
|
25
24
|
table_validate(doc)
|
26
25
|
requirement_validate(doc)
|
27
26
|
image_validate(doc)
|
27
|
+
block_validate(doc)
|
28
28
|
math_validate(doc)
|
29
29
|
fatalerrors = @log.abort_messages
|
30
30
|
fatalerrors.empty? or
|
@@ -98,61 +98,6 @@ module Metanorma
|
|
98
98
|
@log.add("Style", i, err2)
|
99
99
|
end
|
100
100
|
|
101
|
-
def image_validate(doc)
|
102
|
-
image_exists(doc)
|
103
|
-
image_toobig(doc)
|
104
|
-
png_validate(doc)
|
105
|
-
end
|
106
|
-
|
107
|
-
def image_exists(doc)
|
108
|
-
doc.xpath("//image").each do |i|
|
109
|
-
Vectory::Utils::url?(i["src"]) and next
|
110
|
-
Vectory::Utils::datauri?(i["src"]) and next
|
111
|
-
expand_path(i["src"]) and next
|
112
|
-
@log.add("Images", i.parent,
|
113
|
-
"Image not found: #{i['src']}", severity: 0)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def expand_path(loc)
|
118
|
-
relative_path = File.join(@localdir, loc)
|
119
|
-
[loc, relative_path].detect do |p|
|
120
|
-
File.exist?(p) ? p : nil
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def png_validate(doc)
|
125
|
-
doc.xpath("//image[@mimetype = 'image/png']").each do |i|
|
126
|
-
Vectory::Utils::url?(i["src"]) and next
|
127
|
-
decoded = if Vectory::Utils::datauri?(i["src"])
|
128
|
-
Vectory::Utils::decode_datauri(i["src"])[:data]
|
129
|
-
else
|
130
|
-
path = expand_path(i["src"]) or next
|
131
|
-
File.binread(path)
|
132
|
-
end
|
133
|
-
png_validate1(i, decoded)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def png_validate1(img, buffer)
|
138
|
-
PngCheck.check_buffer(buffer)
|
139
|
-
rescue PngCheck::CorruptPngError => e
|
140
|
-
@log.add("Images", img.parent,
|
141
|
-
"Corrupt PNG image detected: #{e.message}")
|
142
|
-
end
|
143
|
-
|
144
|
-
TOO_BIG_IMG_ERR = <<~ERR.freeze
|
145
|
-
Image too large for Data URI encoding: disable Data URI encoding (`:data-uri-image: false`), or set `:data-uri-maxsize: 0`
|
146
|
-
ERR
|
147
|
-
|
148
|
-
def image_toobig(doc)
|
149
|
-
@dataurimaxsize.zero? and return
|
150
|
-
doc.xpath("//image").each do |i|
|
151
|
-
i["src"].size > @dataurimaxsize and
|
152
|
-
@log.add("Images", i.parent, TOO_BIG_IMG_ERR, severity: 0)
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
101
|
def validate(doc)
|
157
102
|
content_validate(doc)
|
158
103
|
schema_validate(formattedstr_strip(doc.dup), schema_location)
|
@@ -250,6 +195,39 @@ module Metanorma
|
|
250
195
|
get_anchors_between(from["target"], to_location["target"])
|
251
196
|
.each { |id| @doc_xrefs[id] = from }
|
252
197
|
end
|
198
|
+
|
199
|
+
def block_validate(doc)
|
200
|
+
nested_asset_validate(doc)
|
201
|
+
all_empty_block_validate(doc)
|
202
|
+
end
|
203
|
+
|
204
|
+
def all_empty_block_validate(doc)
|
205
|
+
%w(note example admonition figure quote pre).each do |tag|
|
206
|
+
empty_block_validate(doc, "//#{tag}", nil)
|
207
|
+
end
|
208
|
+
empty_block_validate(doc, "//sourcecode", "body")
|
209
|
+
empty_block_validate(doc, "//formula", "stem")
|
210
|
+
empty_block_validate(doc, "//ol", "li")
|
211
|
+
empty_block_validate(doc, "//ul", "li")
|
212
|
+
empty_block_validate(doc, "//dl", "dt")
|
213
|
+
end
|
214
|
+
|
215
|
+
def empty_block_validate(doc, tag, body)
|
216
|
+
# require "debug"; binding.b
|
217
|
+
doc.xpath(tag).each do |t|
|
218
|
+
body and t = t.at("./#{body}")
|
219
|
+
empty_block?(t) or next
|
220
|
+
@log.add("Blocks", t, "#{tag.sub(/^\/\//, '')} is empty", severity: 1)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def empty_block?(block)
|
225
|
+
content = block.children.reject { |n| n.name == "name" }
|
226
|
+
content.map do |n|
|
227
|
+
%w(image xref eref).include?(n.name) ? n.name : n
|
228
|
+
end
|
229
|
+
content.map(&:to_s).join.strip.empty?
|
230
|
+
end
|
253
231
|
end
|
254
232
|
end
|
255
233
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "pngcheck"
|
2
|
+
|
3
|
+
module Metanorma
|
4
|
+
module Standoc
|
5
|
+
module Validate
|
6
|
+
def image_validate(doc)
|
7
|
+
image_exists(doc)
|
8
|
+
image_toobig(doc)
|
9
|
+
png_validate(doc)
|
10
|
+
end
|
11
|
+
|
12
|
+
def image_exists(doc)
|
13
|
+
doc.xpath("//image").each do |i|
|
14
|
+
Vectory::Utils::url?(i["src"]) and next
|
15
|
+
Vectory::Utils::datauri?(i["src"]) and next
|
16
|
+
expand_path(i["src"]) and next
|
17
|
+
@log.add("Images", i.parent,
|
18
|
+
"Image not found: #{i['src']}", severity: 0)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def expand_path(loc)
|
23
|
+
relative_path = File.join(@localdir, loc)
|
24
|
+
[loc, relative_path].detect do |p|
|
25
|
+
File.exist?(p) ? p : nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def png_validate(doc)
|
30
|
+
doc.xpath("//image[@mimetype = 'image/png']").each do |i|
|
31
|
+
Vectory::Utils::url?(i["src"]) and next
|
32
|
+
decoded = if Vectory::Utils::datauri?(i["src"])
|
33
|
+
Vectory::Utils::decode_datauri(i["src"])[:data]
|
34
|
+
else
|
35
|
+
path = expand_path(i["src"]) or next
|
36
|
+
File.binread(path)
|
37
|
+
end
|
38
|
+
png_validate1(i, decoded)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def png_validate1(img, buffer)
|
43
|
+
PngCheck.check_buffer(buffer)
|
44
|
+
rescue PngCheck::CorruptPngError => e
|
45
|
+
@log.add("Images", img.parent,
|
46
|
+
"Corrupt PNG image detected: #{e.message}")
|
47
|
+
end
|
48
|
+
|
49
|
+
TOO_BIG_IMG_ERR = <<~ERR.freeze
|
50
|
+
Image too large for Data URI encoding: disable Data URI encoding (`:data-uri-image: false`), or set `:data-uri-maxsize: 0`
|
51
|
+
ERR
|
52
|
+
|
53
|
+
def image_toobig(doc)
|
54
|
+
@dataurimaxsize.zero? and return
|
55
|
+
doc.xpath("//image").each do |i|
|
56
|
+
i["src"].size > @dataurimaxsize and
|
57
|
+
@log.add("Images", i.parent, TOO_BIG_IMG_ERR, severity: 0)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
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.1.0
|
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-06-
|
11
|
+
date: 2025-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -554,6 +554,7 @@ files:
|
|
554
554
|
- lib/metanorma/standoc/terms.rb
|
555
555
|
- lib/metanorma/standoc/utils.rb
|
556
556
|
- lib/metanorma/standoc/validate.rb
|
557
|
+
- lib/metanorma/standoc/validate_image.rb
|
557
558
|
- lib/metanorma/standoc/validate_schema.rb
|
558
559
|
- lib/metanorma/standoc/validate_section.rb
|
559
560
|
- lib/metanorma/standoc/validate_table.rb
|