isodoc 2.5.10 → 2.6.0
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/convert.rb +4 -2
- data/lib/isodoc/function/blocks.rb +1 -4
- data/lib/isodoc/function/blocks_example_note.rb +1 -7
- data/lib/isodoc/function/inline.rb +2 -2
- data/lib/isodoc/function/references.rb +13 -15
- data/lib/isodoc/function/section.rb +35 -63
- data/lib/isodoc/function/section_titles.rb +0 -14
- data/lib/isodoc/function/to_word_html.rb +44 -21
- data/lib/isodoc/function/utils.rb +1 -0
- data/lib/isodoc/html_function/footnotes.rb +2 -2
- data/lib/isodoc/html_function/html.rb +0 -10
- data/lib/isodoc/init.rb +3 -3
- data/lib/isodoc/presentation_function/erefs.rb +2 -2
- data/lib/isodoc/presentation_function/image.rb +22 -10
- data/lib/isodoc/presentation_function/refs.rb +16 -3
- data/lib/isodoc/presentation_function/section.rb +28 -6
- data/lib/isodoc/presentation_function/terms.rb +7 -0
- data/lib/isodoc/presentation_function/xrefs.rb +4 -4
- data/lib/isodoc/presentation_xml_convert.rb +3 -1
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +15 -6
- data/lib/isodoc/word_function/inline.rb +3 -3
- data/lib/isodoc/word_function/postprocess.rb +20 -4
- data/lib/isodoc/xref/xref_gen.rb +5 -5
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14b2734abde4e3ab09b2a0637134ff9346bf2e378cebd580d154ae3799461c92
|
4
|
+
data.tar.gz: 3a1594d3c372cced922b30641dcdda21b1b2c95f8a921bd2d309eb7218952d35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5638291318ca9a1eaa7c626b031afa8116dfb933cb6c8e408904126c367852b3e298735629c356e1d6192b49eec3c5fd8e94f39f5219d486b5aab9832158f43f
|
7
|
+
data.tar.gz: 52320e6fd84d57978a2c803417cfccfedf13e63b3b83c5bcbc73d69f2234a231ff35709b6bcd57dcbd9a622efda6c74c8fae50d132704fe8a655f71e996d2c71
|
data/isodoc.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
end
|
29
29
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
30
30
|
|
31
|
-
spec.add_dependency "html2doc", "~> 1.
|
31
|
+
spec.add_dependency "html2doc", "~> 1.6.0"
|
32
32
|
spec.add_dependency "htmlentities", "~> 4.3.4"
|
33
33
|
# spec.add_dependency "isodoc-i18n", "~> 1.1.0" # already in relaton-render and mn-requirements
|
34
34
|
spec.add_dependency "emf2svg"
|
data/lib/isodoc/convert.rb
CHANGED
@@ -113,6 +113,8 @@ module IsoDoc
|
|
113
113
|
docxml = Nokogiri::XSLT(x).transform(docxml)
|
114
114
|
end
|
115
115
|
docxml
|
116
|
+
rescue
|
117
|
+
require "debug"; binding.b
|
116
118
|
end
|
117
119
|
|
118
120
|
def extract_preprocess_xslt(docxml)
|
@@ -156,11 +158,11 @@ module IsoDoc
|
|
156
158
|
|
157
159
|
def middle_clause(_docxml = nil)
|
158
160
|
"//clause[parent::sections][not(@type = 'scope')]" \
|
159
|
-
"[not(descendant::terms)]"
|
161
|
+
"[not(descendant::terms)][not(descendant::references)]"
|
160
162
|
end
|
161
163
|
|
162
164
|
def target_pdf(node)
|
163
|
-
if
|
165
|
+
if node["target"].include?("#") then node["target"].sub("#", ".pdf#")
|
164
166
|
else "##{node['target']}"
|
165
167
|
end
|
166
168
|
end
|
@@ -5,10 +5,6 @@ module IsoDoc
|
|
5
5
|
module Blocks
|
6
6
|
@annotation = false
|
7
7
|
|
8
|
-
def middle_title(_isoxml, out)
|
9
|
-
out.p(class: "zzSTDTitle1") { |p| p << @meta.get[:doctitle] }
|
10
|
-
end
|
11
|
-
|
12
8
|
def figure_name_parse(_node, div, name)
|
13
9
|
name.nil? and return
|
14
10
|
div.p class: "FigureTitle", style: "text-align:center;" do |p|
|
@@ -140,6 +136,7 @@ module IsoDoc
|
|
140
136
|
if node["type"] == "floating-title"
|
141
137
|
classtype = "h#{node['depth']}"
|
142
138
|
end
|
139
|
+
classtype ||= node["class"]
|
143
140
|
classtype
|
144
141
|
end
|
145
142
|
|
@@ -71,7 +71,7 @@ module IsoDoc
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def note_parse1(node, div)
|
74
|
-
name = node
|
74
|
+
name = node.at(ns("./name"))&.remove
|
75
75
|
name and div.p do |p|
|
76
76
|
p.span class: "note_label" do |s|
|
77
77
|
name.children.each { |n| parse(n, s) }
|
@@ -110,12 +110,6 @@ module IsoDoc
|
|
110
110
|
@note = false
|
111
111
|
end
|
112
112
|
|
113
|
-
def middle_admonitions(isoxml, out)
|
114
|
-
isoxml.xpath(ns("//sections/note | //sections/admonition")).each do |x|
|
115
|
-
parse(x, out)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
113
|
def admonition_name_parse(_node, div, name)
|
120
114
|
div.p class: "AdmonitionTitle", style: "text-align:center;" do |p|
|
121
115
|
name.children.each { |n| parse(n, p) }
|
@@ -38,7 +38,7 @@ module IsoDoc
|
|
38
38
|
|
39
39
|
def xref_parse(node, out)
|
40
40
|
target = if /#/.match?(node["target"])
|
41
|
-
node["target"].sub(
|
41
|
+
node["target"].sub("#", ".html#")
|
42
42
|
else
|
43
43
|
"##{node['target']}"
|
44
44
|
end
|
@@ -150,7 +150,7 @@ module IsoDoc
|
|
150
150
|
end
|
151
151
|
|
152
152
|
def error_parse(node, out)
|
153
|
-
text = node.to_xml.gsub(
|
153
|
+
text = node.to_xml.gsub("<", "<").gsub(">", ">")
|
154
154
|
out.para do |p|
|
155
155
|
p.b(role: "strong") { |e| e << text }
|
156
156
|
end
|
@@ -145,21 +145,20 @@ module IsoDoc
|
|
145
145
|
|
146
146
|
def norm_ref_xpath
|
147
147
|
"//bibliography/references[@normative = 'true'] | " \
|
148
|
-
"//bibliography/clause[.//references[@normative = 'true']]"
|
148
|
+
"//bibliography/clause[.//references[@normative = 'true']] | " \
|
149
|
+
"//sections/references[@normative = 'true'] | " \
|
150
|
+
"//sections/clause[.//references[@normative = 'true']]"
|
149
151
|
end
|
150
152
|
|
151
|
-
def norm_ref(
|
152
|
-
|
153
|
-
return num
|
153
|
+
def norm_ref(node, out)
|
154
|
+
node["hidden"] != "true" or return
|
154
155
|
out.div do |div|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
else biblio_list(f, div, false)
|
156
|
+
clause_name(node, node.at(ns("./title")), div, nil)
|
157
|
+
if node.name == "clause"
|
158
|
+
node.elements.each { |e| parse(e, div) unless e.name == "title" }
|
159
|
+
else biblio_list(node, div, false)
|
160
160
|
end
|
161
161
|
end
|
162
|
-
num
|
163
162
|
end
|
164
163
|
|
165
164
|
def bibliography_xpath
|
@@ -168,15 +167,14 @@ module IsoDoc
|
|
168
167
|
"//bibliography/references[@normative = 'false']"
|
169
168
|
end
|
170
169
|
|
171
|
-
def bibliography(
|
172
|
-
|
173
|
-
return
|
170
|
+
def bibliography(node, out)
|
171
|
+
node["hidden"] != "true" or return
|
174
172
|
page_break(out)
|
175
173
|
out.div do |div|
|
176
174
|
div.h1 class: "Section3" do |h1|
|
177
|
-
|
175
|
+
node.at(ns("./title"))&.children&.each { |c2| parse(c2, h1) }
|
178
176
|
end
|
179
|
-
biblio_list(
|
177
|
+
biblio_list(node, div, true)
|
180
178
|
end
|
181
179
|
end
|
182
180
|
|
@@ -17,13 +17,11 @@ module IsoDoc
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def clause(
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
parse(c1, s)
|
26
|
-
end
|
20
|
+
def clause(node, out)
|
21
|
+
out.div **attr_code(clause_attrs(node)) do |s|
|
22
|
+
clause_name(node, node.at(ns("./title")), s, nil)
|
23
|
+
node.elements.reject { |c1| c1.name == "title" }.each do |c1|
|
24
|
+
parse(c1, s)
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
@@ -32,44 +30,40 @@ module IsoDoc
|
|
32
30
|
{ id: node["id"], class: "Section3" }
|
33
31
|
end
|
34
32
|
|
35
|
-
def annex(
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
else parse(c1, s)
|
42
|
-
end
|
33
|
+
def annex(node, out)
|
34
|
+
page_break(out)
|
35
|
+
out.div **attr_code(annex_attrs(node)) do |s|
|
36
|
+
node.elements.each do |c1|
|
37
|
+
if c1.name == "title" then annex_name(node, c1, s)
|
38
|
+
else parse(c1, s)
|
43
39
|
end
|
44
40
|
end
|
45
41
|
end
|
46
42
|
end
|
47
43
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
44
|
+
def indexsect(node, out)
|
45
|
+
clause_parse(node, out)
|
46
|
+
end
|
47
|
+
|
48
|
+
def scope(node, out)
|
49
|
+
out.div **attr_code(id: node["id"]) do |div|
|
50
|
+
clause_name(node, node.at(ns("./title")), div, nil)
|
51
|
+
node.elements.each do |e|
|
54
52
|
parse(e, div) unless e.name == "title"
|
55
53
|
end
|
56
54
|
end
|
57
|
-
num
|
58
55
|
end
|
59
56
|
|
60
57
|
TERM_CLAUSE = "//sections/terms | " \
|
61
58
|
"//sections/clause[descendant::terms]".freeze
|
62
59
|
|
63
|
-
def terms_defs(
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
clause_name(f, f.at(ns("./title")), div, nil)
|
68
|
-
f.elements.each do |e|
|
60
|
+
def terms_defs(node, out)
|
61
|
+
out.div **attr_code(id: node["id"]) do |div|
|
62
|
+
clause_name(node, node.at(ns("./title")), div, nil)
|
63
|
+
node.elements.each do |e|
|
69
64
|
parse(e, div) unless %w{title source}.include? e.name
|
70
65
|
end
|
71
66
|
end
|
72
|
-
num
|
73
67
|
end
|
74
68
|
|
75
69
|
# subclause
|
@@ -77,16 +71,13 @@ module IsoDoc
|
|
77
71
|
clause_parse(isoxml, out)
|
78
72
|
end
|
79
73
|
|
80
|
-
def symbols_abbrevs(
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
clause_name(f, f.at(ns("./title")), div, nil)
|
85
|
-
f.elements.each do |e|
|
74
|
+
def symbols_abbrevs(node, out)
|
75
|
+
out.div **attr_code(id: node["id"], class: "Symbols") do |div|
|
76
|
+
clause_name(node, node.at(ns("./title")), div, nil)
|
77
|
+
node.elements.each do |e|
|
86
78
|
parse(e, div) unless e.name == "title"
|
87
79
|
end
|
88
80
|
end
|
89
|
-
num
|
90
81
|
end
|
91
82
|
|
92
83
|
# subclause
|
@@ -171,15 +162,14 @@ module IsoDoc
|
|
171
162
|
end
|
172
163
|
end
|
173
164
|
|
174
|
-
def colophon(
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
end
|
165
|
+
def colophon(node, out)
|
166
|
+
@seen_colophon or page_break(out)
|
167
|
+
@seen_colophon = true
|
168
|
+
out.div class: "Section3", id: node["id"] do |div|
|
169
|
+
clause_name(node, node.at(ns("./title")), div,
|
170
|
+
{ class: "IntroTitle" })
|
171
|
+
node.elements.each do |e|
|
172
|
+
parse(e, div) unless e.name == "title"
|
183
173
|
end
|
184
174
|
end
|
185
175
|
end
|
@@ -194,24 +184,6 @@ module IsoDoc
|
|
194
184
|
t.size == 1 && %w(terms definitions references).include?(t[0].name)
|
195
185
|
end
|
196
186
|
|
197
|
-
def front(isoxml, out)
|
198
|
-
p = isoxml.at(ns("//preface")) or return
|
199
|
-
p.elements.each do |e|
|
200
|
-
if is_clause?(e.name)
|
201
|
-
case e.name
|
202
|
-
when "abstract" then abstract e, out
|
203
|
-
when "foreword" then foreword e, out
|
204
|
-
when "introduction" then introduction e, out
|
205
|
-
when "executivesummary" then executivesummary e, out
|
206
|
-
when "clause" then preface e, out
|
207
|
-
when "acknowledgements" then acknowledgements e, out
|
208
|
-
end
|
209
|
-
else
|
210
|
-
preface_block(e, out)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
187
|
def executivesummary(clause, out)
|
216
188
|
introduction clause, out
|
217
189
|
end
|
@@ -56,7 +56,6 @@ module IsoDoc
|
|
56
56
|
|
57
57
|
# top level clause names
|
58
58
|
def clause_name(node, title, div, header_class)
|
59
|
-
preceding_floating_titles(node, div)
|
60
59
|
header_class = {} if header_class.nil?
|
61
60
|
div.h1 **attr_code(header_class) do |h1|
|
62
61
|
if title.is_a?(String) then h1 << title
|
@@ -69,7 +68,6 @@ module IsoDoc
|
|
69
68
|
end
|
70
69
|
|
71
70
|
def annex_name(_annex, name, div)
|
72
|
-
preceding_floating_titles(name, div)
|
73
71
|
return if name.nil?
|
74
72
|
|
75
73
|
div.h1 class: "Annex" do |t|
|
@@ -84,18 +82,6 @@ module IsoDoc
|
|
84
82
|
node.children.each { |c| parse(c, p) }
|
85
83
|
end
|
86
84
|
end
|
87
|
-
|
88
|
-
def preceding_floating_titles(node, div)
|
89
|
-
return if node.nil?
|
90
|
-
|
91
|
-
out = node.xpath("./preceding-sibling::*")
|
92
|
-
.reverse.each_with_object([]) do |p, m|
|
93
|
-
break m unless p.name == "p"
|
94
|
-
|
95
|
-
m << p
|
96
|
-
end or return
|
97
|
-
out.each { |c| parse(c, div) }
|
98
|
-
end
|
99
85
|
end
|
100
86
|
end
|
101
87
|
end
|
@@ -82,20 +82,57 @@ module IsoDoc
|
|
82
82
|
section_break(body)
|
83
83
|
end
|
84
84
|
|
85
|
+
TOP_ELEMENTS =
|
86
|
+
"//preface/*[@displayorder] | //sections/*[@displayorder] | " \
|
87
|
+
"//annex[@displayorder] | //bibliography/*[@displayorder] | " \
|
88
|
+
"//colophon/*[@displayorder] | //indexsect[@displayorder]"
|
89
|
+
.freeze
|
90
|
+
|
85
91
|
def make_body3(body, docxml)
|
86
92
|
body.div class: "main-section" do |div3|
|
87
93
|
boilerplate docxml, div3
|
88
|
-
|
89
|
-
abstract docxml, div3
|
90
|
-
foreword docxml, div3
|
91
|
-
introduction docxml, div3
|
92
|
-
acknowledgements docxml, div3
|
93
|
-
middle docxml, div3
|
94
|
+
content(div3, docxml, ns(self.class::TOP_ELEMENTS))
|
94
95
|
footnotes div3
|
95
96
|
comments div3
|
96
97
|
end
|
97
98
|
end
|
98
99
|
|
100
|
+
# xpath presumed to list elements with displayorder attribute
|
101
|
+
def content(body, docxml, xpath)
|
102
|
+
docxml.xpath(xpath).sort_by { |c| c["displayorder"].to_i }
|
103
|
+
.each do |c|
|
104
|
+
top_element_render(c, body)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def top_element_render(e, out)
|
109
|
+
case e.name
|
110
|
+
when "abstract" then abstract e, out
|
111
|
+
when "foreword" then foreword e, out
|
112
|
+
when "introduction" then introduction e, out
|
113
|
+
when "executivesummary" then executivesummary e, out
|
114
|
+
when "acknowledgements" then acknowledgements e, out
|
115
|
+
when "annex" then annex e, out
|
116
|
+
when "definitions" then symbols_abbrevs e, out
|
117
|
+
when "indexsect" then indexsect e, out
|
118
|
+
when "references"
|
119
|
+
if e["normative"] == "true" then norm_ref e, out
|
120
|
+
else bibliography e, out
|
121
|
+
end
|
122
|
+
when "clause"
|
123
|
+
if e.parent.name == "preface" then preface e, out
|
124
|
+
elsif e.parent.name == "colophon" then colophon e, out
|
125
|
+
elsif e["type"] == "scope" then scope e, out
|
126
|
+
elsif e.at(ns(".//terms")) then terms_defs e, out
|
127
|
+
elsif e.at(ns(".//references[@normative = 'true']"))
|
128
|
+
norm_ref e, out
|
129
|
+
elsif e.at(ns(".//references")) then bibliography e, out
|
130
|
+
else clause e, out
|
131
|
+
end
|
132
|
+
else parse(e, out)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
99
136
|
def info(isoxml, out)
|
100
137
|
@meta.code_css isoxml, out
|
101
138
|
@meta.title isoxml, out
|
@@ -116,22 +153,8 @@ module IsoDoc
|
|
116
153
|
@meta.get
|
117
154
|
end
|
118
155
|
|
119
|
-
def middle(isoxml, out)
|
120
|
-
middle_title(isoxml, out)
|
121
|
-
middle_admonitions(isoxml, out)
|
122
|
-
scope isoxml, out, 0
|
123
|
-
norm_ref isoxml, out, 0
|
124
|
-
terms_defs isoxml, out, 0
|
125
|
-
symbols_abbrevs isoxml, out, 0
|
126
|
-
clause isoxml, out
|
127
|
-
annex isoxml, out
|
128
|
-
bibliography isoxml, out
|
129
|
-
colophon isoxml, out
|
130
|
-
end
|
131
|
-
|
132
156
|
def boilerplate(node, out)
|
133
|
-
|
134
|
-
|
157
|
+
@bare and return
|
135
158
|
boilerplate = node.at(ns("//boilerplate")) or return
|
136
159
|
out.div class: "authority" do |s|
|
137
160
|
boilerplate.children.each do |n|
|
@@ -176,6 +176,7 @@ module IsoDoc
|
|
176
176
|
imgtype = "emf" if emf?("#{imgclass}/#{imgtype}")
|
177
177
|
imgtype = imgtype.sub(/\+[a-z0-9]+$/, "") # svg+xml
|
178
178
|
imgtype = "png" unless /^[a-z0-9]+$/.match? imgtype
|
179
|
+
imgtype == "postscript" and imgtype = "eps"
|
179
180
|
Tempfile.open(["image", ".#{imgtype}"]) do |f|
|
180
181
|
f.binmode
|
181
182
|
f.write(Base64.strict_decode64(imgdata))
|
@@ -36,7 +36,7 @@ module IsoDoc
|
|
36
36
|
|
37
37
|
def make_generic_footnote_text(node, fnid)
|
38
38
|
noko do |xml|
|
39
|
-
xml.aside
|
39
|
+
xml.aside id: "fn:#{fnid}", class: "footnote" do |div|
|
40
40
|
node.children.each { |n| parse(n, div) }
|
41
41
|
end
|
42
42
|
end.join("\n")
|
@@ -59,7 +59,7 @@ module IsoDoc
|
|
59
59
|
return if @seen_footnote.include?(tid + fn)
|
60
60
|
|
61
61
|
@in_footnote = true
|
62
|
-
out.aside
|
62
|
+
out.aside class: "footnote" do |a|
|
63
63
|
a << make_table_footnote_text(node, tid + fn, fn)
|
64
64
|
end
|
65
65
|
@in_footnote = false
|
@@ -33,16 +33,6 @@ module IsoDoc
|
|
33
33
|
section_break(body)
|
34
34
|
end
|
35
35
|
|
36
|
-
def make_body3(body, docxml)
|
37
|
-
body.div class: "main-section" do |div3|
|
38
|
-
boilerplate docxml, div3
|
39
|
-
front docxml, div3
|
40
|
-
middle docxml, div3
|
41
|
-
footnotes div3
|
42
|
-
comments div3
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
36
|
def googlefonts
|
47
37
|
<<~HEAD.freeze
|
48
38
|
<link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet"/>
|
data/lib/isodoc/init.rb
CHANGED
@@ -21,9 +21,9 @@ module IsoDoc
|
|
21
21
|
def toc_init(docxml)
|
22
22
|
x = "//metanorma-extension/presentation-metadata" \
|
23
23
|
"[name[text() = 'TOC Heading Levels']]/value"
|
24
|
-
n = docxml.at(ns(x.sub(
|
24
|
+
n = docxml.at(ns(x.sub("TOC", "DOC TOC"))) and
|
25
25
|
@wordToClevels = n.text.to_i
|
26
|
-
n = docxml.at(ns(x.sub(
|
26
|
+
n = docxml.at(ns(x.sub("TOC", "HTML TOC"))) and
|
27
27
|
@htmlToClevels = n.text.to_i
|
28
28
|
end
|
29
29
|
|
@@ -93,7 +93,7 @@ module IsoDoc
|
|
93
93
|
@fn_bookmarks = {}
|
94
94
|
end
|
95
95
|
|
96
|
-
|
96
|
+
def init_fonts(options)
|
97
97
|
@normalfontsize = options[:normalfontsize]
|
98
98
|
@smallerfontsize = options[:smallerfontsize]
|
99
99
|
@monospacefontsize = options[:monospacefontsize]
|
@@ -4,7 +4,7 @@ module IsoDoc
|
|
4
4
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
5
5
|
def expand_citeas(text)
|
6
6
|
text.nil? and return text
|
7
|
-
HTMLEntities.new.decode(text.gsub(
|
7
|
+
HTMLEntities.new.decode(text.gsub("&#x", "&#"))
|
8
8
|
end
|
9
9
|
|
10
10
|
def erefstack1(elem)
|
@@ -84,7 +84,7 @@ module IsoDoc
|
|
84
84
|
locs1 = []
|
85
85
|
until locs.empty?
|
86
86
|
if locs[1] == "to"
|
87
|
-
locs1 << @i18n.chain_to.sub(
|
87
|
+
locs1 << @i18n.chain_to.sub("%1", locs[0]).sub("%2", locs[2])
|
88
88
|
locs.shift(3)
|
89
89
|
else locs1 << locs.shift
|
90
90
|
end
|
@@ -108,25 +108,37 @@ module IsoDoc
|
|
108
108
|
|
109
109
|
def svg_to_emf(node)
|
110
110
|
uri = svg_to_emf_uri(node)
|
111
|
-
|
112
|
-
(!node["height"] || node["height"] == "auto")
|
113
|
-
node["height"] = node.elements.first["height"]
|
114
|
-
node["width"] = node.elements.first["width"]
|
115
|
-
end
|
111
|
+
svg_impose_height_attr(node)
|
116
112
|
ret = imgfile_suffix(uri, "emf")
|
117
|
-
File.exist?(ret)
|
113
|
+
if File.exist?(ret) && File.exist?(node["src"])
|
114
|
+
warn "Exists: #{ret}, Exists: #{node['src']}"
|
115
|
+
return ret
|
116
|
+
end
|
117
|
+
warn "Converting..."
|
118
118
|
inkscape_convert(uri, ret, '--export-type="emf"')
|
119
119
|
end
|
120
120
|
|
121
|
+
def svg_impose_height_attr(node)
|
122
|
+
e = node.elements&.first or return
|
123
|
+
(e.name == "svg" &&
|
124
|
+
(!node["height"] || node["height"] == "auto")) or return
|
125
|
+
node["height"] = e["height"]
|
126
|
+
node["width"] = e["width"]
|
127
|
+
end
|
128
|
+
|
121
129
|
def inkscape_convert(uri, file, option)
|
122
130
|
exe = inkscape_installed? or raise "Inkscape missing in PATH, unable" \
|
123
131
|
"to convert image #{uri}. Aborting."
|
124
132
|
uri = Metanorma::Utils::external_path uri
|
125
133
|
exe = Metanorma::Utils::external_path exe
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
134
|
+
warn %(#{exe} #{option} #{uri})
|
135
|
+
err = system %(#{exe} #{option} #{uri})
|
136
|
+
File.exist?(file) and return Metanorma::Utils::datauri(file)
|
137
|
+
file2 = uri + File.extname(file)
|
138
|
+
warn "Checking #{file2}"
|
139
|
+
warn `ls #{File.dirname(file2)}`
|
140
|
+
File.exist?(file2) and return Metanorma::Utils::datauri(file2)
|
141
|
+
raise %(Fail on #{exe} #{option} #{uri} outputting #{file}: status #{err})
|
130
142
|
end
|
131
143
|
|
132
144
|
def svg_to_emf_uri(node)
|
@@ -7,9 +7,21 @@ module IsoDoc
|
|
7
7
|
bibitem(x, renderings)
|
8
8
|
end
|
9
9
|
hidden_items(docxml)
|
10
|
+
move_norm_ref_to_sections(docxml)
|
10
11
|
@xrefs.parse_inclusions(refs: true).parse(docxml)
|
11
12
|
end
|
12
13
|
|
14
|
+
def move_norm_ref_to_sections(docxml)
|
15
|
+
docxml.at(ns(@xrefs.klass.norm_ref_xpath)) or return
|
16
|
+
s = docxml.at(ns("//sections")) ||
|
17
|
+
docxml.at(ns("//preface"))&.after("<sections/>")&.next_element ||
|
18
|
+
docxml.at(ns("//annex | //bibliography"))&.before("<sections/>")
|
19
|
+
&.previous_element or return
|
20
|
+
docxml.xpath(ns(@xrefs.klass.norm_ref_xpath)).each do |r|
|
21
|
+
s << r.remove
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
13
25
|
def hidden_items(docxml)
|
14
26
|
docxml.xpath(ns("//references[bibitem/@hidden = 'true']")).each do |x|
|
15
27
|
x.at(ns("./bibitem[not(@hidden = 'true')]")) and next
|
@@ -131,7 +143,8 @@ module IsoDoc
|
|
131
143
|
idents = @xrefs.klass.render_identifier(ids)
|
132
144
|
ret = if biblio then biblio_ref_entry_code(ordinal, idents, ids,
|
133
145
|
standard, datefn, bib)
|
134
|
-
else norm_ref_entry_code(ordinal, idents, ids, standard, datefn,
|
146
|
+
else norm_ref_entry_code(ordinal, idents, ids, standard, datefn,
|
147
|
+
bib)
|
135
148
|
end
|
136
149
|
bib << "<biblio-tag>#{ret}</biblio-tag>"
|
137
150
|
end
|
@@ -148,8 +161,8 @@ module IsoDoc
|
|
148
161
|
|
149
162
|
# if ids is just a number, only use that ([1] Non-Standard)
|
150
163
|
# else, use both ordinal, as prefix, and ids
|
151
|
-
def biblio_ref_entry_code(ordinal, ids, _id,
|
152
|
-
#standard and id = nil
|
164
|
+
def biblio_ref_entry_code(ordinal, ids, _id, _standard, datefn, _bib)
|
165
|
+
# standard and id = nil
|
153
166
|
ret = (ids[:ordinal] || ids[:metanorma] || "[#{ordinal}]")
|
154
167
|
if ids[:sdo]
|
155
168
|
ret = prefix_bracketed_ref(ret)
|
@@ -2,6 +2,14 @@ require_relative "refs"
|
|
2
2
|
|
3
3
|
module IsoDoc
|
4
4
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
5
|
+
def middle_title(docxml)
|
6
|
+
s = docxml.at(ns("//sections")) or return
|
7
|
+
t = @meta.get[:doctitle]
|
8
|
+
t.nil? || t.empty? and return
|
9
|
+
s.children.first.previous =
|
10
|
+
"<p class='zzSTDTitle1'>#{t}</p>"
|
11
|
+
end
|
12
|
+
|
5
13
|
def clause(docxml)
|
6
14
|
docxml.xpath(ns("//clause | " \
|
7
15
|
"//terms | //definitions | //references"))
|
@@ -26,10 +34,10 @@ module IsoDoc
|
|
26
34
|
end
|
27
35
|
|
28
36
|
def floattitle(docxml)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
37
|
+
p = "//clause | //annex | //appendix | //introduction | //foreword | " \
|
38
|
+
"//preface/abstract | //acknowledgements | //terms | " \
|
39
|
+
"//definitions | //references | //colophon | //indexsect"
|
40
|
+
docxml.xpath(ns(p)).each do |f|
|
33
41
|
floattitle1(f)
|
34
42
|
end
|
35
43
|
# top-level
|
@@ -94,9 +102,9 @@ module IsoDoc
|
|
94
102
|
end
|
95
103
|
|
96
104
|
def display_order_at(docxml, xpath, idx)
|
97
|
-
|
98
|
-
|
105
|
+
c = docxml.at(ns(xpath)) or return idx
|
99
106
|
idx += 1
|
107
|
+
idx = preceding_floating_titles(c, idx)
|
100
108
|
c["displayorder"] = idx
|
101
109
|
idx
|
102
110
|
end
|
@@ -104,11 +112,25 @@ module IsoDoc
|
|
104
112
|
def display_order_xpath(docxml, xpath, idx)
|
105
113
|
docxml.xpath(ns(xpath)).each do |c|
|
106
114
|
idx += 1
|
115
|
+
idx = preceding_floating_titles(c, idx)
|
107
116
|
c["displayorder"] = idx
|
108
117
|
end
|
109
118
|
idx
|
110
119
|
end
|
111
120
|
|
121
|
+
def preceding_floating_titles(node, idx)
|
122
|
+
out = node.xpath("./preceding-sibling::*")
|
123
|
+
.reverse.each_with_object([]) do |p, m|
|
124
|
+
%w(note admonition p).include?(p.name) or break m
|
125
|
+
m << p
|
126
|
+
end
|
127
|
+
out.reject { |c| c["displayorder"] }.reverse.each do |c|
|
128
|
+
c["displayorder"] = idx
|
129
|
+
idx += 1
|
130
|
+
end
|
131
|
+
idx
|
132
|
+
end
|
133
|
+
|
112
134
|
def display_order(docxml)
|
113
135
|
i = 0
|
114
136
|
i = display_order_xpath(docxml, "//preface/*", i)
|
@@ -52,6 +52,7 @@ module IsoDoc
|
|
52
52
|
name << ", #{designation_grammar(g).join(', ')}"
|
53
53
|
designation_localization(desgn, name)
|
54
54
|
designation_pronunciation(desgn, name)
|
55
|
+
designation_bookmarks(desgn, name)
|
55
56
|
desgn.children = name.children
|
56
57
|
end
|
57
58
|
|
@@ -94,6 +95,12 @@ module IsoDoc
|
|
94
95
|
name << ", /#{to_xml(f.children)}/"
|
95
96
|
end
|
96
97
|
|
98
|
+
def designation_bookmarks(desgn, name)
|
99
|
+
desgn.xpath(ns(".//bookmark")).each do |b|
|
100
|
+
name << b.remove
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
97
104
|
def termexample(docxml)
|
98
105
|
docxml.xpath(ns("//termexample")).each { |f| example1(f) }
|
99
106
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module IsoDoc
|
2
2
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
3
3
|
def prefix_container(container, linkend, node, _target)
|
4
|
-
l10n(@i18n.nested_xref.sub(
|
5
|
-
.sub(
|
4
|
+
l10n(@i18n.nested_xref.sub("%1", anchor_xref(node, container))
|
5
|
+
.sub("%2", linkend))
|
6
6
|
end
|
7
7
|
|
8
8
|
def anchor_value(id)
|
@@ -133,8 +133,8 @@ module IsoDoc
|
|
133
133
|
end
|
134
134
|
|
135
135
|
def i18n_chain_boolean(value, entry)
|
136
|
-
@i18n.send("chain_#{entry[:conn]}").sub(
|
137
|
-
.sub(
|
136
|
+
@i18n.send("chain_#{entry[:conn]}").sub("%1", value)
|
137
|
+
.sub("%2", loc2xref(entry))
|
138
138
|
end
|
139
139
|
|
140
140
|
def can_conflate_xref_rendering?(locs)
|
@@ -47,9 +47,11 @@ module IsoDoc
|
|
47
47
|
# to deal with single-term and single-ref annexes
|
48
48
|
def section(docxml)
|
49
49
|
references docxml
|
50
|
+
# feeds middle_title
|
50
51
|
# triggers xrefs reparse, so put references before all other sections,
|
51
52
|
# which alter titles and thus can alter xrefs
|
52
|
-
rearrange_clauses docxml # feeds toc, display_order, clausetitle, clause
|
53
|
+
rearrange_clauses docxml # feeds toc, display_order, clausetitle, clause, middle_title
|
54
|
+
middle_title docxml
|
53
55
|
annex docxml
|
54
56
|
clause docxml # feeds clausetitle
|
55
57
|
term docxml
|
data/lib/isodoc/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require_relative "
|
2
|
-
require_relative "
|
3
|
-
require_relative "
|
1
|
+
require_relative "table"
|
2
|
+
require_relative "inline"
|
3
|
+
require_relative "lists"
|
4
4
|
|
5
5
|
module IsoDoc
|
6
6
|
module WordFunction
|
@@ -29,25 +29,34 @@ module IsoDoc
|
|
29
29
|
def make_body2(body, docxml)
|
30
30
|
body.div class: "WordSection2" do |div2|
|
31
31
|
boilerplate docxml, div2
|
32
|
-
|
32
|
+
content(div2, docxml, ns("//preface/*[@displayorder]"))
|
33
33
|
div2.p { |p| p << " " } # placeholder
|
34
34
|
end
|
35
35
|
section_break(body)
|
36
36
|
end
|
37
37
|
|
38
|
+
MAIN_ELEMENTS =
|
39
|
+
"//sections/*[@displayorder] | //annex[@displayorder] | " \
|
40
|
+
"//bibliography/*[@displayorder] | //colophon/*[@displayorder] | " \
|
41
|
+
"//indexsect[@displayorder]".freeze
|
42
|
+
|
38
43
|
def make_body3(body, docxml)
|
39
44
|
body.div class: "WordSection3" do |div3|
|
40
|
-
|
45
|
+
content(div3, docxml, ns(self.class::MAIN_ELEMENTS))
|
41
46
|
footnotes div3
|
42
47
|
comments div3
|
43
48
|
end
|
44
49
|
end
|
45
50
|
|
46
|
-
def para_class(
|
51
|
+
def para_class(node)
|
47
52
|
return "Sourcecode" if @annotation
|
48
53
|
return "MsoCommentText" if @in_comment
|
49
54
|
return "Note" if @note
|
55
|
+
if node["type"] == "floating-title"
|
56
|
+
return "h#{node['depth']}"
|
57
|
+
end
|
50
58
|
|
59
|
+
n = node["class"] and return n
|
51
60
|
nil
|
52
61
|
end
|
53
62
|
|
@@ -8,7 +8,7 @@ module IsoDoc
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def section_break(body, continuous: false)
|
11
|
-
body.p do |p|
|
11
|
+
body.p class: "section-break" do |p|
|
12
12
|
if continuous
|
13
13
|
p.br clear: "all", style: "page-break-before:auto;" \
|
14
14
|
"mso-break-type:section-break"
|
@@ -19,7 +19,7 @@ module IsoDoc
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def page_break(out)
|
22
|
-
out.p do |p|
|
22
|
+
out.p class: "page-break" do |p|
|
23
23
|
p.br clear: "all",
|
24
24
|
style: "mso-special-character:line-break;" \
|
25
25
|
"page-break-before:always"
|
@@ -58,7 +58,7 @@ module IsoDoc
|
|
58
58
|
|
59
59
|
def xref_parse(node, out)
|
60
60
|
target = if /#/.match?(node["target"])
|
61
|
-
node["target"].sub(
|
61
|
+
node["target"].sub("#", ".doc#")
|
62
62
|
else
|
63
63
|
"##{node['target']}"
|
64
64
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "fileutils"
|
2
|
-
require_relative "
|
3
|
-
require_relative "
|
4
|
-
require_relative "
|
2
|
+
require_relative "postprocess_cover"
|
3
|
+
require_relative "postprocess_toc"
|
4
|
+
require_relative "postprocess_table"
|
5
5
|
|
6
6
|
module IsoDoc
|
7
7
|
module WordFunction
|
@@ -16,7 +16,7 @@ module IsoDoc
|
|
16
16
|
|
17
17
|
def toWord(result, filename, dir, header)
|
18
18
|
result = from_xhtml(word_cleanup(to_xhtml(result)))
|
19
|
-
.gsub(
|
19
|
+
.gsub("-DOUBLE_HYPHEN_ESCAPE-", "--")
|
20
20
|
@wordstylesheet = wordstylesheet_update
|
21
21
|
Html2Doc.new(
|
22
22
|
filename: filename, imagedir: @localdir,
|
@@ -56,6 +56,7 @@ module IsoDoc
|
|
56
56
|
word_example_cleanup(docxml)
|
57
57
|
word_pseudocode_cleanup(docxml)
|
58
58
|
word_image_caption(docxml)
|
59
|
+
word_floating_titles(docxml)
|
59
60
|
word_section_breaks(docxml)
|
60
61
|
word_tab_clean(docxml)
|
61
62
|
authority_cleanup(docxml)
|
@@ -173,6 +174,21 @@ module IsoDoc
|
|
173
174
|
end
|
174
175
|
docxml
|
175
176
|
end
|
177
|
+
|
178
|
+
# move p.h1 (floating title) after any page, section breaks
|
179
|
+
def word_floating_titles(docxml)
|
180
|
+
docxml.xpath("//p[@class = 'section-break' or @class = 'page-break']")
|
181
|
+
.each do |b|
|
182
|
+
out = b.xpath("./preceding-sibling::*").reverse
|
183
|
+
.each_with_object([]) do |p, m|
|
184
|
+
(p.name == "p" && p["class"] == "h1") or break m
|
185
|
+
m << p
|
186
|
+
end
|
187
|
+
b.delete("class")
|
188
|
+
out.empty? and next
|
189
|
+
out[-1].previous = b.remove
|
190
|
+
end
|
191
|
+
end
|
176
192
|
end
|
177
193
|
end
|
178
194
|
end
|
data/lib/isodoc/xref/xref_gen.rb
CHANGED
@@ -44,7 +44,7 @@ module IsoDoc
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def termnote_label(note)
|
47
|
-
@labels["termnote"].gsub(
|
47
|
+
@labels["termnote"].gsub("%", note.to_s)
|
48
48
|
end
|
49
49
|
|
50
50
|
def increment_label(elems, node, counter, increment: true)
|
@@ -194,11 +194,11 @@ refer_list)
|
|
194
194
|
|
195
195
|
def list_item_anchor_label(label, list_anchor, prev_label, refer_list)
|
196
196
|
prev_label.empty? or
|
197
|
-
label = @i18n.list_nested_xref.sub(
|
198
|
-
.sub(
|
197
|
+
label = @i18n.list_nested_xref.sub("%1", "#{prev_label})")
|
198
|
+
.sub("%2", label)
|
199
199
|
refer_list and
|
200
|
-
label = @i18n.list_nested_xref.sub(
|
201
|
-
.sub(
|
200
|
+
label = @i18n.list_nested_xref.sub("%1", list_anchor[:xref])
|
201
|
+
.sub("%2", label)
|
202
202
|
label
|
203
203
|
end
|
204
204
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isodoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07
|
11
|
+
date: 2023-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: html2doc
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.6.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.6.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: htmlentities
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|