isodoc 1.6.0 → 1.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +2 -12
- data/.hound.yml +3 -1
- data/.rubocop.yml +4 -8
- data/Rakefile +2 -2
- data/bin/rspec +1 -2
- data/isodoc.gemspec +4 -3
- data/lib/isodoc-yaml/i18n-ar.yaml +152 -0
- data/lib/isodoc-yaml/i18n-de.yaml +149 -0
- data/lib/isodoc-yaml/i18n-en.yaml +1 -0
- data/lib/isodoc-yaml/i18n-es.yaml +151 -0
- data/lib/isodoc-yaml/i18n-fr.yaml +1 -0
- data/lib/isodoc-yaml/i18n-ru.yaml +154 -0
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +1 -0
- data/lib/isodoc.rb +0 -2
- data/lib/isodoc/common.rb +2 -0
- data/lib/isodoc/convert.rb +10 -4
- data/lib/isodoc/css.rb +30 -26
- data/lib/isodoc/function/blocks.rb +26 -8
- data/lib/isodoc/function/blocks_example_note.rb +2 -2
- data/lib/isodoc/function/cleanup.rb +53 -45
- data/lib/isodoc/function/form.rb +51 -0
- data/lib/isodoc/function/inline.rb +8 -7
- data/lib/isodoc/function/references.rb +71 -77
- data/lib/isodoc/function/section.rb +28 -16
- data/lib/isodoc/function/table.rb +22 -22
- data/lib/isodoc/function/terms.rb +6 -7
- data/lib/isodoc/function/to_word_html.rb +19 -25
- data/lib/isodoc/function/utils.rb +180 -160
- data/lib/isodoc/gem_tasks.rb +36 -38
- data/lib/isodoc/headlesshtml_convert.rb +8 -7
- data/lib/isodoc/html_convert.rb +10 -4
- data/lib/isodoc/html_function/comments.rb +14 -12
- data/lib/isodoc/html_function/footnotes.rb +14 -7
- data/lib/isodoc/html_function/form.rb +62 -0
- data/lib/isodoc/html_function/html.rb +30 -26
- data/lib/isodoc/html_function/postprocess.rb +191 -226
- data/lib/isodoc/html_function/postprocess_footnotes.rb +59 -0
- data/lib/isodoc/html_function/sectionsplit.rb +230 -0
- data/lib/isodoc/i18n.rb +33 -31
- data/lib/isodoc/metadata.rb +22 -20
- data/lib/isodoc/metadata_contributor.rb +31 -28
- data/lib/isodoc/pdf_convert.rb +11 -13
- data/lib/isodoc/presentation_function/bibdata.rb +54 -30
- data/lib/isodoc/presentation_function/block.rb +17 -8
- data/lib/isodoc/presentation_function/inline.rb +72 -120
- data/lib/isodoc/presentation_function/math.rb +84 -0
- data/lib/isodoc/presentation_function/section.rb +55 -19
- data/lib/isodoc/presentation_xml_convert.rb +2 -0
- data/lib/isodoc/sassc_importer.rb +1 -1
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +28 -24
- data/lib/isodoc/word_function/footnotes.rb +22 -15
- data/lib/isodoc/word_function/postprocess.rb +50 -36
- data/lib/isodoc/xref.rb +11 -10
- data/lib/isodoc/xref/xref_counter.rb +32 -17
- data/lib/isodoc/xref/xref_gen.rb +33 -21
- data/lib/isodoc/xref/xref_gen_seq.rb +60 -35
- data/lib/isodoc/xref/xref_sect_gen.rb +37 -35
- data/spec/assets/scripts_override.html +3 -0
- data/spec/isodoc/blocks_spec.rb +2258 -2622
- data/spec/isodoc/cleanup_spec.rb +1103 -1107
- data/spec/isodoc/form_spec.rb +156 -0
- data/spec/isodoc/i18n_spec.rb +802 -917
- data/spec/isodoc/inline_spec.rb +1105 -921
- data/spec/isodoc/lists_spec.rb +316 -315
- data/spec/isodoc/metadata_spec.rb +384 -379
- data/spec/isodoc/postproc_spec.rb +1783 -1549
- data/spec/isodoc/presentation_xml_spec.rb +355 -278
- data/spec/isodoc/ref_spec.rb +718 -723
- data/spec/isodoc/section_spec.rb +216 -199
- data/spec/isodoc/sectionsplit_spec.rb +190 -0
- data/spec/isodoc/table_spec.rb +41 -42
- data/spec/isodoc/terms_spec.rb +84 -84
- data/spec/isodoc/xref_spec.rb +1024 -930
- metadata +33 -7
@@ -59,7 +59,7 @@ module IsoDoc::Function
|
|
59
59
|
name = node&.at(ns("./name"))&.remove
|
60
60
|
div.p do |p|
|
61
61
|
name and p.span **{ class: "note_label" } do |s|
|
62
|
-
name
|
62
|
+
name.children.each { |n| parse(n, s) }
|
63
63
|
s << note_delim
|
64
64
|
end
|
65
65
|
insert_tab(p, 1)
|
@@ -98,7 +98,7 @@ module IsoDoc::Function
|
|
98
98
|
@note = true
|
99
99
|
out.div **note_attrs(node) do |div|
|
100
100
|
node&.at(ns("./*[local-name() != 'name'][1]"))&.name == "p" ?
|
101
|
-
#node.first_element_child.name == "p" ?
|
101
|
+
# node.first_element_child.name == "p" ?
|
102
102
|
note_p_parse(node, div) : note_parse1(node, div)
|
103
103
|
end
|
104
104
|
@note = false
|
@@ -1,16 +1,17 @@
|
|
1
1
|
module IsoDoc::Function
|
2
2
|
module Cleanup
|
3
3
|
def textcleanup(docxml)
|
4
|
-
|
4
|
+
termref_cleanup(passthrough_cleanup(docxml))
|
5
5
|
end
|
6
6
|
|
7
7
|
def termref_cleanup(docxml)
|
8
|
-
docxml
|
9
|
-
gsub(/\s*\[MODIFICATION\]\s*\[\/TERMREF\]/,
|
10
|
-
|
11
|
-
gsub(
|
12
|
-
gsub(
|
13
|
-
gsub(
|
8
|
+
docxml
|
9
|
+
.gsub(/\s*\[MODIFICATION\]\s*\[\/TERMREF\]/,
|
10
|
+
l10n(", #{@i18n.modified} [/TERMREF]"))
|
11
|
+
.gsub(%r{\s*\[/TERMREF\]\s*</p>\s*<p>\s*\[TERMREF\]}, "; ")
|
12
|
+
.gsub(/\[TERMREF\]\s*/, l10n("[#{@i18n.source}: "))
|
13
|
+
.gsub(%r{\s*\[/TERMREF\]\s*}, l10n("]"))
|
14
|
+
.gsub(/\s*\[MODIFICATION\]/, l10n(", #{@i18n.modified} — "))
|
14
15
|
end
|
15
16
|
|
16
17
|
def passthrough_cleanup(docxml)
|
@@ -21,7 +22,7 @@ module IsoDoc::Function
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def cleanup(docxml)
|
24
|
-
@i18n ||= i18n_init(@lang, @script)
|
25
|
+
@i18n ||= i18n_init(@lang, @script)
|
25
26
|
comment_cleanup(docxml)
|
26
27
|
footnote_cleanup(docxml)
|
27
28
|
inline_header_cleanup(docxml)
|
@@ -34,30 +35,36 @@ module IsoDoc::Function
|
|
34
35
|
|
35
36
|
def table_long_strings_cleanup(docxml)
|
36
37
|
return unless @break_up_urls_in_tables == true
|
38
|
+
|
37
39
|
docxml.xpath("//td | //th").each do |d|
|
38
40
|
d.traverse do |n|
|
39
41
|
next unless n.text?
|
42
|
+
|
40
43
|
n.replace(HTMLEntities.new.encode(
|
41
|
-
|
44
|
+
break_up_long_strings(n.text),
|
45
|
+
))
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
46
|
-
def break_up_long_strings(
|
47
|
-
return
|
48
|
-
|
49
|
-
|
50
|
+
def break_up_long_strings(text)
|
51
|
+
return text if /^\s*$/.match?(text)
|
52
|
+
|
53
|
+
text.split(/(?=\s)/).map do |w|
|
54
|
+
if /^\s*$/.match(text) || (w.size < 30) then w
|
55
|
+
else
|
50
56
|
w.scan(/.{,30}/).map do |w1|
|
51
|
-
|
52
|
-
|
57
|
+
w1.size < 30 ? w1 : break_up_long_strings1(w1)
|
58
|
+
end.join
|
59
|
+
end
|
53
60
|
end.join
|
54
61
|
end
|
55
62
|
|
56
|
-
def break_up_long_strings1(
|
57
|
-
s =
|
58
|
-
if s.size == 1 then
|
63
|
+
def break_up_long_strings1(text)
|
64
|
+
s = text.split(%r{(?<=[,.?+;/=])})
|
65
|
+
if s.size == 1 then "#{text} "
|
59
66
|
else
|
60
|
-
s[-1] = "
|
67
|
+
s[-1] = " #{s[-1]}"
|
61
68
|
s.join
|
62
69
|
end
|
63
70
|
end
|
@@ -78,11 +85,11 @@ module IsoDoc::Function
|
|
78
85
|
docxml
|
79
86
|
end
|
80
87
|
|
81
|
-
def figure_get_or_make_dl(
|
82
|
-
dl =
|
88
|
+
def figure_get_or_make_dl(elem)
|
89
|
+
dl = elem.at(".//dl")
|
83
90
|
if dl.nil?
|
84
|
-
|
85
|
-
dl =
|
91
|
+
elem.add_child("<p><b>#{@i18n.key}</b></p><dl></dl>")
|
92
|
+
dl = elem.at(".//dl")
|
86
93
|
end
|
87
94
|
dl
|
88
95
|
end
|
@@ -91,10 +98,10 @@ module IsoDoc::Function
|
|
91
98
|
"//div[@class = 'figure'][descendant::aside]"\
|
92
99
|
"[not(descendant::div[@class = 'figure'])]".freeze
|
93
100
|
|
94
|
-
def figure_aside_process(
|
101
|
+
def figure_aside_process(elem, aside, key)
|
95
102
|
# get rid of footnote link, it is in diagram
|
96
|
-
|
97
|
-
fnref =
|
103
|
+
elem&.at("./a[@class='TableFootnoteRef']")&.remove
|
104
|
+
fnref = elem.at(".//span[@class='TableFootnoteRef']/..")
|
98
105
|
dt = key.add_child("<dt></dt>").first
|
99
106
|
dd = key.add_child("<dd></dd>").first
|
100
107
|
fnref.parent = dt
|
@@ -109,6 +116,7 @@ module IsoDoc::Function
|
|
109
116
|
def figure_cleanup(docxml)
|
110
117
|
docxml.xpath(FIGURE_WITH_FOOTNOTES).each do |f|
|
111
118
|
next unless f.at(".//aside[not(ancestor::p[@class = 'FigureTitle'])]")
|
119
|
+
|
112
120
|
key = figure_get_or_make_dl(f)
|
113
121
|
f.xpath(".//aside").each do |aside|
|
114
122
|
figure_aside_process(f, aside, key)
|
@@ -137,12 +145,13 @@ module IsoDoc::Function
|
|
137
145
|
docxml
|
138
146
|
end
|
139
147
|
|
140
|
-
def merge_fnref_into_fn_text(
|
141
|
-
fn =
|
148
|
+
def merge_fnref_into_fn_text(elem)
|
149
|
+
fn = elem.at('.//span[@class="TableFootnoteRef"]/..')
|
142
150
|
n = fn.next_element
|
143
151
|
n&.children&.first&.add_previous_sibling(fn.remove)
|
144
152
|
end
|
145
153
|
|
154
|
+
# preempt html2doc putting MsoNormal under TableFootnote class
|
146
155
|
def table_footnote_cleanup(docxml)
|
147
156
|
docxml.xpath("//table[descendant::aside]").each do |t|
|
148
157
|
t.xpath(".//aside").each do |a|
|
@@ -152,36 +161,36 @@ module IsoDoc::Function
|
|
152
161
|
t << a.remove
|
153
162
|
end
|
154
163
|
end
|
155
|
-
# preempt html2doc putting MsoNormal there
|
156
164
|
docxml.xpath("//p[not(self::*[@class])]"\
|
157
165
|
"[ancestor::*[@class = 'TableFootnote']]").each do |p|
|
158
166
|
p["class"] = "TableFootnote"
|
159
167
|
end
|
160
168
|
end
|
161
169
|
|
162
|
-
def remove_bottom_border(
|
163
|
-
|
164
|
-
|
170
|
+
def remove_bottom_border(cell)
|
171
|
+
cell["style"] =
|
172
|
+
cell["style"].gsub(/border-bottom:[^;]+;/, "border-bottom:0pt;")
|
165
173
|
end
|
166
174
|
|
167
|
-
def table_get_or_make_tfoot(
|
168
|
-
tfoot =
|
175
|
+
def table_get_or_make_tfoot(table)
|
176
|
+
tfoot = table.at(".//tfoot")
|
169
177
|
if tfoot.nil?
|
170
|
-
|
171
|
-
tfoot =
|
178
|
+
table.add_child("<tfoot></tfoot>")
|
179
|
+
tfoot = table.at(".//tfoot")
|
172
180
|
else
|
173
181
|
tfoot.xpath(".//td | .//th").each { |td| remove_bottom_border(td) }
|
174
182
|
end
|
175
183
|
tfoot
|
176
184
|
end
|
177
185
|
|
178
|
-
def new_fullcolspan_row(
|
186
|
+
def new_fullcolspan_row(table, tfoot)
|
179
187
|
# how many columns in the table?
|
180
188
|
cols = 0
|
181
|
-
|
189
|
+
table.at(".//tr").xpath("./td | ./th").each do |td|
|
182
190
|
cols += (td["colspan"] ? td["colspan"].to_i : 1)
|
183
191
|
end
|
184
|
-
style =
|
192
|
+
style =
|
193
|
+
%{border-top:0pt;border-bottom:#{IsoDoc::Function::Table::SW} 1.5pt;}
|
185
194
|
tfoot.add_child("<tr><td colspan='#{cols}' style='#{style}'/></tr>")
|
186
195
|
tfoot.xpath(".//td").last
|
187
196
|
end
|
@@ -204,15 +213,14 @@ module IsoDoc::Function
|
|
204
213
|
docxml
|
205
214
|
end
|
206
215
|
|
207
|
-
def symbols_cleanup(docxml)
|
208
|
-
end
|
216
|
+
def symbols_cleanup(docxml); end
|
209
217
|
|
210
|
-
def table_footnote_reference_format(
|
211
|
-
|
218
|
+
def table_footnote_reference_format(link)
|
219
|
+
link
|
212
220
|
end
|
213
221
|
|
214
|
-
def footnote_reference_format(
|
215
|
-
|
222
|
+
def footnote_reference_format(link)
|
223
|
+
link
|
216
224
|
end
|
217
225
|
end
|
218
226
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module IsoDoc::Function
|
2
|
+
module Form
|
3
|
+
def form_parse(node, out)
|
4
|
+
node.children.each do |n|
|
5
|
+
parse(n, out)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def input_parse(node, out)
|
10
|
+
case node["type"]
|
11
|
+
when "button" then out << "[#{node['value'] || 'BUTTON'}]"
|
12
|
+
when "checkbox" then out << "☐ "
|
13
|
+
when "date" then text_input(out)
|
14
|
+
when "file" then text_input(out)
|
15
|
+
when "password" then text_input(out)
|
16
|
+
when "radio" then out << "◎ "
|
17
|
+
when "submit" # nop
|
18
|
+
when "text" then text_input(out, node["maxlength"])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def text_input(out, length = 10)
|
23
|
+
length ||= 10
|
24
|
+
length = length.to_i
|
25
|
+
length.zero? and length = 10
|
26
|
+
out << "_" * length
|
27
|
+
out << " "
|
28
|
+
end
|
29
|
+
|
30
|
+
def select_parse(node, out)
|
31
|
+
text_input(out, node["size"] || 10)
|
32
|
+
end
|
33
|
+
|
34
|
+
def label_parse(node, out)
|
35
|
+
node.children.each do |n|
|
36
|
+
parse(n, out)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def option_parse(node, out); end
|
41
|
+
|
42
|
+
def textarea_parse(_node, out)
|
43
|
+
out.table **{ border: 1, width: "50%" } do |t|
|
44
|
+
t.tr do |tr|
|
45
|
+
tr.td do |td|
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -3,11 +3,12 @@ require_relative "inline_simple"
|
|
3
3
|
module IsoDoc::Function
|
4
4
|
module Inline
|
5
5
|
def link_parse(node, out)
|
6
|
-
|
6
|
+
url = node["target"]
|
7
|
+
node["updatetype"] == "true" and url = suffix_url(url)
|
8
|
+
out.a **attr_code(href: url, title: node["alt"]) do |l|
|
7
9
|
if node.text.empty?
|
8
10
|
l << node["target"].sub(/^mailto:/, "")
|
9
|
-
else
|
10
|
-
node.children.each { |n| parse(n, l) }
|
11
|
+
else node.children.each { |n| parse(n, l) }
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -33,6 +34,7 @@ module IsoDoc::Function
|
|
33
34
|
|
34
35
|
def suffix_url(url)
|
35
36
|
return url if %r{^https?://}.match?(url)
|
37
|
+
return url unless File.extname(url).empty?
|
36
38
|
|
37
39
|
url.sub(/#{File.extname(url)}$/, ".html")
|
38
40
|
end
|
@@ -78,8 +80,7 @@ module IsoDoc::Function
|
|
78
80
|
"#{@openmathdelim}#{HTMLEntities.new.encode(node.text)}"\
|
79
81
|
"#{@closemathdelim}"
|
80
82
|
when "MathML" then node.first_element_child.to_s
|
81
|
-
else
|
82
|
-
HTMLEntities.new.encode(node.text)
|
83
|
+
else HTMLEntities.new.encode(node.text)
|
83
84
|
end
|
84
85
|
out.span **{ class: "stem" } do |span|
|
85
86
|
span.parent.add_child ooml
|
@@ -122,13 +123,13 @@ module IsoDoc::Function
|
|
122
123
|
end
|
123
124
|
|
124
125
|
def add_parse(node, out)
|
125
|
-
out.span **{class: "addition"} do |e|
|
126
|
+
out.span **{ class: "addition" } do |e|
|
126
127
|
node.children.each { |n| parse(n, e) }
|
127
128
|
end
|
128
129
|
end
|
129
130
|
|
130
131
|
def del_parse(node, out)
|
131
|
-
out.span **{class: "deletion"} do |e|
|
132
|
+
out.span **{ class: "deletion" } do |e|
|
132
133
|
node.children.each { |n| parse(n, e) }
|
133
134
|
end
|
134
135
|
end
|
@@ -1,82 +1,81 @@
|
|
1
1
|
module IsoDoc::Function
|
2
2
|
module References
|
3
|
-
|
4
3
|
# This is highly specific to ISO, but it's not a bad precedent for
|
5
4
|
# references anyway; keeping here instead of in IsoDoc::Iso for now
|
6
|
-
def docid_l10n(
|
7
|
-
return
|
8
|
-
|
9
|
-
|
5
|
+
def docid_l10n(text)
|
6
|
+
return text if text.nil?
|
7
|
+
|
8
|
+
text.gsub(/All Parts/i, @i18n.all_parts.downcase) if @i18n.all_parts
|
9
|
+
text
|
10
10
|
end
|
11
11
|
|
12
12
|
# TODO generate formatted ref if not present
|
13
|
-
def nonstd_bibitem(list,
|
14
|
-
list.p **attr_code(iso_bibitem_entry_attrs(
|
15
|
-
ids = bibitem_ref_code(
|
13
|
+
def nonstd_bibitem(list, bib, ordinal, biblio)
|
14
|
+
list.p **attr_code(iso_bibitem_entry_attrs(bib, biblio)) do |ref|
|
15
|
+
ids = bibitem_ref_code(bib)
|
16
16
|
identifiers = render_identifier(ids)
|
17
17
|
if biblio then ref_entry_code(ref, ordinal, identifiers, ids)
|
18
18
|
else
|
19
|
-
ref <<
|
19
|
+
ref << (identifiers[0] || identifiers[1]).to_s
|
20
20
|
ref << ", #{identifiers[1]}" if identifiers[0] && identifiers[1]
|
21
21
|
end
|
22
22
|
ref << ", " unless biblio && !identifiers[1]
|
23
|
-
reference_format(
|
23
|
+
reference_format(bib, ref)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def std_bibitem_entry(list,
|
28
|
-
list.p **attr_code(iso_bibitem_entry_attrs(
|
29
|
-
identifiers = render_identifier(bibitem_ref_code(
|
27
|
+
def std_bibitem_entry(list, bib, ordinal, biblio)
|
28
|
+
list.p **attr_code(iso_bibitem_entry_attrs(bib, biblio)) do |ref|
|
29
|
+
identifiers = render_identifier(bibitem_ref_code(bib))
|
30
30
|
if biblio then ref_entry_code(ref, ordinal, identifiers, nil)
|
31
31
|
else
|
32
|
-
ref <<
|
32
|
+
ref << (identifiers[0] || identifiers[1]).to_s
|
33
33
|
ref << ", #{identifiers[1]}" if identifiers[0] && identifiers[1]
|
34
34
|
end
|
35
|
-
date_note_process(
|
35
|
+
date_note_process(bib, ref)
|
36
36
|
ref << ", " unless biblio && !identifiers[1]
|
37
|
-
reference_format(
|
37
|
+
reference_format(bib, ref)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
# if t is just a number, only use that ([1] Non-Standard)
|
42
42
|
# else, use both ordinal, as prefix, and t
|
43
|
-
def ref_entry_code(r, ordinal, t,
|
43
|
+
def ref_entry_code(r, ordinal, t, _id)
|
44
44
|
prefix_bracketed_ref(r, t[0] || "[#{ordinal}]")
|
45
|
-
t[1] and r <<
|
45
|
+
t[1] and r << (t[1]).to_s
|
46
46
|
end
|
47
47
|
|
48
|
-
def pref_ref_code(
|
49
|
-
|
48
|
+
def pref_ref_code(bib)
|
49
|
+
bib.at(ns("./docidentifier[not(@type = 'DOI' or @type = 'metanorma' "\
|
50
50
|
"or @type = 'ISSN' or @type = 'ISBN' or @type = 'rfc-anchor')]"))
|
51
51
|
end
|
52
52
|
|
53
53
|
# returns [metanorma, non-metanorma, DOI/ISSN/ISBN] identifiers
|
54
|
-
def bibitem_ref_code(
|
55
|
-
id =
|
56
|
-
id1 = pref_ref_code(
|
57
|
-
id2 =
|
58
|
-
"@type = 'ISBN']"))
|
54
|
+
def bibitem_ref_code(bib)
|
55
|
+
id = bib.at(ns("./docidentifier[@type = 'metanorma']"))
|
56
|
+
id1 = pref_ref_code(bib)
|
57
|
+
id2 = bib.at(ns("./docidentifier[@type = 'DOI' or @type = 'ISSN' or "\
|
58
|
+
"@type = 'ISBN']"))
|
59
59
|
return [id, id1, id2] if id || id1 || id2
|
60
|
+
|
60
61
|
id = Nokogiri::XML::Node.new("docidentifier", b.document)
|
61
62
|
id << "(NO ID)"
|
62
63
|
[nil, id, nil]
|
63
64
|
end
|
64
65
|
|
65
|
-
def bracket_if_num(
|
66
|
-
return nil if
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
def bracket_if_num(num)
|
67
|
+
return nil if num.nil?
|
68
|
+
|
69
|
+
num = num.text.sub(/^\[/, "").sub(/\]$/, "")
|
70
|
+
return "[#{num}]" if /^\d+$/.match?(num)
|
71
|
+
|
72
|
+
num
|
70
73
|
end
|
71
74
|
|
72
|
-
def render_identifier(
|
73
|
-
[
|
74
|
-
|
75
|
-
|
76
|
-
docid_prefix(id[1]["type"], id[1].text.sub(/^\[/, "").sub(/\]$/, "")),
|
77
|
-
id[2].nil? ? nil :
|
78
|
-
docid_prefix(id[2]["type"], id[2].text.sub(/^\[/, "").sub(/\]$/, "")),
|
79
|
-
]
|
75
|
+
def render_identifier(ident)
|
76
|
+
[bracket_if_num(ident[0]),
|
77
|
+
ident[1].nil? ? nil : ident[1].text.sub(/^\[/, "").sub(/\]$/, ""),
|
78
|
+
ident[2].nil? ? nil : ident[2].text.sub(/^\[/, "").sub(/\]$/, "")]
|
80
79
|
end
|
81
80
|
|
82
81
|
def docid_prefix(prefix, docid)
|
@@ -87,32 +86,34 @@ module IsoDoc::Function
|
|
87
86
|
|
88
87
|
def omit_docid_prefix(prefix)
|
89
88
|
return true if prefix.nil? || prefix.empty?
|
90
|
-
|
89
|
+
|
90
|
+
%w(ISO IEC IEV ITU W3C csd metanorma repository rfc-anchor)
|
91
|
+
.include? prefix
|
91
92
|
end
|
92
93
|
|
93
|
-
def date_note_process(
|
94
|
-
date_note =
|
94
|
+
def date_note_process(bib, ref)
|
95
|
+
date_note = bib.at(ns("./note[@type = 'Unpublished-Status']"))
|
95
96
|
return if date_note.nil?
|
97
|
+
|
96
98
|
date_note.children.first.replace("<p>#{date_note.content}</p>")
|
97
99
|
footnote_parse(date_note, ref)
|
98
100
|
end
|
99
101
|
|
100
|
-
def iso_bibitem_entry_attrs(
|
101
|
-
{ id:
|
102
|
+
def iso_bibitem_entry_attrs(bib, biblio)
|
103
|
+
{ id: bib["id"], class: biblio ? "Biblio" : "NormRef" }
|
102
104
|
end
|
103
105
|
|
104
|
-
def iso_title(
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
title
|
106
|
+
def iso_title(bib)
|
107
|
+
bib.at(ns("./title[@language = '#{@lang}' and @type = 'main']")) ||
|
108
|
+
bib.at(ns("./title[@language = '#{@lang}']")) ||
|
109
|
+
bib.at(ns("./title[@type = 'main']")) ||
|
110
|
+
bib.at(ns("./title"))
|
110
111
|
end
|
111
112
|
|
112
113
|
# reference not to be rendered because it is deemed implicit
|
113
114
|
# in the standards environment
|
114
|
-
def implicit_reference(
|
115
|
-
|
115
|
+
def implicit_reference(bib)
|
116
|
+
bib["hidden"] == "true"
|
116
117
|
end
|
117
118
|
|
118
119
|
def prefix_bracketed_ref(ref, text)
|
@@ -120,35 +121,37 @@ module IsoDoc::Function
|
|
120
121
|
insert_tab(ref, 1)
|
121
122
|
end
|
122
123
|
|
123
|
-
def reference_format(
|
124
|
-
if ftitle =
|
125
|
-
ftitle&.children&.each { |n| parse(n,
|
124
|
+
def reference_format(bib, out)
|
125
|
+
if ftitle = bib.at(ns("./formattedref"))
|
126
|
+
ftitle&.children&.each { |n| parse(n, out) }
|
126
127
|
else
|
127
|
-
|
128
|
-
|
129
|
-
title&.children&.each { |n| parse(n, i) }
|
128
|
+
out.i do |i|
|
129
|
+
iso_title(bib)&.children&.each { |n| parse(n, i) }
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
def is_standard(
|
134
|
+
def is_standard(bib)
|
135
135
|
ret = false
|
136
|
-
|
137
|
-
|
138
|
-
|
136
|
+
drop = %w(metanorma DOI ISSN ISBN)
|
137
|
+
bib.xpath(ns("./docidentifier")).each do |id|
|
138
|
+
next if id["type"].nil? || drop.include?(id["type"])
|
139
|
+
|
139
140
|
ret = true
|
140
141
|
end
|
141
142
|
ret
|
142
143
|
end
|
143
144
|
|
144
|
-
def biblio_list(
|
145
|
+
def biblio_list(refs, div, biblio)
|
145
146
|
i = 0
|
146
|
-
|
147
|
+
refs.children.each do |b|
|
147
148
|
if b.name == "bibitem"
|
148
149
|
next if implicit_reference(b)
|
150
|
+
|
149
151
|
i += 1
|
150
|
-
|
151
|
-
|
152
|
+
if is_standard(b) then std_bibitem_entry(div, b, i, biblio)
|
153
|
+
else nonstd_bibitem(div, b, i, biblio)
|
154
|
+
end
|
152
155
|
else
|
153
156
|
parse(b, div) unless %w(title).include? b.name
|
154
157
|
end
|
@@ -167,14 +170,13 @@ module IsoDoc::Function
|
|
167
170
|
clause_name(num, f.at(ns("./title")), div, nil)
|
168
171
|
if f.name == "clause"
|
169
172
|
f.elements.each { |e| parse(e, div) unless e.name == "title" }
|
170
|
-
else
|
171
|
-
biblio_list(f, div, false)
|
173
|
+
else biblio_list(f, div, false)
|
172
174
|
end
|
173
175
|
end
|
174
176
|
num
|
175
177
|
end
|
176
178
|
|
177
|
-
def bibliography_xpath
|
179
|
+
def bibliography_xpath
|
178
180
|
"//bibliography/clause[.//references]"\
|
179
181
|
"[not(.//references[@normative = 'true'])] | "\
|
180
182
|
"//bibliography/references[@normative = 'false']"
|
@@ -184,7 +186,7 @@ module IsoDoc::Function
|
|
184
186
|
f = isoxml.at(ns(bibliography_xpath)) and f["hidden"] != "true" or return
|
185
187
|
page_break(out)
|
186
188
|
out.div do |div|
|
187
|
-
div.h1 **{class: "Section3"} do |h1|
|
189
|
+
div.h1 **{ class: "Section3" } do |h1|
|
188
190
|
f&.at(ns("./title"))&.children&.each { |c2| parse(c2, h1) }
|
189
191
|
end
|
190
192
|
biblio_list(f, div, true)
|
@@ -193,19 +195,11 @@ module IsoDoc::Function
|
|
193
195
|
|
194
196
|
def bibliography_parse(node, out)
|
195
197
|
node["hidden"] != true or return
|
196
|
-
title = node&.at(ns("./title"))&.text || ""
|
197
198
|
out.div do |div|
|
198
199
|
clause_parse_title(node, div, node.at(ns("./title")), out,
|
199
200
|
{ class: "Section3" })
|
200
201
|
biblio_list(node, div, true)
|
201
202
|
end
|
202
203
|
end
|
203
|
-
|
204
|
-
def format_ref(ref, prefix, isopub, date, allparts)
|
205
|
-
ref = docid_prefix(prefix, ref)
|
206
|
-
return "[#{ref}]" if ref && /^\d+$/.match(ref) && !prefix &&
|
207
|
-
!/^\[.*\]$/.match(ref)
|
208
|
-
ref
|
209
|
-
end
|
210
204
|
end
|
211
205
|
end
|