isodoc 1.7.6 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/isodoc.gemspec +1 -1
- data/lib/isodoc/class_utils.rb +23 -0
- data/lib/isodoc/convert.rb +9 -0
- data/lib/isodoc/function/cleanup.rb +4 -0
- data/lib/isodoc/function/inline.rb +2 -4
- data/lib/isodoc/function/utils.rb +1 -1
- data/lib/isodoc/html_function/html.rb +1 -0
- data/lib/isodoc/html_function/postprocess.rb +4 -6
- data/lib/isodoc/metadata_date.rb +13 -11
- data/lib/isodoc/presentation_function/bibdata.rb +2 -2
- data/lib/isodoc/presentation_function/block.rb +0 -36
- data/lib/isodoc/presentation_function/inline.rb +14 -11
- data/lib/isodoc/presentation_function/terms.rb +179 -0
- data/lib/isodoc/presentation_xml_convert.rb +11 -4
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +24 -14
- data/lib/isodoc/word_function/comments.rb +0 -4
- data/lib/isodoc/word_function/postprocess.rb +184 -176
- data/lib/isodoc/xref/xref_gen.rb +18 -22
- data/lib/isodoc/xref/xref_gen_seq.rb +10 -16
- data/lib/isodoc/xref/xref_sect_gen.rb +134 -129
- data/lib/isodoc/xslfo_convert.rb +11 -7
- data/lib/isodoc-yaml/i18n-ar.yaml +22 -0
- data/lib/isodoc-yaml/i18n-de.yaml +20 -0
- data/lib/isodoc-yaml/i18n-en.yaml +20 -0
- data/lib/isodoc-yaml/i18n-es.yaml +20 -0
- data/lib/isodoc-yaml/i18n-fr.yaml +20 -0
- data/lib/isodoc-yaml/i18n-ru.yaml +21 -1
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +21 -0
- data/lib/metanorma/output/xslfo.rb +4 -11
- data/spec/assets/i18n.yaml +3 -1
- data/spec/isodoc/blocks_spec.rb +14 -8
- data/spec/isodoc/i18n_spec.rb +8 -8
- data/spec/isodoc/inline_spec.rb +200 -6
- data/spec/isodoc/lists_spec.rb +344 -222
- data/spec/isodoc/section_spec.rb +11 -10
- data/spec/isodoc/table_spec.rb +71 -73
- data/spec/isodoc/terms_spec.rb +354 -34
- data/spec/isodoc/xref_numbering_spec.rb +347 -0
- data/spec/isodoc/xref_spec.rb +271 -350
- data/spec/isodoc/xslfo_convert_spec.rb +34 -9
- metadata +7 -6
- data/lib/isodoc/presentation_function/concept.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec504b3b905ec960bef74398b3789ab5b7eb248dc05a7c3f64590db77d31cac6
|
4
|
+
data.tar.gz: c2de4c1589a7ff282715f4930a1851393358a64fd407c5a1e3bda02beddc0782
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34a1c43f6f34f90aa326ed7ff50ede791eadaf22c05ebf0f4183fb2cb3c708bd4f0512572b638a94e236b807f5a873986c24579fe126eb88ad15ef1e178c64d2
|
7
|
+
data.tar.gz: 23fbe4f295729ad565ab787903e9c4b49388671766b91477dc3d26302b8499da892f77d6e034ce4f6cc4ba1b0956c8dbb051e94a3a336acdb661d1e6d30e584b
|
data/isodoc.gemspec
CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
30
30
|
|
31
31
|
spec.add_dependency "asciimath"
|
32
|
-
spec.add_dependency "html2doc", "~> 1.
|
32
|
+
spec.add_dependency "html2doc", "~> 1.2.0"
|
33
33
|
spec.add_dependency "htmlentities", "~> 4.3.4"
|
34
34
|
spec.add_dependency "liquid", "~> 4"
|
35
35
|
# spec.add_dependency "metanorma", ">= 1.2.0"
|
data/lib/isodoc/class_utils.rb
CHANGED
@@ -27,5 +27,28 @@ module IsoDoc
|
|
27
27
|
end.join
|
28
28
|
Liquid::Template.parse(doc)
|
29
29
|
end
|
30
|
+
|
31
|
+
def case_strict(text, casing, script)
|
32
|
+
return text unless %w(Latn Cyrl Grek Armn).include?(script)
|
33
|
+
|
34
|
+
letters = text.chars
|
35
|
+
case casing
|
36
|
+
when "capital" then letters.first.upcase!
|
37
|
+
when "lowercase" then letters.first.downcase!
|
38
|
+
end
|
39
|
+
letters.join
|
40
|
+
end
|
41
|
+
|
42
|
+
def case_with_markup(linkend, casing, script)
|
43
|
+
seen = false
|
44
|
+
xml = Nokogiri::XML("<root>#{linkend}</root>")
|
45
|
+
xml.traverse do |b|
|
46
|
+
next unless b.text? && !seen
|
47
|
+
|
48
|
+
b.replace(Common::case_strict(b.text, casing, script))
|
49
|
+
seen = true
|
50
|
+
end
|
51
|
+
xml.root.children.to_xml
|
52
|
+
end
|
30
53
|
end
|
31
54
|
end
|
data/lib/isodoc/convert.rb
CHANGED
@@ -102,6 +102,7 @@ module IsoDoc
|
|
102
102
|
@bookmarks_allocated = { "X" => true }
|
103
103
|
@fn_bookmarks = {}
|
104
104
|
@baseassetpath = options[:baseassetpath]
|
105
|
+
@aligncrosselements = options[:aligncrosselements]
|
105
106
|
end
|
106
107
|
|
107
108
|
def tmpimagedir_suffix
|
@@ -118,6 +119,7 @@ module IsoDoc
|
|
118
119
|
|
119
120
|
def convert1(docxml, filename, dir)
|
120
121
|
@xrefs.parse docxml
|
122
|
+
bibitem_lookup(docxml)
|
121
123
|
noko do |xml|
|
122
124
|
xml.html **{ lang: @lang.to_s } do |html|
|
123
125
|
html.parent.add_namespace("epub", "http://www.idpf.org/2007/ops")
|
@@ -129,6 +131,13 @@ module IsoDoc
|
|
129
131
|
end.join("\n")
|
130
132
|
end
|
131
133
|
|
134
|
+
def bibitem_lookup(docxml)
|
135
|
+
@bibitems = docxml.xpath(ns("//references/bibitem"))
|
136
|
+
.each_with_object({}) do |b, m|
|
137
|
+
m[b["id"]] = b
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
132
141
|
def metadata_init(lang, script, i18n)
|
133
142
|
@meta = Metadata.new(lang, script, i18n)
|
134
143
|
end
|
@@ -165,6 +165,10 @@ module IsoDoc
|
|
165
165
|
t << a.remove
|
166
166
|
end
|
167
167
|
end
|
168
|
+
table_footnote_cleanup_propagate(docxml)
|
169
|
+
end
|
170
|
+
|
171
|
+
def table_footnote_cleanup_propagate(docxml)
|
168
172
|
docxml.xpath("//p[not(self::*[@class])]"\
|
169
173
|
"[ancestor::*[@class = 'TableFootnote']]").each do |p|
|
170
174
|
p["class"] = "TableFootnote"
|
@@ -41,10 +41,8 @@ module IsoDoc
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def eref_target(node)
|
44
|
-
|
45
|
-
|
46
|
-
"uri[@type = 'citation']"))
|
47
|
-
return href unless url
|
44
|
+
return "##{node['bibitemid']}" unless url = @bibitems[node["bibitemid"]]
|
45
|
+
&.at(ns("./uri[@type = 'citation']"))
|
48
46
|
|
49
47
|
href = suffix_url(url.text)
|
50
48
|
anchor = node&.at(ns(".//locality[@type = 'anchor']"))&.text&.strip
|
@@ -211,7 +211,7 @@ module IsoDoc
|
|
211
211
|
c = HTMLEntities.new
|
212
212
|
text.split(/([<>])/).each_slice(4).map do |a|
|
213
213
|
a[0] = c.encode(c.decode(a[0]), :hexadecimal)
|
214
|
-
a[
|
214
|
+
a[2] = c.encode(c.decode(a[2]), :hexadecimal) if a.size >= 3
|
215
215
|
a
|
216
216
|
end.join
|
217
217
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "isodoc/html_function/mathvariant_to_plain"
|
2
2
|
require_relative "postprocess_footnotes"
|
3
|
+
require "metanorma-utils"
|
3
4
|
|
4
5
|
module IsoDoc
|
5
6
|
module HtmlFunction
|
@@ -74,7 +75,8 @@ module IsoDoc
|
|
74
75
|
head = docxml.at("//*[local-name() = 'head']")
|
75
76
|
head << htmlstylesheet(@htmlstylesheet)
|
76
77
|
s = htmlstylesheet(@htmlstylesheet_override) and head << s
|
77
|
-
@bare and
|
78
|
+
@bare and
|
79
|
+
head << "<style>body {margin-left: 2em; margin-right: 2em;}</style>"
|
78
80
|
docxml
|
79
81
|
end
|
80
82
|
|
@@ -167,11 +169,7 @@ module IsoDoc
|
|
167
169
|
end
|
168
170
|
|
169
171
|
def datauri(img)
|
170
|
-
|
171
|
-
supertype = type == "xml" ? "application" : "image"
|
172
|
-
bin = IO.binread(image_localfile(img))
|
173
|
-
data = Base64.strict_encode64(bin)
|
174
|
-
img["src"] = "data:#{supertype}/#{type};base64,#{data}"
|
172
|
+
img["src"] = Metanorma::Utils::datauri(img["src"], @localdir)
|
175
173
|
end
|
176
174
|
|
177
175
|
def image_suffix(img)
|
data/lib/isodoc/metadata_date.rb
CHANGED
@@ -6,7 +6,7 @@ module IsoDoc
|
|
6
6
|
vote-ended}.freeze
|
7
7
|
|
8
8
|
def months
|
9
|
-
|
9
|
+
{
|
10
10
|
"01": @labels["month_january"],
|
11
11
|
"02": @labels["month_february"],
|
12
12
|
"03": @labels["month_march"],
|
@@ -19,30 +19,32 @@ module IsoDoc
|
|
19
19
|
"10": @labels["month_october"],
|
20
20
|
"11": @labels["month_november"],
|
21
21
|
"12": @labels["month_december"],
|
22
|
-
|
22
|
+
}
|
23
23
|
end
|
24
24
|
|
25
25
|
def monthyr(isodate)
|
26
26
|
m = /(?<yr>\d\d\d\d)-(?<mo>\d\d)/.match isodate
|
27
27
|
return isodate unless m && m[:yr] && m[:mo]
|
28
|
+
|
28
29
|
l10n("#{months[m[:mo].to_sym]} #{m[:yr]}",
|
29
|
-
|
30
|
+
@lang, @script)
|
30
31
|
end
|
31
32
|
|
32
33
|
def MMMddyyyy(isodate)
|
33
34
|
return nil if isodate.nil?
|
35
|
+
|
34
36
|
arr = isodate.split("-")
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
if arr.size == 1 && (/^\d+$/.match isodate)
|
38
|
+
Date.new(*arr.map(&:to_i)).strftime("%Y")
|
39
|
+
elsif arr.size == 2
|
40
|
+
Date.new(*arr.map(&:to_i)).strftime("%B %Y")
|
41
|
+
else
|
42
|
+
Date.parse(isodate).strftime("%B %d, %Y")
|
43
|
+
end
|
42
44
|
end
|
43
45
|
|
44
46
|
def bibdate(isoxml, _out)
|
45
|
-
isoxml.xpath(ns(
|
47
|
+
isoxml.xpath(ns("//bibdata/date")).each do |d|
|
46
48
|
set("#{d['type'].gsub(/-/, '_')}date".to_sym, Common::date_range(d))
|
47
49
|
end
|
48
50
|
end
|
@@ -10,7 +10,7 @@ module IsoDoc
|
|
10
10
|
"</localized-strings>"
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
def docid_prefixes(docxml)
|
14
14
|
docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
|
15
15
|
i.children = @xrefs.klass.docid_prefix(i["type"], i.text)
|
16
16
|
end
|
@@ -97,7 +97,7 @@ module IsoDoc
|
|
97
97
|
|
98
98
|
# https://stackoverflow.com/a/31822406
|
99
99
|
def blank?(elem)
|
100
|
-
elem.nil? || elem.respond_to?(:empty?) && elem.empty?
|
100
|
+
elem.nil? || (elem.respond_to?(:empty?) && elem.empty?)
|
101
101
|
end
|
102
102
|
|
103
103
|
def trim_hash(hash)
|
@@ -54,12 +54,6 @@ module IsoDoc
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
def termexample(docxml)
|
58
|
-
docxml.xpath(ns("//termexample")).each do |f|
|
59
|
-
example1(f)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
57
|
def example1(elem)
|
64
58
|
n = @xrefs.get[elem["id"]]
|
65
59
|
lbl = if n.nil? || n[:label].nil? || n[:label].empty?
|
@@ -89,36 +83,6 @@ module IsoDoc
|
|
89
83
|
prefix_name(elem, "", lbl, "name")
|
90
84
|
end
|
91
85
|
|
92
|
-
def termnote(docxml)
|
93
|
-
docxml.xpath(ns("//termnote")).each do |f|
|
94
|
-
termnote1(f)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# introduce name element
|
99
|
-
def termnote1(elem)
|
100
|
-
lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???")
|
101
|
-
prefix_name(elem, "", lower2cap(lbl), "name")
|
102
|
-
end
|
103
|
-
|
104
|
-
def termdefinition(docxml)
|
105
|
-
docxml.xpath(ns("//term[definition]")).each do |f|
|
106
|
-
termdefinition1(f)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def termdefinition1(elem)
|
111
|
-
return unless elem.xpath(ns("./definition")).size > 1
|
112
|
-
|
113
|
-
d = elem.at(ns("./definition"))
|
114
|
-
d = d.replace("<ol><li>#{d.children.to_xml}</li></ol>").first
|
115
|
-
elem.xpath(ns("./definition")).each do |f|
|
116
|
-
f = f.replace("<li>#{f.children.to_xml}</li>").first
|
117
|
-
d << f
|
118
|
-
end
|
119
|
-
d.wrap("<definition></definition>")
|
120
|
-
end
|
121
|
-
|
122
86
|
def recommendation(docxml)
|
123
87
|
docxml.xpath(ns("//recommendation")).each do |f|
|
124
88
|
recommendation1(f, lower2cap(@i18n.recommendation))
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require "metanorma-utils"
|
2
|
-
require_relative "./concept"
|
3
2
|
|
4
3
|
module IsoDoc
|
5
4
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
@@ -7,13 +6,16 @@ module IsoDoc
|
|
7
6
|
l10n("#{@xrefs.anchor(container, :xref)}, #{linkend}")
|
8
7
|
end
|
9
8
|
|
9
|
+
def anchor_value(id)
|
10
|
+
@xrefs.anchor(id, :value) || @xrefs.anchor(id, :label) ||
|
11
|
+
@xrefs.anchor(id, :xref)
|
12
|
+
end
|
13
|
+
|
10
14
|
def anchor_linkend(node, linkend)
|
11
15
|
if node["citeas"].nil? && node["bibitemid"]
|
12
16
|
return @xrefs.anchor(node["bibitemid"], :xref) || "???"
|
13
17
|
elsif node["target"] && node["droploc"]
|
14
|
-
return
|
15
|
-
@xrefs.anchor(node["target"], :label) ||
|
16
|
-
@xrefs.anchor(node["target"], :xref) || "???"
|
18
|
+
return anchor_value(node["target"]) || "???"
|
17
19
|
elsif node["target"] && !/.#./.match(node["target"])
|
18
20
|
linkend = anchor_linkend1(node)
|
19
21
|
end
|
@@ -27,14 +29,15 @@ module IsoDoc
|
|
27
29
|
(container && get_note_container_id(node) != container &&
|
28
30
|
@xrefs.get[node["target"]]) and
|
29
31
|
linkend = prefix_container(container, linkend, node["target"])
|
30
|
-
capitalise_xref(node, linkend)
|
32
|
+
capitalise_xref(node, linkend, anchor_value(node["target"]))
|
31
33
|
end
|
32
34
|
|
33
|
-
def capitalise_xref(node, linkend)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
def capitalise_xref(node, linkend, label)
|
36
|
+
linktext = linkend.gsub(/<[^>]+>/, "")
|
37
|
+
(label && !label.empty? && /^#{Regexp.escape(label)}/.match?(linktext)) ||
|
38
|
+
linktext[0, 1].match?(/\p{Upper}/) and return linkend
|
39
|
+
node["case"] and
|
40
|
+
return Common::case_with_markup(linkend, node["case"], @script)
|
38
41
|
|
39
42
|
capitalise_xref1(node, linkend)
|
40
43
|
end
|
@@ -43,7 +46,7 @@ module IsoDoc
|
|
43
46
|
prec = nearest_block_parent(node).xpath("./descendant-or-self::text()") &
|
44
47
|
node.xpath("./preceding::text()")
|
45
48
|
if prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map(&:text).join)
|
46
|
-
linkend
|
49
|
+
Common::case_with_markup(linkend, "capital", @script)
|
47
50
|
else linkend
|
48
51
|
end
|
49
52
|
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
module IsoDoc
|
2
|
+
class PresentationXMLConvert < ::IsoDoc::Convert
|
3
|
+
def concept(docxml)
|
4
|
+
docxml.xpath(ns("//concept")).each { |f| concept1(f) }
|
5
|
+
end
|
6
|
+
|
7
|
+
def concept1(node)
|
8
|
+
xref = node&.at(ns("./xref/@target"))&.text or
|
9
|
+
return concept_render(node, ital: node["ital"] || "true",
|
10
|
+
ref: node["ref"] || "true",
|
11
|
+
linkref: node["linkref"] || "true",
|
12
|
+
linkmention: node["linkmention"] || "false")
|
13
|
+
if node.at(ns("//definitions//dt[@id = '#{xref}']"))
|
14
|
+
concept_render(node, ital: node["ital"] || "false",
|
15
|
+
ref: node["ref"] || "false",
|
16
|
+
linkref: node["linkref"] || "true",
|
17
|
+
linkmention: node["linkmention"] || "false")
|
18
|
+
else concept_render(node, ital: node["ital"] || "true",
|
19
|
+
ref: node["ref"] || "true",
|
20
|
+
linkref: node["linkref"] || "true",
|
21
|
+
linkmention: node["linkmention"] || "false")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def concept_render(node, opts)
|
26
|
+
node&.at(ns("./refterm"))&.remove
|
27
|
+
r = node.at(ns("./renderterm"))
|
28
|
+
ref = node.at(ns("./xref | ./eref | ./termref"))
|
29
|
+
ref && opts[:ref] != "false" and r&.next = " "
|
30
|
+
opts[:ital] == "true" and r&.name = "em"
|
31
|
+
if opts[:linkmention] == "true" && !r.nil? && !ref.nil?
|
32
|
+
ref2 = ref.clone
|
33
|
+
r2 = r.clone
|
34
|
+
r.replace(ref2).children = r2
|
35
|
+
end
|
36
|
+
concept1_ref(node, ref, opts)
|
37
|
+
if opts[:ital] == "false"
|
38
|
+
r = node.at(ns(".//renderterm"))
|
39
|
+
r&.replace(r&.children)
|
40
|
+
end
|
41
|
+
node.replace(node.children)
|
42
|
+
end
|
43
|
+
|
44
|
+
def concept1_ref(_node, ref, opts)
|
45
|
+
ref.nil? and return
|
46
|
+
return ref.remove if opts[:ref] == "false"
|
47
|
+
|
48
|
+
r = concept1_ref_content(ref)
|
49
|
+
ref = r.at("./descendant-or-self::xmlns:xref | "\
|
50
|
+
"./descendant-or-self::xmlns:eref | "\
|
51
|
+
"./descendant-or-self::xmlns:termref")
|
52
|
+
%w(xref eref).include? ref&.name and get_linkend(ref)
|
53
|
+
if opts[:linkref] == "false" && %w(xref eref).include?(ref&.name)
|
54
|
+
ref.replace(ref.children)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def concept1_ref_content(ref)
|
59
|
+
if non_locality_elems(ref).select do |c|
|
60
|
+
!c.text? || /\S/.match(c)
|
61
|
+
end.empty?
|
62
|
+
ref.replace(@i18n.term_defined_in.sub(/%/,
|
63
|
+
ref.to_xml))
|
64
|
+
else ref.replace("[#{ref.to_xml}]")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def related(docxml)
|
69
|
+
docxml.xpath(ns("//related")).each { |f| related1(f) }
|
70
|
+
end
|
71
|
+
|
72
|
+
def related1(node)
|
73
|
+
p = node.at(ns("./preferred"))
|
74
|
+
ref = node.at(ns("./xref | ./eref | ./termref"))
|
75
|
+
label = @i18n.relatedterms[node["type"]].upcase
|
76
|
+
node.replace(l10n("<p><strong>#{label}:</strong> "\
|
77
|
+
"<em>#{p.to_xml}</em> (#{ref.to_xml})</p>"))
|
78
|
+
end
|
79
|
+
|
80
|
+
def designation(docxml)
|
81
|
+
docxml.xpath(ns("//preferred | //admitted | //deprecates")).each do |p|
|
82
|
+
designation1(p)
|
83
|
+
end
|
84
|
+
docxml.xpath(ns("//term")).each do |t|
|
85
|
+
merge_second_preferred(t)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def merge_second_preferred(term)
|
90
|
+
pref = nil
|
91
|
+
term.xpath(ns("./preferred")).each_with_index do |p, i|
|
92
|
+
if i.zero? then pref = p
|
93
|
+
else
|
94
|
+
pref << l10n("; #{p.children.to_xml}")
|
95
|
+
p.remove
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def designation1(desgn)
|
101
|
+
s = desgn.at(ns("./termsource"))
|
102
|
+
name = desgn.at(ns("./expression/name | ./letter-symbol/name | "\
|
103
|
+
"./graphical-symbol")) or return
|
104
|
+
|
105
|
+
g = desgn.at(ns("./expression/grammar")) and
|
106
|
+
name << " #{designation_grammar(g).join(', ')}"
|
107
|
+
desgn.children = name.children
|
108
|
+
s and desgn.next = s
|
109
|
+
end
|
110
|
+
|
111
|
+
def designation_grammar(grammar)
|
112
|
+
ret = []
|
113
|
+
grammar.xpath(ns("./gender")).each do |x|
|
114
|
+
ret << @i18n.grammar_abbrevs[x.text]
|
115
|
+
end
|
116
|
+
%w(isPreposition isParticiple isAdjective isVerb isAdverb isNoun)
|
117
|
+
.each do |x|
|
118
|
+
grammar.at(ns("./#{x}[text() = 'true']")) and
|
119
|
+
ret << @i18n.grammar_abbrevs[x]
|
120
|
+
end
|
121
|
+
ret
|
122
|
+
end
|
123
|
+
|
124
|
+
def definition1(elem)
|
125
|
+
nodes = Nokogiri::XML::NodeSet.new(elem.document)
|
126
|
+
v = elem&.at(ns("./verbaldefinition"))&.children and nodes += v
|
127
|
+
n = elem&.at(ns("./nonverbalrepresentation"))&.children and nodes += n
|
128
|
+
elem.children = nodes
|
129
|
+
end
|
130
|
+
|
131
|
+
def termexample(docxml)
|
132
|
+
docxml.xpath(ns("//termexample")).each do |f|
|
133
|
+
example1(f)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def termnote(docxml)
|
138
|
+
docxml.xpath(ns("//termnote")).each do |f|
|
139
|
+
termnote1(f)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# introduce name element
|
144
|
+
def termnote1(elem)
|
145
|
+
lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???")
|
146
|
+
prefix_name(elem, "", lower2cap(lbl), "name")
|
147
|
+
end
|
148
|
+
|
149
|
+
def termdefinition(docxml)
|
150
|
+
docxml.xpath(ns("//term[definition]")).each do |f|
|
151
|
+
termdefinition1(f)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def termdefinition1(elem)
|
156
|
+
unwrap_definition(elem)
|
157
|
+
multidef(elem) if elem.xpath(ns("./definition")).size > 1
|
158
|
+
end
|
159
|
+
|
160
|
+
def multidef(elem)
|
161
|
+
d = elem.at(ns("./definition"))
|
162
|
+
d = d.replace("<ol><li>#{d.children.to_xml}</li></ol>").first
|
163
|
+
elem.xpath(ns("./definition")).each do |f|
|
164
|
+
f = f.replace("<li>#{f.children.to_xml}</li>").first
|
165
|
+
d << f
|
166
|
+
end
|
167
|
+
d.wrap("<definition></definition>")
|
168
|
+
end
|
169
|
+
|
170
|
+
def unwrap_definition(elem)
|
171
|
+
elem.xpath(ns("./definition")).each do |d|
|
172
|
+
nodes = Nokogiri::XML::NodeSet.new(elem.document)
|
173
|
+
v = d&.at(ns("./verbaldefinition"))&.children and nodes += v
|
174
|
+
n = d&.at(ns("./nonverbalrepresentation"))&.children and nodes += n
|
175
|
+
d.children = nodes
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative "presentation_function/block"
|
2
|
+
require_relative "presentation_function/terms"
|
2
3
|
require_relative "presentation_function/inline"
|
3
4
|
require_relative "presentation_function/math"
|
4
5
|
require_relative "presentation_function/section"
|
@@ -25,6 +26,7 @@ module IsoDoc
|
|
25
26
|
@xrefs.parse docxml
|
26
27
|
section docxml
|
27
28
|
block docxml
|
29
|
+
terms docxml
|
28
30
|
inline docxml
|
29
31
|
end
|
30
32
|
|
@@ -46,17 +48,13 @@ module IsoDoc
|
|
46
48
|
sourcecode docxml
|
47
49
|
formula docxml
|
48
50
|
example docxml
|
49
|
-
termexample docxml
|
50
51
|
note docxml
|
51
|
-
termnote docxml
|
52
|
-
termdefinition docxml
|
53
52
|
permission docxml
|
54
53
|
requirement docxml
|
55
54
|
recommendation docxml
|
56
55
|
end
|
57
56
|
|
58
57
|
def inline(docxml)
|
59
|
-
concept docxml
|
60
58
|
xref docxml
|
61
59
|
eref docxml
|
62
60
|
origin docxml
|
@@ -65,6 +63,15 @@ module IsoDoc
|
|
65
63
|
variant docxml
|
66
64
|
end
|
67
65
|
|
66
|
+
def terms(docxml)
|
67
|
+
termexample docxml
|
68
|
+
termnote docxml
|
69
|
+
termdefinition docxml
|
70
|
+
designation docxml
|
71
|
+
concept docxml
|
72
|
+
related docxml
|
73
|
+
end
|
74
|
+
|
68
75
|
def postprocess(result, filename, _dir)
|
69
76
|
toXML(result, filename)
|
70
77
|
@files_to_delete.each { |f| FileUtils.rm_rf f }
|
data/lib/isodoc/version.rb
CHANGED
@@ -54,11 +54,11 @@ module IsoDoc
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def para_class(_node)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
return "Sourcecode" if @annotation
|
58
|
+
return "MsoCommentText" if @in_comment
|
59
|
+
return "Note" if @note
|
60
|
+
|
61
|
+
nil
|
62
62
|
end
|
63
63
|
|
64
64
|
def para_parse(node, out)
|
@@ -86,21 +86,31 @@ module IsoDoc
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def dl_parse(node, out)
|
89
|
+
return super unless node.ancestors("table, dl").empty?
|
90
|
+
|
91
|
+
dl_parse_table(node, out)
|
92
|
+
end
|
93
|
+
|
94
|
+
def dl_parse_table(node, out)
|
89
95
|
out.table **{ class: "dl" } do |v|
|
90
96
|
node.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
|
91
|
-
v
|
92
|
-
tr.td **{ valign: "top", align: "left" } do |term|
|
93
|
-
dt_parse(dt, term)
|
94
|
-
end
|
95
|
-
tr.td **{ valign: "top" } do |listitem|
|
96
|
-
dd.children.each { |n| parse(n, listitem) }
|
97
|
-
end
|
98
|
-
end
|
97
|
+
dl_parse_table1(v, dt, dd)
|
99
98
|
end
|
100
99
|
dl_parse_notes(node, v)
|
101
100
|
end
|
102
101
|
end
|
103
102
|
|
103
|
+
def dl_parse_table1(table, dterm, ddefn)
|
104
|
+
table.tr do |tr|
|
105
|
+
tr.td **{ valign: "top", align: "left" } do |term|
|
106
|
+
dt_parse(dterm, term)
|
107
|
+
end
|
108
|
+
tr.td **{ valign: "top" } do |listitem|
|
109
|
+
ddefn.children.each { |n| parse(n, listitem) }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
104
114
|
def dl_parse_notes(node, out)
|
105
115
|
return if node.elements.reject { |n| dt_dd? n }.empty?
|
106
116
|
|
@@ -120,8 +130,8 @@ module IsoDoc
|
|
120
130
|
dl
|
121
131
|
end
|
122
132
|
|
133
|
+
# get rid of footnote link, it is in diagram
|
123
134
|
def figure_aside_process(fig, aside, key)
|
124
|
-
# get rid of footnote link, it is in diagram
|
125
135
|
fig&.at("./a[@class='TableFootnoteRef']")&.remove
|
126
136
|
fnref = fig.at(".//span[@class='TableFootnoteRef']/..")
|
127
137
|
tr = key.add_child("<tr></tr>").first
|