isodoc 1.7.4 → 1.7.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/isodoc.gemspec +7 -5
- data/lib/isodoc/class_utils.rb +25 -2
- data/lib/isodoc/convert.rb +2 -0
- data/lib/isodoc/function/to_word_html.rb +2 -1
- data/lib/isodoc/function/utils.rb +34 -14
- data/lib/isodoc/html_function/comments.rb +107 -111
- data/lib/isodoc/html_function/footnotes.rb +68 -67
- data/lib/isodoc/html_function/html.rb +113 -103
- data/lib/isodoc/presentation_function/block.rb +73 -78
- data/lib/isodoc/presentation_function/concept.rb +68 -0
- data/lib/isodoc/presentation_function/image.rb +112 -0
- data/lib/isodoc/presentation_function/inline.rb +20 -49
- data/lib/isodoc/presentation_xml_convert.rb +1 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +176 -174
- data/lib/isodoc/word_function/comments.rb +117 -112
- data/lib/isodoc/word_function/footnotes.rb +88 -86
- data/lib/isodoc/word_function/inline.rb +42 -67
- data/lib/isodoc/word_function/postprocess_cover.rb +121 -110
- data/lib/isodoc/xref/xref_gen.rb +153 -150
- data/lib/isodoc/xref/xref_sect_gen.rb +134 -129
- data/lib/isodoc/xslfo_convert.rb +7 -6
- data/spec/assets/i18n.yaml +3 -1
- data/spec/assets/odf.svg +1 -4
- data/spec/isodoc/blocks_spec.rb +229 -157
- data/spec/isodoc/i18n_spec.rb +3 -3
- data/spec/isodoc/inline_spec.rb +304 -105
- data/spec/isodoc/postproc_spec.rb +38 -0
- data/spec/isodoc/presentation_xml_spec.rb +60 -0
- data/spec/isodoc/section_spec.rb +125 -0
- data/spec/isodoc/terms_spec.rb +116 -0
- data/spec/isodoc/xslfo_convert_spec.rb +16 -4
- metadata +57 -27
@@ -1,160 +1,165 @@
|
|
1
|
-
module IsoDoc
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module IsoDoc
|
2
|
+
module XrefGen
|
3
|
+
module Sections
|
4
|
+
def back_anchor_names(docxml)
|
5
|
+
i = Counter.new("@")
|
6
|
+
docxml.xpath(ns("//annex")).each do |c|
|
7
|
+
i.increment(c)
|
8
|
+
annex_names(c, i.print)
|
9
|
+
end
|
10
|
+
docxml.xpath(ns(@klass.bibliography_xpath)).each do |b|
|
11
|
+
preface_names(b)
|
12
|
+
end
|
13
|
+
docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref|
|
14
|
+
reference_names(ref)
|
15
|
+
end
|
8
16
|
end
|
9
|
-
|
10
|
-
|
17
|
+
|
18
|
+
def initial_anchor_names(doc)
|
19
|
+
doc.xpath(ns("//preface/*")).each do |c|
|
20
|
+
c.element? and preface_names(c)
|
21
|
+
end
|
22
|
+
# potentially overridden in middle_section_asset_names()
|
23
|
+
sequential_asset_names(doc.xpath(ns("//preface/*")))
|
24
|
+
n = Counter.new
|
25
|
+
n = section_names(doc.at(ns("//clause[@type = 'scope']")), n, 1)
|
26
|
+
n = section_names(doc.at(ns(@klass.norm_ref_xpath)), n, 1)
|
27
|
+
n = section_names(doc.at(ns("//sections/terms | "\
|
28
|
+
"//sections/clause[descendant::terms]")), n, 1)
|
29
|
+
n = section_names(doc.at(ns("//sections/definitions")), n, 1)
|
30
|
+
clause_names(doc, n)
|
31
|
+
middle_section_asset_names(doc)
|
32
|
+
termnote_anchor_names(doc)
|
33
|
+
termexample_anchor_names(doc)
|
11
34
|
end
|
12
|
-
|
13
|
-
|
35
|
+
|
36
|
+
def preface_clause_name(clause)
|
37
|
+
clause.at(ns("./title"))&.text || clause.name.capitalize
|
14
38
|
end
|
15
|
-
end
|
16
39
|
|
17
|
-
|
18
|
-
|
19
|
-
# potentially overridden in middle_section_asset_names()
|
20
|
-
sequential_asset_names(doc.xpath(ns("//preface/*")))
|
21
|
-
n = Counter.new
|
22
|
-
n = section_names(doc.at(ns("//clause[@type = 'scope']")), n, 1)
|
23
|
-
n = section_names(doc.at(ns(@klass.norm_ref_xpath)), n, 1)
|
24
|
-
n = section_names(doc.at(ns("//sections/terms | "\
|
25
|
-
"//sections/clause[descendant::terms]")), n, 1)
|
26
|
-
n = section_names(doc.at(ns("//sections/definitions")), n, 1)
|
27
|
-
clause_names(doc, n)
|
28
|
-
middle_section_asset_names(doc)
|
29
|
-
termnote_anchor_names(doc)
|
30
|
-
termexample_anchor_names(doc)
|
31
|
-
end
|
40
|
+
SUBCLAUSES =
|
41
|
+
"./clause | ./references | ./term | ./terms | ./definitions".freeze
|
32
42
|
|
33
|
-
|
34
|
-
clause
|
35
|
-
|
43
|
+
# in StanDoc, prefaces have no numbering; they are referenced only by title
|
44
|
+
def preface_names(clause)
|
45
|
+
return if clause.nil?
|
36
46
|
|
37
|
-
|
38
|
-
|
47
|
+
@anchors[clause["id"]] =
|
48
|
+
{ label: nil, level: 1, xref: preface_clause_name(clause),
|
49
|
+
type: "clause" }
|
50
|
+
clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i|
|
51
|
+
preface_names1(c, c.at(ns("./title"))&.text,
|
52
|
+
"#{preface_clause_name(clause)}, #{i + 1}", 2)
|
53
|
+
end
|
54
|
+
end
|
39
55
|
|
40
|
-
|
41
|
-
|
42
|
-
|
56
|
+
def preface_names1(clause, title, parent_title, level)
|
57
|
+
label = title || parent_title
|
58
|
+
@anchors[clause["id"]] =
|
59
|
+
{ label: nil, level: level, xref: label, type: "clause" }
|
60
|
+
clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i|
|
61
|
+
preface_names1(c, c.at(ns("./title"))&.text, "#{label} #{i + 1}",
|
62
|
+
level + 1)
|
63
|
+
end
|
64
|
+
end
|
43
65
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
66
|
+
def middle_section_asset_names(doc)
|
67
|
+
middle_sections = "//clause[@type = 'scope'] | "\
|
68
|
+
"#{@klass.norm_ref_xpath} | "\
|
69
|
+
"//sections/terms | //preface/* | "\
|
70
|
+
"//sections/definitions | //clause[parent::sections]"
|
71
|
+
sequential_asset_names(doc.xpath(ns(middle_sections)))
|
50
72
|
end
|
51
|
-
end
|
52
73
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i|
|
58
|
-
preface_names1(c, c.at(ns("./title"))&.text, "#{label} #{i + 1}",
|
59
|
-
level + 1)
|
74
|
+
def clause_names(docxml, num)
|
75
|
+
docxml.xpath(ns(@klass.middle_clause(docxml))).each_with_index do |c, _i|
|
76
|
+
section_names(c, num, 1)
|
77
|
+
end
|
60
78
|
end
|
61
|
-
end
|
62
79
|
|
63
|
-
|
64
|
-
|
65
|
-
"#{@klass.norm_ref_xpath} | "\
|
66
|
-
"//sections/terms | //preface/* | "\
|
67
|
-
"//sections/definitions | //clause[parent::sections]"
|
68
|
-
sequential_asset_names(doc.xpath(ns(middle_sections)))
|
69
|
-
end
|
80
|
+
def section_names(clause, num, lvl)
|
81
|
+
return num if clause.nil?
|
70
82
|
|
71
|
-
|
72
|
-
|
73
|
-
|
83
|
+
num.increment(clause)
|
84
|
+
@anchors[clause["id"]] =
|
85
|
+
{ label: num.print, xref: l10n("#{@labels['clause']} #{num.print}"),
|
86
|
+
level: lvl, type: "clause" }
|
87
|
+
i = Counter.new
|
88
|
+
clause.xpath(ns(SUBCLAUSES)).each do |c|
|
89
|
+
i.increment(c)
|
90
|
+
section_names1(c, "#{num.print}.#{i.print}", lvl + 1)
|
91
|
+
end
|
92
|
+
num
|
74
93
|
end
|
75
|
-
end
|
76
94
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
i.increment(c)
|
87
|
-
section_names1(c, "#{num.print}.#{i.print}", lvl + 1)
|
95
|
+
def section_names1(clause, num, level)
|
96
|
+
@anchors[clause["id"]] =
|
97
|
+
{ label: num, level: level, xref: l10n("#{@labels['clause']} #{num}"),
|
98
|
+
type: "clause" }
|
99
|
+
i = Counter.new
|
100
|
+
clause.xpath(ns(SUBCLAUSES)).each do |c|
|
101
|
+
i.increment(c)
|
102
|
+
section_names1(c, "#{num}.#{i.print}", level + 1)
|
103
|
+
end
|
88
104
|
end
|
89
|
-
num
|
90
|
-
end
|
91
105
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
i.increment(c)
|
99
|
-
section_names1(c, "#{num}.#{i.print}", level + 1)
|
106
|
+
def annex_name_lbl(clause, num)
|
107
|
+
obl = l10n("(#{@labels['inform_annex']})")
|
108
|
+
clause["obligation"] == "normative" and
|
109
|
+
obl = l10n("(#{@labels['norm_annex']})")
|
110
|
+
title = Common::case_with_markup(@labels["annex"], "capital", @script)
|
111
|
+
l10n("<strong>#{title} #{num}</strong><br/>#{obl}")
|
100
112
|
end
|
101
|
-
end
|
102
113
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
114
|
+
def single_annex_special_section(clause)
|
115
|
+
a = clause.xpath(ns("./references | ./terms | ./definitions"))
|
116
|
+
a.size == 1 or return nil
|
117
|
+
clause.xpath(ns("./clause | ./p | ./table | ./ol | ./ul | ./dl | "\
|
118
|
+
"./note | ./admonition | ./figure")).empty? or
|
119
|
+
return nil
|
120
|
+
a[0]
|
121
|
+
end
|
109
122
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
123
|
+
def annex_names(clause, num)
|
124
|
+
@anchors[clause["id"]] = { label: annex_name_lbl(clause, num),
|
125
|
+
type: "clause", value: num.to_s, level: 1,
|
126
|
+
xref: "#{@labels['annex']} #{num}" }
|
127
|
+
if a = single_annex_special_section(clause)
|
128
|
+
annex_names1(a, num.to_s, 1)
|
129
|
+
else
|
130
|
+
i = Counter.new
|
131
|
+
clause.xpath(ns(SUBCLAUSES)).each do |c|
|
132
|
+
i.increment(c)
|
133
|
+
annex_names1(c, "#{num}.#{i.print}", 2)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
hierarchical_asset_names(clause, num)
|
137
|
+
end
|
118
138
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
xref: "#{@labels['annex']} #{num}", level: 1 }
|
123
|
-
if a = single_annex_special_section(clause)
|
124
|
-
annex_names1(a, num.to_s, 1)
|
125
|
-
else
|
139
|
+
def annex_names1(clause, num, level)
|
140
|
+
@anchors[clause["id"]] = { xref: "#{@labels['annex']} #{num}",
|
141
|
+
label: num, level: level, type: "clause" }
|
126
142
|
i = Counter.new
|
127
143
|
clause.xpath(ns(SUBCLAUSES)).each do |c|
|
128
144
|
i.increment(c)
|
129
|
-
annex_names1(c, "#{num}.#{i.print}",
|
145
|
+
annex_names1(c, "#{num}.#{i.print}", level + 1)
|
130
146
|
end
|
131
147
|
end
|
132
|
-
hierarchical_asset_names(clause, num)
|
133
|
-
end
|
134
148
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
149
|
+
ISO_PUBLISHER_XPATH =
|
150
|
+
"./contributor[xmlns:role/@type = 'publisher']/"\
|
151
|
+
"organization[abbreviation = 'ISO' or xmlns:abbreviation = 'IEC' or "\
|
152
|
+
"xmlns:name = 'International Organization for Standardization' or "\
|
153
|
+
"xmlns:name = 'International Electrotechnical Commission']".freeze
|
154
|
+
|
155
|
+
def reference_names(ref)
|
156
|
+
# isopub = ref.at(ns(ISO_PUBLISHER_XPATH))
|
157
|
+
ids = @klass.bibitem_ref_code(ref)
|
158
|
+
identifiers = @klass.render_identifier(ids)
|
159
|
+
# date = ref.at(ns("./date[@type = 'published']"))
|
160
|
+
reference = @klass.docid_l10n(identifiers[0] || identifiers[1])
|
161
|
+
@anchors[ref["id"]] = { xref: reference }
|
142
162
|
end
|
143
163
|
end
|
144
|
-
|
145
|
-
ISO_PUBLISHER_XPATH =
|
146
|
-
"./contributor[xmlns:role/@type = 'publisher']/"\
|
147
|
-
"organization[abbreviation = 'ISO' or xmlns:abbreviation = 'IEC' or "\
|
148
|
-
"xmlns:name = 'International Organization for Standardization' or "\
|
149
|
-
"xmlns:name = 'International Electrotechnical Commission']".freeze
|
150
|
-
|
151
|
-
def reference_names(ref)
|
152
|
-
# isopub = ref.at(ns(ISO_PUBLISHER_XPATH))
|
153
|
-
ids = @klass.bibitem_ref_code(ref)
|
154
|
-
identifiers = @klass.render_identifier(ids)
|
155
|
-
# date = ref.at(ns("./date[@type = 'published']"))
|
156
|
-
reference = @klass.docid_l10n(identifiers[0] || identifiers[1])
|
157
|
-
@anchors[ref["id"]] = { xref: reference }
|
158
|
-
end
|
159
164
|
end
|
160
165
|
end
|
data/lib/isodoc/xslfo_convert.rb
CHANGED
@@ -20,12 +20,13 @@ module IsoDoc
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def pdf_options(_docxml)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
ret = ""
|
24
|
+
font_manifest_file = @options.dig(MN2PDF_OPTIONS,
|
25
|
+
MN2PDF_FONT_MANIFEST) and
|
26
|
+
ret += " --font-manifest #{font_manifest_file}"
|
27
|
+
@aligncrosselements && !@aligncrosselements.empty? and
|
28
|
+
ret += %( --param align-cross-elements = "#{@aligncrosselements.gsub(/,/, ' ')}")
|
29
|
+
ret
|
29
30
|
end
|
30
31
|
|
31
32
|
def convert(input_filename, file = nil, debug = false,
|
data/spec/assets/i18n.yaml
CHANGED
@@ -6,12 +6,14 @@ source: SOURCE
|
|
6
6
|
modified: modified
|
7
7
|
scope: Amplekso
|
8
8
|
symbols: Simboloj kai mallongigitaj terminoj
|
9
|
-
annex:
|
9
|
+
annex: <strong>aldono</strong>
|
10
10
|
normref: Normaj citaĵoj
|
11
11
|
bibliography: Bibliografio
|
12
12
|
inform_annex: informa
|
13
13
|
all_parts: ĉiuj partoj
|
14
14
|
norm_annex: normative
|
15
|
+
figure: figur-etikedo duvorta
|
16
|
+
example: Ekzempl-etikedo Duvorta
|
15
17
|
note: NOTO
|
16
18
|
locality: {
|
17
19
|
table: Tabelo
|
data/spec/assets/odf.svg
CHANGED
@@ -1,4 +1 @@
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
|
2
|
-
<circle fill="#009" r="45" cx="50" cy="50"/>
|
3
|
-
<path d="M33,26H78A37,37,0,0,1,33,83V57H59V43H33Z" fill="#FFF"/>
|
4
|
-
</svg>
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle fill="#009" r="45" cx="50" cy="50"/><path d="M33,26H78A37,37,0,0,1,33,83V57H59V43H33Z" fill="#FFF"/></svg>
|