isodoc 3.4.1 → 3.4.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/lib/isodoc/base_style/typography.scss +5 -0
- data/lib/isodoc/convert.rb +3 -2
- data/lib/isodoc/function/blocks.rb +33 -5
- data/lib/isodoc/function/blocks_example_note.rb +5 -3
- data/lib/isodoc/function/cleanup.rb +5 -4
- data/lib/isodoc/function/inline.rb +9 -27
- data/lib/isodoc/function/inline_simple.rb +25 -0
- data/lib/isodoc/function/references.rb +11 -4
- data/lib/isodoc/function/setup.rb +2 -1
- data/lib/isodoc/function/table.rb +2 -2
- data/lib/isodoc/function/to_word_html.rb +1 -0
- data/lib/isodoc/function/utils.rb +1 -1
- data/lib/isodoc/init.rb +17 -7
- data/lib/isodoc/metadata.rb +10 -6
- data/lib/isodoc/metadata_contributor.rb +15 -2
- data/lib/isodoc/presentation_function/autonum.rb +65 -4
- data/lib/isodoc/presentation_function/bibdata.rb +15 -4
- data/lib/isodoc/presentation_function/block.rb +36 -78
- data/lib/isodoc/presentation_function/docid.rb +18 -10
- data/lib/isodoc/presentation_function/erefs.rb +55 -28
- data/lib/isodoc/presentation_function/erefs_locality.rb +18 -10
- data/lib/isodoc/presentation_function/footnotes.rb +2 -1
- data/lib/isodoc/presentation_function/image.rb +15 -5
- data/lib/isodoc/presentation_function/index.rb +1 -5
- data/lib/isodoc/presentation_function/inline.rb +2 -20
- data/lib/isodoc/presentation_function/list.rb +3 -3
- data/lib/isodoc/presentation_function/metadata.rb +50 -32
- data/lib/isodoc/presentation_function/refs.rb +70 -86
- data/lib/isodoc/presentation_function/section.rb +0 -3
- data/lib/isodoc/presentation_function/section_refs.rb +55 -0
- data/lib/isodoc/presentation_function/source.rb +73 -0
- data/lib/isodoc/presentation_function/terms.rb +7 -5
- data/lib/isodoc/presentation_function/xrefs.rb +17 -6
- data/lib/isodoc/presentation_xml_convert.rb +10 -4
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/lists.rb +4 -2
- data/lib/isodoc/word_function/postprocess_table.rb +3 -1
- data/lib/isodoc/xref/xref_gen.rb +72 -119
- data/lib/isodoc/xref/xref_gen_seq.rb +18 -14
- data/lib/isodoc/xref/xref_list_gen.rb +107 -0
- data/lib/isodoc/xref/xref_sect_asset.rb +0 -1
- data/lib/isodoc/xref/xref_sect_gen.rb +0 -2
- data/lib/isodoc/xref.rb +1 -0
- data/lib/isodoc/xslfo_convert.rb +5 -1
- data/lib/isodoc-yaml/i18n-ar.yaml +9 -0
- data/lib/isodoc-yaml/i18n-de.yaml +9 -0
- data/lib/isodoc-yaml/i18n-en.yaml +9 -0
- data/lib/isodoc-yaml/i18n-es.yaml +9 -0
- data/lib/isodoc-yaml/i18n-fr.yaml +9 -0
- data/lib/isodoc-yaml/i18n-ja.yaml +9 -0
- data/lib/isodoc-yaml/i18n-ru.yaml +9 -0
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +9 -0
- metadata +5 -2
|
@@ -18,14 +18,14 @@ module IsoDoc
|
|
|
18
18
|
def logo_expand_pres_metadata(docxml)
|
|
19
19
|
docxml.xpath(ns("//metanorma-extension/presentation-metadata/*"))
|
|
20
20
|
.each do |x|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
logo_size_pres_metadata_incomplete?(x) or next
|
|
22
|
+
parts = x.name.split("-")
|
|
23
|
+
@output_formats.each_key do |f|
|
|
24
|
+
tagname = "logo-#{parts[1]}-#{f}-#{parts[2..].join('-')}"
|
|
25
|
+
x.parent.next = <<~XML
|
|
26
|
+
<presentation-metadata><#{tagname}>#{x.text}</#{tagname}></presentation-metadata>
|
|
27
|
+
XML
|
|
28
|
+
end
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
@@ -37,10 +37,25 @@ module IsoDoc
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def localized_strings(docxml)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
ins, langs, i18n_cache = localized_strings_prep(docxml)
|
|
41
|
+
ins or return
|
|
42
|
+
words = langs.each_with_object([]) do |l, m|
|
|
43
|
+
@i18n = if @lang == l then i18n_cache
|
|
44
|
+
else i18n_init(l, ::Metanorma::Utils.default_script(l), nil, {})
|
|
45
|
+
end
|
|
46
|
+
m << i18n_name(trim_hash(@i18n.get), "", l).join
|
|
47
|
+
end
|
|
48
|
+
ins.next = "<localized-strings>#{words.join}</localized-strings>"
|
|
49
|
+
@i18n = i18n_cache
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def localized_strings_prep(docxml)
|
|
53
|
+
ins = docxml.at(ns("//bibdata")) or return
|
|
54
|
+
langs = docxml.xpath(ns("//bibdata/title/@language")).map(&:to_s)
|
|
55
|
+
langs << @lang
|
|
56
|
+
langs.uniq!
|
|
57
|
+
i18n_cache = @i18n
|
|
58
|
+
[ins, langs, i18n_cache]
|
|
44
59
|
end
|
|
45
60
|
|
|
46
61
|
def attachments_extract(docxml)
|
|
@@ -81,7 +96,7 @@ module IsoDoc
|
|
|
81
96
|
@tocfigures || @toctables || @tocrecommendations or return
|
|
82
97
|
ins = extension_insert(docxml)
|
|
83
98
|
@tocfigures and
|
|
84
|
-
ins
|
|
99
|
+
ins.add_child "<toc type='figure'><title>#{@i18n.toc_figures}</title></toc>"
|
|
85
100
|
@toctables and
|
|
86
101
|
ins << "<toc type='table'><title>#{@i18n.toc_tables}</title></toc>"
|
|
87
102
|
@tocfigures and
|
|
@@ -90,27 +105,29 @@ module IsoDoc
|
|
|
90
105
|
end
|
|
91
106
|
|
|
92
107
|
def fonts_metadata(xmldoc)
|
|
108
|
+
@fontlicenseagreement || @fontist_fonts or return
|
|
93
109
|
ins = presmeta_insert_pt(xmldoc)
|
|
94
|
-
@fontist_fonts and CSV.parse_line(@fontist_fonts, col_sep: ";")
|
|
95
|
-
.map(&:strip).reverse_each do |f|
|
|
96
|
-
ins.next = presmeta("fonts", f)
|
|
97
|
-
end
|
|
98
110
|
@fontlicenseagreement and
|
|
99
|
-
ins.
|
|
111
|
+
ins.add_child(presmeta("font-license-agreement", @fontlicenseagreement))
|
|
112
|
+
@fontist_fonts and CSV.parse_line(@fontist_fonts, col_sep: ";").compact
|
|
113
|
+
.map(&:strip).reject(&:empty?).each do |f|
|
|
114
|
+
ins.add_child(presmeta("fonts", f))
|
|
115
|
+
end
|
|
100
116
|
end
|
|
101
117
|
|
|
102
118
|
def presmeta_insert_pt(xmldoc)
|
|
103
|
-
xmldoc.at(ns("//presentation-metadata"))
|
|
104
|
-
|
|
119
|
+
ins = xmldoc.at(ns("//presentation-metadata")) and return ins
|
|
120
|
+
ins = extension_insert_pt(xmldoc)
|
|
121
|
+
ins << "<presentation-metadata> </presentation-metadata>"
|
|
122
|
+
ins.elements.last
|
|
105
123
|
end
|
|
106
124
|
|
|
107
125
|
def presmeta(name, value)
|
|
108
|
-
"
|
|
109
|
-
"</presentation-metadata>"
|
|
126
|
+
"<#{name}>#{value}</#{name}>"
|
|
110
127
|
end
|
|
111
128
|
|
|
112
|
-
def i18n_tag(key, value)
|
|
113
|
-
"<localized-string key='#{key}' language='#{
|
|
129
|
+
def i18n_tag(key, value, lang)
|
|
130
|
+
"<localized-string key='#{key}' language='#{lang}'>#{value}" \
|
|
114
131
|
"</localized-string>"
|
|
115
132
|
end
|
|
116
133
|
|
|
@@ -118,28 +135,29 @@ module IsoDoc
|
|
|
118
135
|
key.to_s.gsub(/\s|\./, "_")
|
|
119
136
|
end
|
|
120
137
|
|
|
121
|
-
def
|
|
138
|
+
def i18n_name(hash, pref, lang)
|
|
122
139
|
case hash
|
|
123
|
-
when Hash then
|
|
140
|
+
when Hash then i18n_name1(hash, pref, lang)
|
|
124
141
|
when Array
|
|
125
142
|
hash.reject { |a| blank?(a) }.each_with_object([])
|
|
126
143
|
.with_index do |(v1, g), i|
|
|
127
|
-
|
|
144
|
+
i18n_name(v1, "#{i18n_safe(k)}.#{i}", lang).each { |x| g << x }
|
|
128
145
|
end
|
|
129
|
-
else [i18n_tag(pref, hash)]
|
|
146
|
+
else [i18n_tag(pref, hash, lang)]
|
|
130
147
|
end
|
|
131
148
|
end
|
|
132
149
|
|
|
133
|
-
def
|
|
150
|
+
def i18n_name1(hash, pref, lang)
|
|
134
151
|
hash.reject { |_k, v| blank?(v) }.each_with_object([]) do |(k, v), g|
|
|
135
152
|
case v
|
|
136
|
-
when Hash then
|
|
153
|
+
when Hash then i18n_name(v, i18n_safe(k), lang).each { |x| g << x }
|
|
137
154
|
when Array
|
|
138
155
|
v.reject { |a| blank?(a) }.each_with_index do |v1, i|
|
|
139
|
-
|
|
156
|
+
i18n_name(v1, "#{i18n_safe(k)}.#{i}", lang).each { |x| g << x }
|
|
140
157
|
end
|
|
141
158
|
else
|
|
142
|
-
g << i18n_tag("#{pref}#{pref.empty? ? '' : '.'}#{i18n_safe(k)}", v
|
|
159
|
+
g << i18n_tag("#{pref}#{pref.empty? ? '' : '.'}#{i18n_safe(k)}", v,
|
|
160
|
+
lang)
|
|
143
161
|
end
|
|
144
162
|
end
|
|
145
163
|
end
|
|
@@ -1,59 +1,5 @@
|
|
|
1
|
-
require_relative "docid"
|
|
2
|
-
|
|
3
1
|
module IsoDoc
|
|
4
2
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
|
5
|
-
def references(docxml)
|
|
6
|
-
@ref_renderings = references_render(docxml)
|
|
7
|
-
docxml.xpath(ns("//references/bibitem")).each do |x|
|
|
8
|
-
bibitem(x, @ref_renderings)
|
|
9
|
-
reference_name(x)
|
|
10
|
-
end
|
|
11
|
-
bibliography_bibitem_number(docxml)
|
|
12
|
-
hidden_items(docxml)
|
|
13
|
-
move_norm_ref_to_sections(docxml)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def reference_names(docxml)
|
|
17
|
-
docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref|
|
|
18
|
-
reference_name(ref)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def reference_name(ref)
|
|
23
|
-
ids = bibitem_ref_code(ref)
|
|
24
|
-
identifiers = render_identifier(ids)
|
|
25
|
-
reference = docid_l10n(identifiers[:metanorma] || identifiers[:sdo] ||
|
|
26
|
-
identifiers[:ordinal] || identifiers[:doi])
|
|
27
|
-
@xrefs.get[ref["id"]] = { xref: esc(reference) }
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def move_norm_ref_to_sections(docxml)
|
|
31
|
-
docxml.at(ns(@xrefs.klass.norm_ref_xpath)) or return
|
|
32
|
-
s = move_norm_ref_to_sections_insert_pt(docxml) or return
|
|
33
|
-
docxml.xpath(ns(@xrefs.klass.norm_ref_xpath)).each do |r|
|
|
34
|
-
r.at("./ancestor::xmlns:bibliography") or next
|
|
35
|
-
s << r.remove
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def move_norm_ref_to_sections_insert_pt(docxml)
|
|
40
|
-
s = docxml.at(ns("//sections")) and return s
|
|
41
|
-
s = docxml.at(ns("//preface")) and
|
|
42
|
-
return s.after("<sections/>").next_element
|
|
43
|
-
docxml.at(ns("//annex | //bibliography"))&.before("<sections/>")
|
|
44
|
-
&.previous_element
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def hidden_items(docxml)
|
|
48
|
-
docxml.xpath(ns("//references[bibitem/@hidden = 'true']")).each do |x|
|
|
49
|
-
x.at(ns("./bibitem[not(@hidden = 'true')]")) and next
|
|
50
|
-
x.elements.map(&:name).any? do |n|
|
|
51
|
-
!%w(title bibitem).include?(n)
|
|
52
|
-
end and next
|
|
53
|
-
x["hidden"] = "true"
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
3
|
def references_render(docxml)
|
|
58
4
|
d = docxml.clone
|
|
59
5
|
d.remove_namespaces!
|
|
@@ -70,29 +16,58 @@ module IsoDoc
|
|
|
70
16
|
bib["type"] ||= "standard"
|
|
71
17
|
end
|
|
72
18
|
|
|
73
|
-
def bibitem(
|
|
74
|
-
implicit_reference(
|
|
75
|
-
|
|
19
|
+
def bibitem(bib, renderings)
|
|
20
|
+
implicit_reference(bib) and bib["hidden"] = "true"
|
|
21
|
+
notes_inside_bibitem(bib)
|
|
22
|
+
bibrender_item(bib, renderings)
|
|
23
|
+
add_id_to_display_bib_notes(bib)
|
|
24
|
+
@xrefs.bibitem_note_names(bib)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def notes_inside_bibitem(bib)
|
|
28
|
+
while (n = bib.next_element) && n.name == "note"
|
|
29
|
+
n["type"] = (n["type"] ? "display,#{n['type']}" : "display")
|
|
30
|
+
bib << n.remove
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def add_id_to_display_bib_notes(bib)
|
|
35
|
+
bib.xpath(ns("./note")).each do |n|
|
|
36
|
+
t = n["type"] or next
|
|
37
|
+
t.split(",").map(&:strip).include?("display") or next
|
|
38
|
+
add_id(n)
|
|
39
|
+
end
|
|
76
40
|
end
|
|
77
41
|
|
|
78
|
-
def bibrender_item(
|
|
79
|
-
if (f =
|
|
80
|
-
bibrender_formattedref(f,
|
|
81
|
-
else bibrender_relaton(
|
|
42
|
+
def bibrender_item(bib, renderings)
|
|
43
|
+
if (f = bib.at(ns("./formattedref"))) && bib.at(ns("./title")).nil?
|
|
44
|
+
bibrender_formattedref(f, bib)
|
|
45
|
+
else bibrender_relaton(bib, renderings)
|
|
82
46
|
end
|
|
47
|
+
bibitem_notes(bib)
|
|
83
48
|
end
|
|
84
49
|
|
|
85
|
-
def bibrender_formattedref(formattedref,
|
|
50
|
+
def bibrender_formattedref(formattedref, bib); end
|
|
86
51
|
|
|
87
|
-
def bibrender_relaton(
|
|
88
|
-
f = renderings[
|
|
52
|
+
def bibrender_relaton(bib, renderings)
|
|
53
|
+
f = renderings[bib["id"]][:formattedref] or return
|
|
89
54
|
f &&= "<formattedref>#{f}</formattedref>"
|
|
90
|
-
if x =
|
|
55
|
+
if x = bib.at(ns("./formattedref"))
|
|
91
56
|
x.replace(f)
|
|
92
|
-
elsif
|
|
93
|
-
|
|
57
|
+
elsif bib.children.empty?
|
|
58
|
+
bib << f
|
|
94
59
|
else
|
|
95
|
-
|
|
60
|
+
bib.children.first.previous = f
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def bibitem_notes(bib)
|
|
65
|
+
f = bib.at(ns("./formattedref")) or return
|
|
66
|
+
bibnote_extract(bib, "display").each do |n|
|
|
67
|
+
f << <<~XML
|
|
68
|
+
<note type='display'>#{to_xml(semx_fmt_dup(n))}</note>
|
|
69
|
+
XML
|
|
70
|
+
transfer_id(n, f.elements.last)
|
|
96
71
|
end
|
|
97
72
|
end
|
|
98
73
|
|
|
@@ -164,31 +139,30 @@ module IsoDoc
|
|
|
164
139
|
datefn = date_note_process(bib)
|
|
165
140
|
ids = bibitem_ref_code(bib)
|
|
166
141
|
idents = render_identifier(ids)
|
|
167
|
-
ret = if biblio then biblio_ref_entry_code(ordinal, idents,
|
|
142
|
+
ret = if biblio then biblio_ref_entry_code(ordinal, idents,
|
|
168
143
|
standard, datefn, bib)
|
|
169
|
-
else norm_ref_entry_code(ordinal, idents,
|
|
170
|
-
bib)
|
|
144
|
+
else norm_ref_entry_code(ordinal, idents, standard, datefn, bib)
|
|
171
145
|
end
|
|
172
146
|
bib.add_first_child("<biblio-tag>#{@i18n.l10n(ret)}</biblio-tag>")
|
|
173
147
|
end
|
|
174
148
|
|
|
175
|
-
def norm_ref_entry_code(_ordinal,
|
|
176
|
-
ret = (
|
|
177
|
-
|
|
178
|
-
(
|
|
179
|
-
ret += ", #{esc
|
|
149
|
+
def norm_ref_entry_code(_ordinal, ids, _standard, datefn, _bib)
|
|
150
|
+
ret = esc((ids[:ordinal] || ids[:content] || ids[:metanorma] || ids[:sdo])
|
|
151
|
+
.to_s)
|
|
152
|
+
(ids[:ordinal] || ids[:metanorma]) && ids[:sdo] and
|
|
153
|
+
ret += ", #{esc ids[:sdo]}"
|
|
180
154
|
ret += datefn
|
|
181
155
|
ret.empty? and return ret
|
|
182
|
-
|
|
156
|
+
ids[:sdo] and ret += ","
|
|
183
157
|
ret.sub(",", "").strip.empty? and return ""
|
|
184
158
|
"#{ret} "
|
|
185
159
|
end
|
|
186
160
|
|
|
187
161
|
# if ids is just a number, only use that ([1] Non-Standard)
|
|
188
162
|
# else, use both ordinal, as prefix, and ids
|
|
189
|
-
def biblio_ref_entry_code(ordinal, ids,
|
|
190
|
-
|
|
191
|
-
|
|
163
|
+
def biblio_ref_entry_code(ordinal, ids, _standard, datefn, _bib)
|
|
164
|
+
ret = esc(ids[:ordinal]) || esc(ids[:content]) || esc(ids[:metanorma]) ||
|
|
165
|
+
"[#{esc ordinal.to_s}]"
|
|
192
166
|
if ids[:sdo] && !ids[:sdo].empty?
|
|
193
167
|
ret = prefix_bracketed_ref(ret)
|
|
194
168
|
ret += "#{esc ids[:sdo]}#{datefn}, "
|
|
@@ -202,14 +176,23 @@ module IsoDoc
|
|
|
202
176
|
"#{text}<tab/>"
|
|
203
177
|
end
|
|
204
178
|
|
|
179
|
+
def bibnote_extract(bib, type)
|
|
180
|
+
bib.xpath(ns("./note")).each_with_object([]) do |n, m|
|
|
181
|
+
n["type"] or next
|
|
182
|
+
n["type"].split(",").map(&:strip).include?(type) and m << n
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
205
186
|
# strip any fns in docidentifier before they are extracted for rendering
|
|
206
187
|
def date_note_process(bib)
|
|
207
188
|
ret = ident_fn(bib)
|
|
208
|
-
date_note = bib
|
|
209
|
-
date_note.
|
|
189
|
+
date_note = bibnote_extract(bib, "Unpublished-Status")
|
|
190
|
+
date_note.empty? and return ret
|
|
210
191
|
id = "_#{UUIDTools::UUID.random_create}"
|
|
211
192
|
@new_ids[id] = nil
|
|
212
|
-
|
|
193
|
+
<<~XML
|
|
194
|
+
#{ret}<fn id='#{id}' reference='#{id}'><p>#{date_note.first.content}</p></fn>
|
|
195
|
+
XML
|
|
213
196
|
end
|
|
214
197
|
|
|
215
198
|
def ident_fn(bib)
|
|
@@ -223,15 +206,16 @@ module IsoDoc
|
|
|
223
206
|
bib["hidden"] == "true"
|
|
224
207
|
end
|
|
225
208
|
|
|
226
|
-
|
|
209
|
+
# DOI, ISSN, ISBN cover term
|
|
210
|
+
SERIAL_NUM_DOCID = <<~XPATH.strip.freeze
|
|
227
211
|
@type = 'DOI' or @type = 'doi' or @type = 'ISSN' or @type = 'issn' or @type = 'ISBN' or @type = 'isbn' or starts-with(@type, 'ISSN.') or starts-with(@type, 'ISBN.') or starts-with(@type, 'issn.') or starts-with(@type, 'isbn.')
|
|
228
212
|
XPATH
|
|
229
213
|
|
|
230
214
|
def standard?(bib)
|
|
231
215
|
ret = false
|
|
232
216
|
bib.xpath(ns("./docidentifier")).each do |id|
|
|
233
|
-
id["type"].nil? ||
|
|
234
|
-
|
|
217
|
+
id["type"].nil? || id.at(".//self::*[#{SERIAL_NUM_DOCID} or "\
|
|
218
|
+
"@type = 'metanorma']") and next
|
|
235
219
|
ret = true
|
|
236
220
|
end
|
|
237
221
|
ret
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module IsoDoc
|
|
2
|
+
class PresentationXMLConvert < ::IsoDoc::Convert
|
|
3
|
+
def references(docxml)
|
|
4
|
+
@ref_renderings = references_render(docxml)
|
|
5
|
+
docxml.xpath(ns("//references/bibitem")).each do |x|
|
|
6
|
+
bibitem(x, @ref_renderings)
|
|
7
|
+
reference_name(x)
|
|
8
|
+
end
|
|
9
|
+
bibliography_bibitem_number(docxml)
|
|
10
|
+
hidden_items(docxml)
|
|
11
|
+
move_norm_ref_to_sections(docxml)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def reference_names(docxml)
|
|
15
|
+
docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref|
|
|
16
|
+
reference_name(ref)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def reference_name(ref)
|
|
21
|
+
identifiers = render_identifier(bibitem_ref_code(ref))
|
|
22
|
+
reference = docid_l10n(identifiers[:content] || identifiers[:metanorma] ||
|
|
23
|
+
identifiers[:sdo] || identifiers[:ordinal] ||
|
|
24
|
+
identifiers[:doi])
|
|
25
|
+
@xrefs.get[ref["id"]] = { xref: esc(reference), type: "bibitem" }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def move_norm_ref_to_sections(docxml)
|
|
29
|
+
docxml.at(ns(@xrefs.klass.norm_ref_xpath)) or return
|
|
30
|
+
s = move_norm_ref_to_sections_insert_pt(docxml) or return
|
|
31
|
+
docxml.xpath(ns(@xrefs.klass.norm_ref_xpath)).each do |r|
|
|
32
|
+
r.at("./ancestor::xmlns:bibliography") or next
|
|
33
|
+
s << r.remove
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def move_norm_ref_to_sections_insert_pt(docxml)
|
|
38
|
+
s = docxml.at(ns("//sections")) and return s
|
|
39
|
+
s = docxml.at(ns("//preface")) and
|
|
40
|
+
return s.after("<sections/>").next_element
|
|
41
|
+
docxml.at(ns("//annex | //bibliography"))&.before("<sections/>")
|
|
42
|
+
&.previous_element
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def hidden_items(docxml)
|
|
46
|
+
docxml.xpath(ns("//references[bibitem/@hidden = 'true']")).each do |x|
|
|
47
|
+
x.at(ns("./bibitem[not(@hidden = 'true')]")) and next
|
|
48
|
+
x.elements.map(&:name).any? do |n|
|
|
49
|
+
!%w(title bibitem).include?(n)
|
|
50
|
+
end and next
|
|
51
|
+
x["hidden"] = "true"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module IsoDoc
|
|
2
|
+
class PresentationXMLConvert < ::IsoDoc::Convert
|
|
3
|
+
# TODO will go back to just one source/modification, preserving it
|
|
4
|
+
def source(docxml)
|
|
5
|
+
fmt_source(docxml)
|
|
6
|
+
docxml.xpath(ns("//fmt-source/source/modification")).each do |f|
|
|
7
|
+
source_modification(f)
|
|
8
|
+
end
|
|
9
|
+
source_types(docxml)
|
|
10
|
+
docxml.xpath(ns("//fmt-source/source")).each do |f|
|
|
11
|
+
f.replace(semx_fmt_dup(f))
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def source_types(docxml)
|
|
16
|
+
docxml.xpath(ns("//table/fmt-source")).each { |f| tablesource(f) }
|
|
17
|
+
docxml.xpath(ns("//figure/fmt-source")).each { |f| figuresource(f) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def fmt_source(docxml)
|
|
21
|
+
n = docxml.xpath(ns("//source")) - docxml.xpath(ns("//term//source")) -
|
|
22
|
+
docxml.xpath(ns("//quote/source"))
|
|
23
|
+
n.each do |s|
|
|
24
|
+
dup = s.clone
|
|
25
|
+
modification_dup_align(s, dup)
|
|
26
|
+
s.next = "<fmt-source>#{to_xml(dup)}</fmt-source>"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def tablesource(elem)
|
|
31
|
+
source1(elem, :table)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def figuresource(elem)
|
|
35
|
+
source1(elem, :figure)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def source_join_delim(_elem)
|
|
39
|
+
"; "
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def source1(elem, ancestor)
|
|
43
|
+
esc_origin(elem)
|
|
44
|
+
source_elems = source1_gather(elem)
|
|
45
|
+
source_elems.each do |e|
|
|
46
|
+
esc_origin(e)
|
|
47
|
+
elem << "#{source_join_delim(elem)}#{to_xml(e.remove.children).strip}"
|
|
48
|
+
end
|
|
49
|
+
source1_label(elem, @i18n.l10n(to_xml(elem.children).strip), ancestor)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def source1_gather(elem)
|
|
53
|
+
source_elems = []
|
|
54
|
+
while elem = elem&.next_element
|
|
55
|
+
case elem.name
|
|
56
|
+
when "source"
|
|
57
|
+
when "fmt-source"
|
|
58
|
+
source_elems << elem
|
|
59
|
+
else break
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
source_elems
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def source1_label(elem, sources, _ancestor)
|
|
66
|
+
elem.children = l10n("[#{@i18n.source}: #{esc sources}]")
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def source_modification(mod)
|
|
70
|
+
termsource_modification(mod.parent)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -148,6 +148,12 @@ module IsoDoc
|
|
|
148
148
|
m1.replace("<modification>#{to_xml(new_m1)}</modification>")
|
|
149
149
|
end
|
|
150
150
|
|
|
151
|
+
def esc_origin(element)
|
|
152
|
+
element.xpath(ns(".//origin")).each do |origin|
|
|
153
|
+
origin.wrap("<esc></esc>")
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
151
157
|
# concatenate sources. localise the concatenation, escaping the docids
|
|
152
158
|
# within the concatenands
|
|
153
159
|
# from punctuation localisation: l10n(<esc>A</esc>, <esc>B</esc>)
|
|
@@ -158,11 +164,7 @@ module IsoDoc
|
|
|
158
164
|
while elem.next_element&.name == "source"
|
|
159
165
|
ret << semx_fmt_dup(elem.next_element.remove)
|
|
160
166
|
end
|
|
161
|
-
ret.each
|
|
162
|
-
element.xpath(ns(".//origin")).each do |origin|
|
|
163
|
-
origin.wrap("<esc></esc>")
|
|
164
|
-
end
|
|
165
|
-
end
|
|
167
|
+
ret.each { |element| esc_origin(element) }
|
|
166
168
|
s = ret.map { |x| to_xml(x) }.map(&:strip)
|
|
167
169
|
.join(termsource_join_delim(elem))
|
|
168
170
|
termsource_label(elem, @i18n.l10n(s))
|
|
@@ -15,13 +15,13 @@ module IsoDoc
|
|
|
15
15
|
|
|
16
16
|
def prefix_container(container, linkend, node, target)
|
|
17
17
|
prefix_container?(container, node) or return linkend
|
|
18
|
-
container_container =
|
|
19
|
-
|
|
18
|
+
container_container = prefix_container_container(container)
|
|
19
|
+
cntnr_label =
|
|
20
20
|
prefix_container(container_container,
|
|
21
21
|
anchor_xref(node, container, container: true),
|
|
22
22
|
node, target)
|
|
23
23
|
l10n(connectives_spans(@i18n.nested_xref
|
|
24
|
-
.sub("%1", "<span class='fmt-xref-container'>#{esc
|
|
24
|
+
.sub("%1", "<span class='fmt-xref-container'>#{esc cntnr_label}</span>")
|
|
25
25
|
.sub("%2", esc(linkend))))
|
|
26
26
|
end
|
|
27
27
|
|
|
@@ -135,7 +135,8 @@ module IsoDoc
|
|
|
135
135
|
def gather_xref_locations(node)
|
|
136
136
|
node.xpath(ns("./location")).each_with_object([]) do |l, m|
|
|
137
137
|
type = @xrefs.anchor(l["target"], :type)
|
|
138
|
-
m << { conn: l["connective"],
|
|
138
|
+
m << { conn: l["connective"], custom: l["custom-connective"],
|
|
139
|
+
target: l["target"],
|
|
139
140
|
type:, node: l, elem: @xrefs.anchor(l["target"], :elem),
|
|
140
141
|
container: @xrefs.anchor(l["target"], :container, false) ||
|
|
141
142
|
%w(termnote).include?(type) }
|
|
@@ -165,14 +166,24 @@ module IsoDoc
|
|
|
165
166
|
else
|
|
166
167
|
ret = loc2xref(list[0])
|
|
167
168
|
list[1..].each { |l| ret = i18n_chain_boolean(ret, l) }
|
|
169
|
+
if list[0][:conn] == "from" && list[0][:custom]
|
|
170
|
+
# TODO: languages with mandatory from, include from in chain_to
|
|
171
|
+
ret = connectives_spans("<conn>#{list[0][:custom]}</conn> ") + ret
|
|
172
|
+
end
|
|
168
173
|
ret
|
|
169
174
|
end
|
|
170
175
|
end
|
|
171
176
|
|
|
177
|
+
def conn_sub(str, conn)
|
|
178
|
+
str.sub(%r{<conn>[^<]+</conn>}, "<conn>#{conn}</conn>")
|
|
179
|
+
end
|
|
180
|
+
|
|
172
181
|
def i18n_chain_boolean(value, entry)
|
|
173
|
-
|
|
182
|
+
ret = @i18n.send("chain_#{entry[:conn]}")
|
|
174
183
|
.sub("%1", value)
|
|
175
|
-
.sub("%2", loc2xref(entry))
|
|
184
|
+
.sub("%2", loc2xref(entry))
|
|
185
|
+
c = entry[:custom] and ret = conn_sub(ret, c)
|
|
186
|
+
connectives_spans(ret)
|
|
176
187
|
end
|
|
177
188
|
|
|
178
189
|
def can_conflate_xref_rendering?(locs)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require_relative "presentation_function/block"
|
|
2
|
+
require_relative "presentation_function/source"
|
|
2
3
|
require_relative "presentation_function/list"
|
|
3
4
|
require_relative "presentation_function/reqt"
|
|
4
5
|
require_relative "presentation_function/concepts"
|
|
@@ -9,6 +10,10 @@ require_relative "presentation_function/erefs"
|
|
|
9
10
|
require_relative "presentation_function/inline"
|
|
10
11
|
require_relative "presentation_function/math"
|
|
11
12
|
require_relative "presentation_function/section"
|
|
13
|
+
require_relative "presentation_function/section_refs"
|
|
14
|
+
require_relative "presentation_function/title"
|
|
15
|
+
require_relative "presentation_function/refs"
|
|
16
|
+
require_relative "presentation_function/docid"
|
|
12
17
|
require_relative "presentation_function/index"
|
|
13
18
|
require_relative "presentation_function/bibdata"
|
|
14
19
|
require_relative "presentation_function/metadata"
|
|
@@ -42,6 +47,7 @@ module IsoDoc
|
|
|
42
47
|
@outputfile = Pathname.new(filename).basename.to_s
|
|
43
48
|
docid_prefixes(docxml) # feeds @xrefs.parse citation processing
|
|
44
49
|
provide_ids docxml # feeds @xrefs.parse
|
|
50
|
+
bibitem_lookup(docxml) # feeds citeas
|
|
45
51
|
@xrefs.parse docxml
|
|
46
52
|
@xrefs.klass.meta = @meta
|
|
47
53
|
counter_init
|
|
@@ -54,7 +60,7 @@ module IsoDoc
|
|
|
54
60
|
def bibitem_lookup(docxml)
|
|
55
61
|
@bibitem_lookup ||= docxml.xpath(ns("//references/bibitem"))
|
|
56
62
|
.each_with_object({}) do |b, m|
|
|
57
|
-
|
|
63
|
+
m[b["id"]] = b
|
|
58
64
|
end
|
|
59
65
|
end
|
|
60
66
|
|
|
@@ -90,6 +96,7 @@ module IsoDoc
|
|
|
90
96
|
end
|
|
91
97
|
|
|
92
98
|
def block(docxml)
|
|
99
|
+
amend docxml # feeds all other blocks
|
|
93
100
|
table docxml
|
|
94
101
|
figure docxml
|
|
95
102
|
sourcecode docxml
|
|
@@ -106,20 +113,19 @@ module IsoDoc
|
|
|
106
113
|
requirement docxml
|
|
107
114
|
recommendation docxml
|
|
108
115
|
requirement_render docxml
|
|
109
|
-
amend docxml
|
|
110
116
|
end
|
|
111
117
|
|
|
112
118
|
def inline(docxml)
|
|
113
119
|
document_footnotes docxml
|
|
114
120
|
comments docxml
|
|
115
|
-
bibitem_lookup(docxml) # feeds citeas
|
|
116
121
|
fmt_ref docxml # feeds citeas, xref, eref, origin, concept
|
|
117
122
|
citeas docxml # feeds xref, eref, origin, concept
|
|
118
123
|
xref docxml
|
|
119
124
|
eref docxml # feeds eref2link
|
|
120
125
|
origin docxml # feeds eref2link
|
|
121
126
|
concept docxml
|
|
122
|
-
eref2link docxml
|
|
127
|
+
eref2link docxml # feeds link
|
|
128
|
+
link docxml
|
|
123
129
|
mathml docxml
|
|
124
130
|
ruby docxml
|
|
125
131
|
variant docxml
|
data/lib/isodoc/version.rb
CHANGED
|
@@ -62,9 +62,11 @@ module IsoDoc
|
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def dl_table_attrs(node)
|
|
65
|
+
key = node.parent.name == "key" && node.parent["class"] == "formula_dl"
|
|
66
|
+
klass = key ? node.parent["class"] : nil
|
|
65
67
|
{ id: node["id"],
|
|
66
|
-
style:
|
|
67
|
-
class: node["class"] || "dl" }
|
|
68
|
+
style: key ? "text-align:left;" : nil,
|
|
69
|
+
class: klass || node["class"] || "dl" }
|
|
68
70
|
end
|
|
69
71
|
|
|
70
72
|
def dl_parse_table(node, out)
|
|
@@ -44,7 +44,9 @@ module IsoDoc
|
|
|
44
44
|
|
|
45
45
|
def word_nested_tables(docxml)
|
|
46
46
|
docxml.xpath("//table").each do |t|
|
|
47
|
-
t.xpath(".//table").
|
|
47
|
+
nested_tables = t.xpath(".//table") - t.xpath(".//td//table") -
|
|
48
|
+
t.xpath(".//th//table")
|
|
49
|
+
nested_tables.reverse_each do |tt|
|
|
48
50
|
t.next = tt.remove
|
|
49
51
|
end
|
|
50
52
|
end
|