metanorma-iso 3.1.3 → 3.1.4

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.
@@ -1,97 +0,0 @@
1
- module Metanorma
2
- module Iso
3
- class Converter < Standoc::Converter
4
- # DRG directives 3.7; but anticipated by standoc
5
- def subfigure_validate(xmldoc)
6
- elems = { footnote: "fn", note: "note", key: "dl" }
7
- xmldoc.xpath("//figure//figure").each do |f|
8
- elems.each do |k, v|
9
- f.xpath(".//#{v}").each do |n|
10
- @log.add("Style", n, "#{k} is not permitted in a subfigure")
11
- end
12
- end
13
- end
14
- end
15
-
16
- def image_name_prefix(xmldoc)
17
- std = xmldoc.at("//bibdata/ext/structuredidentifier/project-number") or
18
- return
19
- num = xmldoc.at("//bibdata/docnumber")&.text or return
20
- ed = xmldoc.at("//bibdata/edition")&.text || "1"
21
- prefix = num
22
- std["part"] and prefix += "-#{std['part']}"
23
- prefix += "_ed#{ed}"
24
- amd = std["amendment"] and prefix += "amd#{amd}"
25
- prefix
26
- end
27
-
28
- def image_name_suffix(xmldoc)
29
- case xmldoc.at("//bibdata/language")&.text
30
- when "fr" then "_f"
31
- when "de" then "_d"
32
- when "ru" then "_r"
33
- when "es" then "_s"
34
- when "ar" then "_a"
35
- # when "en" then "_e"
36
- else
37
- "_e"
38
- end
39
- end
40
-
41
- def disjunct_error(img, cond1, cond2, msg1, msg2)
42
- cond1 && !cond2 and
43
- @log.add("Style", img, "image name #{img['src']} #{msg1}")
44
- !cond1 && cond2 and
45
- @log.add("Style", img, "image name #{img['src']} #{msg2}")
46
- end
47
-
48
- def image_name_parse(img, prefix)
49
- m = %r[(SL)?#{prefix}fig(?<tab>Tab)?(?<annex>[A-Z])?(Text)?(?<num>\d+)
50
- (?<subfig>[a-z])?(?<key>_key\d+)?(?<lang>_[a-z])?$]x
51
- .match(File.basename(img["src"], ".*"))
52
- m.nil? and
53
- @log.add("Style", img,
54
- "image name #{img['src']} does not match DRG requirements")
55
- m
56
- end
57
-
58
- def image_name_validate1(i, prefix)
59
- m = image_name_parse(i, prefix) or return
60
- warn i["src"]
61
- disjunct_error(i, i.at("./ancestor::table"), !m[:tab].nil?,
62
- "is under a table but is not so labelled",
63
- "is labelled as under a table but is not")
64
- disjunct_error(i, i.at("./ancestor::annex"), !m[:annex].nil?,
65
- "is under an annex but is not so labelled",
66
- "is labelled as under an annex but is not")
67
- disjunct_error(i, i.xpath("./ancestor::figure").size > 1, !m[:subfig].nil?,
68
- "does not have a subfigure letter but is a subfigure",
69
- "has a subfigure letter but is not a subfigure")
70
- lang = image_name_suffix(i.document.root)
71
- (m[:lang] || "_e") == lang or
72
- @log.add("Style", i,
73
- "image name #{i['src']} expected to have suffix #{lang}")
74
- end
75
-
76
- # DRG directives 3.2
77
- def image_name_validate(xmldoc)
78
- prefix = image_name_prefix(xmldoc) or return
79
- xmldoc.xpath("//image").each do |i|
80
- i["src"].start_with?("data:") and next
81
- case File.basename(i["src"])
82
- when /^ISO_\d+_/
83
- when /^(SL)?#{prefix}fig/ then image_name_validate1(i, prefix)
84
- else
85
- @log.add("Style", i,
86
- "image name #{i['src']} does not match DRG requirements: expect #{prefix}fig")
87
- end
88
- end
89
- end
90
-
91
- def figure_validate(xmldoc)
92
- image_name_validate(xmldoc)
93
- subfigure_validate(xmldoc)
94
- end
95
- end
96
- end
97
- end