isodoc 2.10.0 → 3.0.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/.rubocop.yml +1 -1
- data/isodoc.gemspec +9 -4
- data/lib/isodoc/base_style/all.css +96 -0
- data/lib/isodoc/base_style/reset.css +96 -0
- data/lib/isodoc/base_style/reset.scss +75 -0
- data/lib/isodoc/base_style/scripts.html +45 -14
- data/lib/isodoc/class_utils.rb +4 -2
- data/lib/isodoc/convert.rb +0 -21
- data/lib/isodoc/css.rb +2 -4
- data/lib/isodoc/function/blocks.rb +37 -52
- data/lib/isodoc/function/blocks_example_note.rb +75 -29
- data/lib/isodoc/function/cleanup.rb +9 -44
- data/lib/isodoc/function/inline.rb +67 -13
- data/lib/isodoc/function/lists.rb +20 -14
- data/lib/isodoc/function/references.rb +9 -126
- data/lib/isodoc/function/reqt.rb +4 -3
- data/lib/isodoc/function/section.rb +30 -35
- data/lib/isodoc/function/section_titles.rb +22 -11
- data/lib/isodoc/function/table.rb +3 -3
- data/lib/isodoc/function/terms.rb +49 -26
- data/lib/isodoc/function/to_word_html.rb +46 -16
- data/lib/isodoc/function/utils.rb +11 -12
- data/lib/isodoc/gem_tasks.rb +1 -1
- data/lib/isodoc/html_function/footnotes.rb +2 -1
- data/lib/isodoc/html_function/html.rb +5 -7
- data/lib/isodoc/html_function/postprocess.rb +25 -6
- data/lib/isodoc/html_function/postprocess_cover.rb +13 -7
- data/lib/isodoc/html_function/postprocess_footnotes.rb +52 -47
- data/lib/isodoc/init.rb +31 -0
- data/lib/isodoc/metadata.rb +20 -13
- data/lib/isodoc/metadata_contributor.rb +5 -10
- data/lib/isodoc/metadata_date.rb +1 -1
- data/lib/isodoc/presentation_function/autonum.rb +153 -0
- data/lib/isodoc/presentation_function/bibdata.rb +4 -5
- data/lib/isodoc/presentation_function/block.rb +107 -40
- data/lib/isodoc/presentation_function/concepts.rb +184 -19
- data/lib/isodoc/presentation_function/docid.rb +78 -0
- data/lib/isodoc/presentation_function/erefs.rb +55 -31
- data/lib/isodoc/presentation_function/image.rb +64 -19
- data/lib/isodoc/presentation_function/index.rb +180 -0
- data/lib/isodoc/presentation_function/inline.rb +47 -16
- data/lib/isodoc/presentation_function/math.rb +128 -71
- data/lib/isodoc/presentation_function/metadata.rb +29 -66
- data/lib/isodoc/presentation_function/refs.rb +75 -28
- data/lib/isodoc/presentation_function/reqt.rb +7 -4
- data/lib/isodoc/presentation_function/section.rb +51 -129
- data/lib/isodoc/presentation_function/sourcecode.rb +52 -19
- data/lib/isodoc/presentation_function/terms.rb +107 -118
- data/lib/isodoc/presentation_function/title.rb +107 -0
- data/lib/isodoc/presentation_function/xrefs.rb +37 -17
- data/lib/isodoc/presentation_xml_convert.rb +24 -10
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +9 -37
- data/lib/isodoc/word_function/comments.rb +0 -1
- data/lib/isodoc/word_function/footnotes.rb +1 -1
- data/lib/isodoc/word_function/lists.rb +13 -9
- data/lib/isodoc/word_function/postprocess.rb +6 -0
- data/lib/isodoc/word_function/postprocess_cover.rb +6 -4
- data/lib/isodoc/word_function/postprocess_table.rb +1 -1
- data/lib/isodoc/word_function/postprocess_toc.rb +10 -6
- data/lib/isodoc/word_function/table.rb +2 -2
- data/lib/isodoc/xref/clause_order.rb +41 -0
- data/lib/isodoc/xref/xref_anchor.rb +31 -16
- data/lib/isodoc/xref/xref_counter.rb +18 -3
- data/lib/isodoc/xref/xref_counter_types.rb +14 -0
- data/lib/isodoc/xref/xref_gen.rb +61 -37
- data/lib/isodoc/xref/xref_gen_seq.rb +148 -81
- data/lib/isodoc/xref/xref_sect_gen.rb +84 -88
- data/lib/isodoc/xref/xref_util.rb +53 -4
- data/lib/isodoc/xref.rb +29 -10
- data/lib/isodoc/xslfo_convert.rb +14 -9
- data/lib/isodoc-yaml/i18n-ar.yaml +17 -13
- data/lib/isodoc-yaml/i18n-de.yaml +17 -13
- data/lib/isodoc-yaml/i18n-en.yaml +18 -17
- data/lib/isodoc-yaml/i18n-es.yaml +17 -13
- data/lib/isodoc-yaml/i18n-fr.yaml +17 -13
- data/lib/isodoc-yaml/i18n-ja.yaml +56 -52
- data/lib/isodoc-yaml/i18n-ru.yaml +17 -16
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +17 -13
- data/lib/nokogiri/xml/node.rb +14 -0
- data/lib/relaton/render-isodoc/config.yml +1 -1
- metadata +90 -13
|
@@ -4,10 +4,6 @@ require "pathname"
|
|
|
4
4
|
module IsoDoc
|
|
5
5
|
module Function
|
|
6
6
|
module ToWordHtml
|
|
7
|
-
def set_termdomain(termdomain)
|
|
8
|
-
@termdomain = termdomain
|
|
9
|
-
end
|
|
10
|
-
|
|
11
7
|
def note?
|
|
12
8
|
@note
|
|
13
9
|
end
|
|
@@ -153,6 +149,12 @@ module IsoDoc
|
|
|
153
149
|
@meta.get
|
|
154
150
|
end
|
|
155
151
|
|
|
152
|
+
def cross_align(isoxml, out)
|
|
153
|
+
isoxml.xpath(ns("//cross-align")).each do |c|
|
|
154
|
+
parse(c, out)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
156
158
|
def boilerplate(node, out)
|
|
157
159
|
@bare and return
|
|
158
160
|
boilerplate = node.at(ns("//boilerplate")) or return
|
|
@@ -186,12 +188,17 @@ module IsoDoc
|
|
|
186
188
|
when "bookmark" then bookmark_parse(node, out)
|
|
187
189
|
when "pagebreak" then pagebreak_parse(node, out)
|
|
188
190
|
when "callout" then callout_parse(node, out)
|
|
189
|
-
when "stem" then stem_parse(node, out)
|
|
191
|
+
when "fmt-stem" then stem_parse(node, out)
|
|
192
|
+
when "stem" then semx_stem_parse(node, out)
|
|
190
193
|
when "clause" then clause_parse(node, out)
|
|
191
|
-
when "xref" then
|
|
192
|
-
when "
|
|
193
|
-
when "
|
|
194
|
-
when "
|
|
194
|
+
when "xref" then semx_xref_parse(node, out)
|
|
195
|
+
when "fmt-xref" then xref_parse(node, out)
|
|
196
|
+
when "eref" then semx_eref_parse(node, out)
|
|
197
|
+
when "fmt-eref" then eref_parse(node, out)
|
|
198
|
+
when "origin" then semx_origin_parse(node, out)
|
|
199
|
+
when "fmt-origin" then origin_parse(node, out)
|
|
200
|
+
when "link" then semx_link_parse(node, out)
|
|
201
|
+
when "fmt-link" then link_parse(node, out)
|
|
195
202
|
when "ul" then ul_parse(node, out)
|
|
196
203
|
when "ol" then ol_parse(node, out)
|
|
197
204
|
when "li" then li_parse(node, out)
|
|
@@ -213,12 +220,18 @@ module IsoDoc
|
|
|
213
220
|
when "pre" then pre_parse(node, out)
|
|
214
221
|
when "annotation" then annotation_parse(node, out)
|
|
215
222
|
when "term" then termdef_parse(node, out)
|
|
216
|
-
when "preferred" then
|
|
217
|
-
when "
|
|
218
|
-
when "
|
|
219
|
-
when "
|
|
220
|
-
when "
|
|
221
|
-
when "
|
|
223
|
+
when "preferred" then semx_term_parse(node, out)
|
|
224
|
+
when "fmt-preferred" then term_parse(node, out)
|
|
225
|
+
when "admitted" then semx_admitted_term_parse(node, out)
|
|
226
|
+
when "fmt-admitted" then admitted_term_parse(node, out)
|
|
227
|
+
when "deprecates" then semx_deprecated_term_parse(node, out)
|
|
228
|
+
when "fmt-deprecates" then deprecated_term_parse(node, out)
|
|
229
|
+
when "domain" then termdomain_parse(node, out)
|
|
230
|
+
when "definition" then semx_definition_parse(node, out)
|
|
231
|
+
when "fmt-definition" then definition_parse(node, out)
|
|
232
|
+
when "termsource" then semx_termref_parse(node, out)
|
|
233
|
+
when "fmt-termsource" then termref_parse(node, out)
|
|
234
|
+
when "related" then semx_related_parse(node, out)
|
|
222
235
|
when "modification" then modification_parse(node, out)
|
|
223
236
|
when "termnote" then termnote_parse(node, out)
|
|
224
237
|
when "terms" then terms_parse(node, out)
|
|
@@ -237,7 +250,6 @@ module IsoDoc
|
|
|
237
250
|
when "legal-statement" then legal_parse(node, out)
|
|
238
251
|
when "feedback-statement" then feedback_parse(node, out)
|
|
239
252
|
when "passthrough" then passthrough_parse(node, out)
|
|
240
|
-
when "amend" then amend_parse(node, out)
|
|
241
253
|
when "tab" then clausedelimspace(node, out) # in Presentation XML only
|
|
242
254
|
when "svg" then svg_parse(node, out) # in Presentation XML only
|
|
243
255
|
when "add" then add_parse(node, out)
|
|
@@ -249,13 +261,31 @@ module IsoDoc
|
|
|
249
261
|
when "option" then option_parse(node, out)
|
|
250
262
|
when "textarea" then textarea_parse(node, out)
|
|
251
263
|
when "toc" then toc_parse(node, out)
|
|
264
|
+
when "title" then freestanding_title(node, out) # not inside clause
|
|
252
265
|
when "variant-title" then variant_title(node, out)
|
|
253
266
|
when "span" then span_parse(node, out)
|
|
254
267
|
when "location" then location_parse(node, out)
|
|
268
|
+
when "cross-align" then cross_align_parse(node, out)
|
|
255
269
|
when "columnbreak" then columnbreak_parse(node, out)
|
|
270
|
+
when "attribution" then attribution_parse(node, out)
|
|
271
|
+
when "author" then author_parse(node, out)
|
|
256
272
|
when "ruby" then ruby_parse(node, out)
|
|
257
273
|
when "rt" then rt_parse(node, out)
|
|
258
274
|
when "rb" then rb_parse(node, out)
|
|
275
|
+
when "semx" then semx_parse(node, out)
|
|
276
|
+
when "name" then name_parse(node, out)
|
|
277
|
+
when "fmt-xref-label" then xref_label_parse(node, out)
|
|
278
|
+
when "fmt-name" then fmt_name_parse(node, out)
|
|
279
|
+
when "floating-title" then floating_title_parse(node, out)
|
|
280
|
+
when "fmt-identifier" then fmt_identifier_parse(node, out)
|
|
281
|
+
when "identifier" then identifier_parse(node, out)
|
|
282
|
+
when "fmt-concept" then fmt_concept_parse(node, out)
|
|
283
|
+
when "concept" then concept_parse(node, out)
|
|
284
|
+
when "erefstack" then erefstack_parse(node, out)
|
|
285
|
+
when "svgmap" then svgmap_parse(node, out)
|
|
286
|
+
when "amend" then amend_parse(node, out)
|
|
287
|
+
when "date" then date_parse(node, out)
|
|
288
|
+
when "fmt-date" then fmt_date_parse(node, out)
|
|
259
289
|
else error_parse(node, out)
|
|
260
290
|
end
|
|
261
291
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "metanorma-utils"
|
|
2
|
+
require_relative "../../nokogiri/xml/node"
|
|
2
3
|
|
|
3
4
|
module IsoDoc
|
|
4
5
|
module Function
|
|
@@ -23,12 +24,12 @@ module IsoDoc
|
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
def insert_tab(out, count)
|
|
26
|
-
tab = %w(Hans Hant).include?(@script) ? " " : "  "
|
|
27
|
+
tab = %w(Hans Hant Jpan Kore).include?(@script) ? " " : "  "
|
|
27
28
|
[1..count].each { out << tab }
|
|
28
29
|
end
|
|
29
30
|
|
|
30
|
-
def noko(&
|
|
31
|
-
Metanorma::Utils::noko_html(&
|
|
31
|
+
def noko(&)
|
|
32
|
+
Metanorma::Utils::noko_html(&)
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
def attr_code(attributes)
|
|
@@ -40,8 +41,7 @@ module IsoDoc
|
|
|
40
41
|
DOCTYPE_HDR = "<!DOCTYPE html SYSTEM " \
|
|
41
42
|
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'.freeze
|
|
42
43
|
|
|
43
|
-
HUGESTRICT =
|
|
44
|
-
Nokogiri::XML::ParseOptions::HUGE |
|
|
44
|
+
HUGESTRICT = Nokogiri::XML::ParseOptions::HUGE |
|
|
45
45
|
Nokogiri::XML::ParseOptions::STRICT
|
|
46
46
|
|
|
47
47
|
def to_xhtml(xml)
|
|
@@ -62,7 +62,7 @@ module IsoDoc
|
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def to_xhtml_prep(xml)
|
|
65
|
-
xml.gsub!(/<\?xml[
|
|
65
|
+
xml.gsub!(/<\?xml[^<>]*>/, "")
|
|
66
66
|
xml.include?("<!DOCTYPE ") || (xml = DOCTYPE_HDR + xml)
|
|
67
67
|
numeric_escapes(xml)
|
|
68
68
|
end
|
|
@@ -130,8 +130,8 @@ module IsoDoc
|
|
|
130
130
|
|
|
131
131
|
def header_strip(hdr)
|
|
132
132
|
h1 = to_xhtml_fragment(hdr.to_s.gsub(%r{<br\s*/>}, " ")
|
|
133
|
-
.gsub(%r{</?p(\s[
|
|
134
|
-
.gsub(/<\/?h[123456][
|
|
133
|
+
.gsub(%r{</?p(\s[^<>]+)?>}, "")
|
|
134
|
+
.gsub(/<\/?h[123456][^<>]*>/, "").gsub(/<\/?b[^<>]*>/, "").dup)
|
|
135
135
|
h1.traverse do |x|
|
|
136
136
|
if x.name == "span" && x["style"]&.include?("mso-tab-count")
|
|
137
137
|
x.replace(" ")
|
|
@@ -213,10 +213,9 @@ module IsoDoc
|
|
|
213
213
|
%w(example requirement recommendation permission
|
|
214
214
|
note table figure sourcecode).freeze
|
|
215
215
|
|
|
216
|
-
def labelled_ancestor(elem)
|
|
217
|
-
#!elem.path.gsub(/\[\d+\]/, "").split(%r{/})[1..-1]
|
|
216
|
+
def labelled_ancestor(elem, exceptions = [])
|
|
218
217
|
!elem.ancestors.map(&:name)
|
|
219
|
-
.intersection(LABELLED_ANCESTOR_ELEMENTS).empty?
|
|
218
|
+
.intersection(LABELLED_ANCESTOR_ELEMENTS - exceptions).empty?
|
|
220
219
|
end
|
|
221
220
|
|
|
222
221
|
def emf?(type)
|
|
@@ -244,7 +243,7 @@ module IsoDoc
|
|
|
244
243
|
win = !!((RUBY_PLATFORM =~ /(win|w)(32|64)$/) ||
|
|
245
244
|
(RUBY_PLATFORM =~ /mswin|mingw/))
|
|
246
245
|
if win
|
|
247
|
-
path.
|
|
246
|
+
path.tr!(%{/}, "\\")
|
|
248
247
|
path[/\s/] ? "\"#{path}\"" : path
|
|
249
248
|
else path
|
|
250
249
|
end
|
data/lib/isodoc/gem_tasks.rb
CHANGED
|
@@ -24,6 +24,7 @@ module IsoDoc
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
# Move to Presentation XML, as <fmt-footnote>: it's a footnote body
|
|
27
28
|
def make_table_footnote_text(node, fnid, fnref)
|
|
28
29
|
attrs = { id: "fn:#{fnid}" }
|
|
29
30
|
noko do |xml|
|
|
@@ -68,7 +69,7 @@ module IsoDoc
|
|
|
68
69
|
|
|
69
70
|
def footnote_parse(node, out)
|
|
70
71
|
return table_footnote_parse(node, out) if (@in_table || @in_figure) &&
|
|
71
|
-
!node.ancestors.map(&:name).include?("name")
|
|
72
|
+
!node.ancestors.map(&:name).include?("fmt-name")
|
|
72
73
|
|
|
73
74
|
fn = node["reference"] || UUIDTools::UUID.random_create.to_s
|
|
74
75
|
attrs = { class: "FootnoteRef", href: "#fn:#{fn}" }
|
|
@@ -15,10 +15,6 @@ module IsoDoc
|
|
|
15
15
|
end.join("\n")
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def preprocess_xslt(docxml)
|
|
19
|
-
super
|
|
20
|
-
end
|
|
21
|
-
|
|
22
18
|
def make_body1(body, _docxml)
|
|
23
19
|
return if @bare
|
|
24
20
|
|
|
@@ -78,13 +74,15 @@ module IsoDoc
|
|
|
78
74
|
end
|
|
79
75
|
|
|
80
76
|
def sourcecode_parse(node, out)
|
|
81
|
-
name = node.at(ns("./name"))
|
|
77
|
+
name = node.at(ns("./fmt-name"))
|
|
82
78
|
tag = node.at(ns(".//sourcecode | .//table")) ? "div" : "pre"
|
|
79
|
+
n = node.at(ns("./fmt-sourcecode"))
|
|
80
|
+
s = n || node
|
|
83
81
|
attr = sourcecode_attrs(node).merge(class: "sourcecode")
|
|
84
82
|
out.send tag, **attr do |div|
|
|
85
|
-
sourcecode_parse1(
|
|
83
|
+
sourcecode_parse1(s, div)
|
|
86
84
|
end
|
|
87
|
-
annotation_parse(
|
|
85
|
+
annotation_parse(s, out)
|
|
88
86
|
sourcecode_name_parse(node, out, name)
|
|
89
87
|
end
|
|
90
88
|
|
|
@@ -20,15 +20,32 @@ module IsoDoc
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def html5(doc)
|
|
23
|
-
doc.sub(%r{<!DOCTYPE html [
|
|
24
|
-
.sub(%r{<\?xml[
|
|
23
|
+
doc.sub(%r{<!DOCTYPE html [^<>]+>}, "<!DOCTYPE html>")
|
|
24
|
+
.sub(%r{<\?xml[^<>]+>}, "")
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def html_cleanup(html)
|
|
28
28
|
html = term_header(html_footnote_filter(html_preface(htmlstyle(html))))
|
|
29
|
-
html = footnote_format(footnote_backlinks(
|
|
29
|
+
html = footnote_format(footnote_backlinks(html))
|
|
30
30
|
html = mathml(html_list_clean(remove_placeholder_paras(html)))
|
|
31
|
-
sourcecode_cleanup(html)
|
|
31
|
+
html_toc(heading_anchors(sourcecode_cleanup(html)))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def heading_anchors(html)
|
|
35
|
+
html.xpath("//h1 | //h2 | //h3 | //h4 | //h5 | //h6 | //h7 | //h8 "\
|
|
36
|
+
"//span[@class = 'inline-header']").each do |h|
|
|
37
|
+
h.at("./ancestor::div[@id='toc']") and next
|
|
38
|
+
div = h.xpath("./ancestor::div[@id]")
|
|
39
|
+
div.empty? and next
|
|
40
|
+
heading_anchor(h, div[-1]["id"])
|
|
41
|
+
end
|
|
42
|
+
html
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def heading_anchor(hdr, id)
|
|
46
|
+
hdr.children = <<~HTML.strip
|
|
47
|
+
<a class='anchor' href='##{id}'/><a class='header' href='##{id}'>#{hdr.children.to_xml}</a>
|
|
48
|
+
HTML
|
|
32
49
|
end
|
|
33
50
|
|
|
34
51
|
def sourcecode_cleanup(html)
|
|
@@ -52,7 +69,7 @@ module IsoDoc
|
|
|
52
69
|
|
|
53
70
|
def html_list_clean(html)
|
|
54
71
|
html.xpath("//ol/div | //ul/div").each do |div|
|
|
55
|
-
li = div
|
|
72
|
+
li = div.xpath("./preceding-sibling::li")&.last ||
|
|
56
73
|
div.at("./following-sibling::li")
|
|
57
74
|
div.parent = li
|
|
58
75
|
end
|
|
@@ -92,7 +109,6 @@ module IsoDoc
|
|
|
92
109
|
type = img["mimetype"]&.sub(%r{^[^/*]+/}, "")
|
|
93
110
|
matched = /\.(?<suffix>[^. \r\n\t]+)$/.match img["src"]
|
|
94
111
|
type and !type.empty? and return type
|
|
95
|
-
|
|
96
112
|
!matched.nil? and matched[:suffix] and return matched[:suffix]
|
|
97
113
|
"png"
|
|
98
114
|
end
|
|
@@ -111,6 +127,9 @@ module IsoDoc
|
|
|
111
127
|
%w(h1 h2 h3 h4 h5 h6 h7 h8).each do |h|
|
|
112
128
|
docxml.xpath("//p[@class = 'TermNum'][../#{h}]").each do |p|
|
|
113
129
|
p.name = "h#{h[1].to_i + 1}"
|
|
130
|
+
id = p["id"]
|
|
131
|
+
p["id"] = "_#{UUIDTools::UUID.random_create}"
|
|
132
|
+
p.wrap("<div id='#{id}'></div>")
|
|
114
133
|
end
|
|
115
134
|
end
|
|
116
135
|
docxml
|
|
@@ -6,9 +6,9 @@ module IsoDoc
|
|
|
6
6
|
module HtmlFunction
|
|
7
7
|
module Html
|
|
8
8
|
def script_cdata(result)
|
|
9
|
-
result.gsub(%r{<script([
|
|
9
|
+
result.gsub(%r{<script([^<>]*)>\s*<!\[CDATA\[}m, "<script\\1>")
|
|
10
10
|
.gsub(%r{\]\]>\s*</script>}, "</script>")
|
|
11
|
-
.gsub(%r{<!\[CDATA\[\s*<script([
|
|
11
|
+
.gsub(%r{<!\[CDATA\[\s*<script([^<>]*)>}m, "<script\\1>")
|
|
12
12
|
.gsub(%r{</script>\s*\]\]>}, "</script>")
|
|
13
13
|
end
|
|
14
14
|
|
|
@@ -40,8 +40,10 @@ module IsoDoc
|
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def html_preface(docxml)
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
@htmlcoverpage && !@htmlcoverpage.empty? && !@bare and
|
|
44
|
+
html_cover(docxml)
|
|
45
|
+
@htmlintropage && !@htmlintropage.empty? && !@bare and
|
|
46
|
+
html_intro(docxml)
|
|
45
47
|
docxml.at("//body") << mathjax(@openmathdelim, @closemathdelim)
|
|
46
48
|
html_main(docxml)
|
|
47
49
|
authority_cleanup(docxml)
|
|
@@ -80,7 +82,8 @@ module IsoDoc
|
|
|
80
82
|
def html_cover(docxml)
|
|
81
83
|
doc = to_xhtml_fragment(File.read(@htmlcoverpage, encoding: "UTF-8"))
|
|
82
84
|
d = docxml.at('//div[@class="title-section"]')
|
|
83
|
-
d.children.first.add_previous_sibling(
|
|
85
|
+
#d.children.first.add_previous_sibling(
|
|
86
|
+
d.add_first_child(
|
|
84
87
|
populate_template(doc.to_xml(encoding: "US-ASCII"), :html),
|
|
85
88
|
)
|
|
86
89
|
end
|
|
@@ -88,7 +91,8 @@ module IsoDoc
|
|
|
88
91
|
def html_intro(docxml)
|
|
89
92
|
doc = to_xhtml_fragment(File.read(@htmlintropage, encoding: "UTF-8"))
|
|
90
93
|
d = docxml.at('//div[@class="prefatory-section"]')
|
|
91
|
-
d.children.first.add_previous_sibling(
|
|
94
|
+
#d.children.first.add_previous_sibling(
|
|
95
|
+
d.add_first_child(
|
|
92
96
|
populate_template(doc.to_xml(encoding: "US-ASCII"), :html),
|
|
93
97
|
)
|
|
94
98
|
end
|
|
@@ -96,7 +100,9 @@ module IsoDoc
|
|
|
96
100
|
def html_toc_entry(level, header)
|
|
97
101
|
content = header.at("./following-sibling::p" \
|
|
98
102
|
"[@class = 'variant-title-toc']") || header
|
|
99
|
-
|
|
103
|
+
id = header.at(".//a[@class = 'anchor']/@href")&.text&.sub(/^#/, "") ||
|
|
104
|
+
header["id"]
|
|
105
|
+
%(<li class="#{level}"><a href="##{id}">\
|
|
100
106
|
#{header_strip(content)}</a></li>)
|
|
101
107
|
end
|
|
102
108
|
|
|
@@ -1,59 +1,64 @@
|
|
|
1
|
-
module IsoDoc
|
|
2
|
-
module
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
module IsoDoc
|
|
2
|
+
module HtmlFunction
|
|
3
|
+
module Html
|
|
4
|
+
def update_footnote_filter(fnote, xref, idx, seen)
|
|
5
|
+
if seen[fnote.text]
|
|
6
|
+
xref.at("./sup").content = seen[fnote.text][:num].to_s
|
|
7
|
+
fnote.remove unless xref["href"] == seen[fnote.text][:href]
|
|
8
|
+
xref["href"] = seen[fnote.text][:href]
|
|
9
|
+
else
|
|
10
|
+
seen[fnote.text] = { num: idx, href: xref["href"] }
|
|
11
|
+
xref.at("./sup").content = idx.to_s
|
|
12
|
+
idx += 1
|
|
13
|
+
end
|
|
14
|
+
[idx, seen]
|
|
12
15
|
end
|
|
13
|
-
[i, seen]
|
|
14
|
-
end
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
def html_footnote_filter(docxml)
|
|
18
|
+
seen = {}
|
|
19
|
+
i = 1
|
|
20
|
+
docxml.xpath('//a[@class = "FootnoteRef"]').each do |x|
|
|
21
|
+
fn = docxml.at(%<//*[@id = '#{x['href'].sub(/^#/, '')}']>) || next
|
|
22
|
+
i, seen = update_footnote_filter(fn, x, i, seen)
|
|
23
|
+
end
|
|
24
|
+
docxml
|
|
22
25
|
end
|
|
23
|
-
docxml
|
|
24
|
-
end
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
def footnote_backlinks1(xref, footnote)
|
|
28
|
+
xdup = xref.dup
|
|
29
|
+
xdup.remove["id"]
|
|
30
|
+
if footnote.elements.empty?
|
|
31
|
+
#footnote.children.empty? and footnote << " "
|
|
32
|
+
#footnote.children.first.previous = xdup
|
|
33
|
+
footnote.add_first_child xdup
|
|
34
|
+
else
|
|
35
|
+
#footnote.elements.first.children.first.previous = xdup
|
|
36
|
+
footnote.elements.first.add_first_child xdup
|
|
37
|
+
end
|
|
33
38
|
end
|
|
34
|
-
end
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
def footnote_backlinks(docxml)
|
|
41
|
+
seen = {}
|
|
42
|
+
docxml.xpath('//a[@class = "FootnoteRef"]').each_with_index do |x, i|
|
|
43
|
+
(seen[x["href"]] and next) or seen[x["href"]] = true
|
|
44
|
+
fn = docxml.at(%<//*[@id = '#{x['href'].sub(/^#/, '')}']>) || next
|
|
45
|
+
footnote_backlinks1(x, fn)
|
|
46
|
+
x["id"] ||= "fnref:#{i + 1}"
|
|
47
|
+
fn.add_child "<a href='##{x['id']}'>↩</a>"
|
|
48
|
+
end
|
|
49
|
+
docxml
|
|
44
50
|
end
|
|
45
|
-
docxml
|
|
46
|
-
end
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
def footnote_format(docxml)
|
|
53
|
+
docxml.xpath("//a[@class = 'FootnoteRef']/sup").each do |x|
|
|
54
|
+
footnote_reference_format(x)
|
|
55
|
+
end
|
|
56
|
+
docxml.xpath("//a[@class = 'TableFootnoteRef'] | "\
|
|
57
|
+
"//span[@class = 'TableFootnoteRef']").each do |x|
|
|
58
|
+
table_footnote_reference_format(x)
|
|
59
|
+
end
|
|
60
|
+
docxml
|
|
55
61
|
end
|
|
56
|
-
docxml
|
|
57
62
|
end
|
|
58
63
|
end
|
|
59
64
|
end
|
data/lib/isodoc/init.rb
CHANGED
|
@@ -140,5 +140,36 @@ module IsoDoc
|
|
|
140
140
|
def agency?(text)
|
|
141
141
|
self.class::AGENCIES.include?(text)
|
|
142
142
|
end
|
|
143
|
+
|
|
144
|
+
def docid_l10n(text)
|
|
145
|
+
text.nil? and return text
|
|
146
|
+
@i18n.all_parts and text.gsub!(/All Parts/i, @i18n.all_parts.downcase)
|
|
147
|
+
x = Nokogiri::XML::DocumentFragment.parse(text)
|
|
148
|
+
(x.xpath(".//text()") - x.xpath(".//fn//text()")).each do |n|
|
|
149
|
+
n.replace(n.text.gsub(/ /, " "))
|
|
150
|
+
end
|
|
151
|
+
to_xml(x)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def docid_prefix(prefix, docid)
|
|
155
|
+
docid = "#{prefix} #{docid}" if prefix && !omit_docid_prefix(prefix) &&
|
|
156
|
+
!/^#{prefix}\b/.match(docid)
|
|
157
|
+
docid_l10n(docid)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def omit_docid_prefix(prefix)
|
|
161
|
+
prefix.nil? || prefix.empty? and return true
|
|
162
|
+
%w(ISO IEC IEV ITU W3C BIPM csd metanorma repository metanorma-ordinal)
|
|
163
|
+
.include? prefix
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def connectives_spans(text)
|
|
167
|
+
text.gsub("<conn>", "<span class='fmt-conn'>")
|
|
168
|
+
.gsub("</conn>", "</span>")
|
|
169
|
+
.gsub("<enum-comma>", "<span class='fmt-enum-comma'>")
|
|
170
|
+
.gsub("</enum-comma>", "</span>")
|
|
171
|
+
.gsub("<comma>", "<span class='fmt-comma'>")
|
|
172
|
+
.gsub("</comma>", "</span>")
|
|
173
|
+
end
|
|
143
174
|
end
|
|
144
175
|
end
|
data/lib/isodoc/metadata.rb
CHANGED
|
@@ -13,9 +13,18 @@ module IsoDoc
|
|
|
13
13
|
@i18n.l10n(expr, lang, script, locale)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
def connectives_strip(text)
|
|
17
|
+
text.gsub("<conn>", "")
|
|
18
|
+
.gsub("</conn>", "")
|
|
19
|
+
.gsub("<enum-comma>", "")
|
|
20
|
+
.gsub("</enum-comma>", "")
|
|
21
|
+
.gsub("<comma>", "")
|
|
22
|
+
.gsub("</comma>", "")
|
|
23
|
+
end
|
|
24
|
+
|
|
16
25
|
def initialize(lang, script, locale, i18n, fonts_options = {})
|
|
17
|
-
@metadata = { lang
|
|
18
|
-
DATETYPES.each { |w| @metadata["#{w.
|
|
26
|
+
@metadata = { lang:, script: }
|
|
27
|
+
DATETYPES.each { |w| @metadata["#{w.tr('-', '_')}date".to_sym] = "XXX" }
|
|
19
28
|
@lang = lang
|
|
20
29
|
@script = script
|
|
21
30
|
@locale = locale
|
|
@@ -29,10 +38,6 @@ module IsoDoc
|
|
|
29
38
|
@metadata
|
|
30
39
|
end
|
|
31
40
|
|
|
32
|
-
def labels
|
|
33
|
-
@labels
|
|
34
|
-
end
|
|
35
|
-
|
|
36
41
|
def set(key, value)
|
|
37
42
|
@metadata[key] = value
|
|
38
43
|
end
|
|
@@ -44,10 +49,12 @@ module IsoDoc
|
|
|
44
49
|
end
|
|
45
50
|
|
|
46
51
|
def doctype(isoxml, _out)
|
|
47
|
-
b = isoxml
|
|
48
|
-
set(:doctype, status_print(b))
|
|
49
|
-
b1 = isoxml
|
|
50
|
-
set(:doctype_display, status_print(b1))
|
|
52
|
+
b = isoxml.at(ns("//bibdata/ext/doctype#{NOLANG}")) || return
|
|
53
|
+
set(:doctype, status_print(b.text))
|
|
54
|
+
b1 = isoxml.at(ns("//bibdata/ext/doctype#{currlang}")) || b
|
|
55
|
+
set(:doctype_display, status_print(b1.text))
|
|
56
|
+
b = isoxml.at(ns("//bibdata/ext/subdoctype#{NOLANG}")) || return
|
|
57
|
+
set(:subdoctype, status_print(b.text))
|
|
51
58
|
end
|
|
52
59
|
|
|
53
60
|
def docstatus(xml, _out)
|
|
@@ -57,11 +64,11 @@ module IsoDoc
|
|
|
57
64
|
s1 = xml.at(ns("//bibdata/status/stage#{currlang}")) || s
|
|
58
65
|
set(:stage, status_print(s.text))
|
|
59
66
|
s1 and set(:stage_display, status_print(s1.text))
|
|
60
|
-
(i = xml
|
|
67
|
+
(i = xml.at(ns("//bibdata/status/substage#{NOLANG}"))&.text) and
|
|
61
68
|
set(:substage, i)
|
|
62
|
-
(i1 = xml
|
|
69
|
+
(i1 = xml.at(ns("//bibdata/status/substage#{currlang}"))&.text || i) and
|
|
63
70
|
set(:substage_display, i1)
|
|
64
|
-
(i2 = xml
|
|
71
|
+
(i2 = xml.at(ns("//bibdata/status/iteration"))&.text) and
|
|
65
72
|
set(:iteration, i2)
|
|
66
73
|
set(:unpublished, unpublished(s.text))
|
|
67
74
|
unpublished(s.text) && set(:stageabbr, stage_abbr(s.text))
|
|
@@ -67,24 +67,19 @@ module IsoDoc
|
|
|
67
67
|
publisher = []
|
|
68
68
|
xml.xpath(ns("//bibdata/contributor[xmlns:role/@type = 'publisher']/" \
|
|
69
69
|
"organization")).each do |org|
|
|
70
|
-
name =
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
name = org.at(ns("./name[@language = '#{@lang}']")) ||
|
|
71
|
+
org.at(ns("./name"))
|
|
72
|
+
agency1 = org.at(ns("./abbreviation"))&.text || name&.text
|
|
73
|
+
publisher << name.text if name
|
|
73
74
|
agency = iso?(org) ? "ISO/#{agency}" : "#{agency}#{agency1}/"
|
|
74
75
|
end
|
|
75
76
|
[agency, publisher]
|
|
76
77
|
end
|
|
77
78
|
|
|
78
|
-
def extract_variant(node)
|
|
79
|
-
node.nil? and return node
|
|
80
|
-
x = node.at(ns("./variant[@language = '#{@lang}']")) and node = x
|
|
81
|
-
node.text
|
|
82
|
-
end
|
|
83
|
-
|
|
84
79
|
def agency(xml)
|
|
85
80
|
agency, publisher = agency1(xml)
|
|
86
81
|
set(:agency, agency.sub(%r{/$}, ""))
|
|
87
|
-
set(:publisher, @i18n.boolean_conj(publisher, "and"))
|
|
82
|
+
set(:publisher, connectives_strip(@i18n.boolean_conj(publisher, "and")))
|
|
88
83
|
agency_addr(xml)
|
|
89
84
|
end
|
|
90
85
|
|
data/lib/isodoc/metadata_date.rb
CHANGED