isodoc 0.4.5 → 0.5.5
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/bin/rspec +18 -0
- data/isodoc.gemspec +1 -1
- data/lib/isodoc.rb +34 -5
- data/lib/isodoc/blocks.rb +62 -50
- data/lib/isodoc/cleanup.rb +34 -10
- data/lib/isodoc/html.rb +31 -16
- data/lib/isodoc/i18n-en.yaml +72 -0
- data/lib/isodoc/i18n-fr.yaml +65 -0
- data/lib/isodoc/i18n-zh-Hans.yaml +64 -0
- data/lib/isodoc/i18n.rb +90 -0
- data/lib/isodoc/inline.rb +25 -18
- data/lib/isodoc/iso2wordhtml.rb +30 -7
- data/lib/isodoc/lists.rb +29 -9
- data/lib/isodoc/metadata.rb +54 -38
- data/lib/isodoc/notes.rb +32 -32
- data/lib/isodoc/postprocessing.rb +65 -46
- data/lib/isodoc/references.rb +63 -29
- data/lib/isodoc/section.rb +94 -44
- data/lib/isodoc/table.rb +19 -19
- data/lib/isodoc/terms.rb +5 -6
- data/lib/isodoc/utils.rb +48 -5
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/xref_gen.rb +87 -75
- data/spec/isodoc/blocks_spec.rb +618 -0
- data/spec/isodoc/lists_spec.rb +227 -0
- data/spec/isodoc/section_spec.rb +419 -0
- data/spec/isodoc/table_spec.rb +135 -0
- data/spec/isodoc/xref_spec.rb +1073 -0
- data/spec/spec_helper.rb +26 -0
- metadata +17 -6
data/lib/isodoc/metadata.rb
CHANGED
@@ -2,15 +2,12 @@ require "htmlentities"
|
|
2
2
|
|
3
3
|
module IsoDoc
|
4
4
|
class Convert
|
5
|
-
|
6
5
|
def init_metadata
|
7
|
-
@meta = {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
secretariat: "XXXX",
|
13
|
-
}
|
6
|
+
@meta = { tc: "XXXX", sc: "XXXX", wg: "XXXX",
|
7
|
+
editorialgroup: [],
|
8
|
+
secretariat: "XXXX",
|
9
|
+
obsoletes: nil,
|
10
|
+
obsoletes_part: nil }
|
14
11
|
%w{published accessed created activated obsoleted}.each do |w|
|
15
12
|
@meta["#{w}date".to_sym] = "XXX"
|
16
13
|
end
|
@@ -57,7 +54,7 @@ module IsoDoc
|
|
57
54
|
wg_num = xml.at(ns("//editorialgroup/workgroup/@number"))
|
58
55
|
wg_type = xml.at(ns("//editorialgroup/workgroup/@type"))&.text || "WG"
|
59
56
|
if wg_num
|
60
|
-
wgid =
|
57
|
+
wgid = "#{wg_type} #{wg_num.text}"
|
61
58
|
set_metadata(:wg, wgid)
|
62
59
|
set_metadata(:editorialgroup, get_metadata[:editorialgroup] << wgid)
|
63
60
|
end
|
@@ -70,32 +67,37 @@ module IsoDoc
|
|
70
67
|
|
71
68
|
def bibdate(isoxml, _out)
|
72
69
|
isoxml.xpath(ns("//bibdata/date")).each do |d|
|
73
|
-
set_metadata("#{d[
|
70
|
+
set_metadata("#{d['type']}date".to_sym, d.text)
|
74
71
|
end
|
75
72
|
end
|
76
73
|
|
77
74
|
def agency(xml)
|
78
75
|
agency = ""
|
79
|
-
|
80
|
-
|
81
|
-
"organization/name")).each do |org|
|
76
|
+
xml.xpath(ns("//bibdata/contributor[xmlns:role/@type = 'publisher']/"\
|
77
|
+
"organization/name")).each do |org|
|
82
78
|
agency = org.text == "ISO" ? "ISO/#{agency}" : "#{agency}#{org.text}/"
|
83
79
|
end
|
84
80
|
set_metadata(:agency, agency.sub(%r{/$}, ""))
|
85
81
|
end
|
86
82
|
|
87
|
-
def
|
83
|
+
def docnumber(isoxml)
|
88
84
|
docnumber = isoxml.at(ns("//project-number"))
|
89
85
|
partnumber = isoxml.at(ns("//project-number/@part"))
|
90
|
-
|
91
|
-
dn = docnumber
|
86
|
+
subpartnumber = isoxml.at(ns("//project-number/@subpart"))
|
87
|
+
dn = docnumber&.text || ""
|
92
88
|
dn += "-#{partnumber.text}" if partnumber
|
89
|
+
dn += "-#{subpartnumber.text}" if subpartnumber
|
90
|
+
dn
|
91
|
+
end
|
92
|
+
|
93
|
+
def id(isoxml, _out)
|
94
|
+
dn = docnumber(isoxml)
|
95
|
+
documentstatus = isoxml.at(ns("//status/stage"))
|
93
96
|
if documentstatus
|
94
97
|
set_metadata(:stage, documentstatus.text)
|
95
98
|
abbr = stage_abbreviation(documentstatus.text)
|
96
99
|
set_metadata(:stageabbr, abbr)
|
97
|
-
documentstatus.text.to_i < 60
|
98
|
-
dn = abbr + " " + dn
|
100
|
+
(documentstatus.text.to_i < 60) && dn = abbr + " " + dn
|
99
101
|
end
|
100
102
|
set_metadata(:docnumber, dn)
|
101
103
|
end
|
@@ -103,38 +105,42 @@ module IsoDoc
|
|
103
105
|
def draftinfo(draft, revdate)
|
104
106
|
draftinfo = ""
|
105
107
|
if draft
|
106
|
-
draftinfo = " (
|
108
|
+
draftinfo = " (#{@draft_lbl} #{draft.text}"
|
107
109
|
draftinfo += ", #{revdate.text}" if revdate
|
108
110
|
draftinfo += ")"
|
109
111
|
end
|
110
|
-
draftinfo
|
112
|
+
l10n(draftinfo)
|
111
113
|
end
|
112
114
|
|
113
115
|
def version(isoxml, _out)
|
114
|
-
|
115
|
-
|
116
|
-
draft
|
117
|
-
set_metadata(:draft, draft
|
118
|
-
revdate = isoxml.at(ns("//version/revision-date"))
|
119
|
-
set_metadata(:revdate, revdate.nil? ? nil : revdate.text)
|
120
|
-
|
121
|
-
set_metadata(:draftinfo, draftinfo(draft, revdate))
|
122
|
-
|
123
|
-
|
116
|
+
set_metadata(:docyear, isoxml&.at(ns("//copyright/from"))&.text)
|
117
|
+
# draft = isoxml.at(ns("//version/draft"))
|
118
|
+
# set_metadata(:draft, draft.nil? ? nil : draft.text)
|
119
|
+
set_metadata(:draft, isoxml&.at(ns("//version/draft"))&.text)
|
120
|
+
# revdate = isoxml.at(ns("//version/revision-date"))
|
121
|
+
#set_metadata(:revdate, revdate.nil? ? nil : revdate.text)
|
122
|
+
set_metadata(:revdate, isoxml&.at(ns("//version/revision-date"))&.text)
|
123
|
+
#set_metadata(:draftinfo, draftinfo(draft, revdate))
|
124
|
+
set_metadata(:draftinfo,
|
125
|
+
draftinfo(get_metadata[:draft], get_metadata[:revdate]))
|
126
|
+
end
|
127
|
+
|
128
|
+
# we don't leave this to i18n.rb, because we have both English and
|
129
|
+
# French titles in the same document
|
124
130
|
def part_label(lang)
|
125
131
|
case lang
|
126
132
|
when "en" then "Part"
|
127
|
-
when "fr" then "
|
133
|
+
when "fr" then "Partie"
|
128
134
|
end
|
129
135
|
end
|
130
136
|
|
131
|
-
def compose_title(main, intro, part, partnum, lang)
|
132
|
-
|
133
|
-
main = c.encode(main.text, :hexadecimal)
|
137
|
+
def compose_title(main, intro, part, partnum, subpartnum, lang)
|
138
|
+
main = main.nil? ? "" : @c.encode(main.text, :hexadecimal)
|
134
139
|
intro &&
|
135
|
-
main = "#{c.encode(intro.text, :hexadecimal)} — #{main}"
|
140
|
+
main = "#{@c.encode(intro.text, :hexadecimal)} — #{main}"
|
136
141
|
if part
|
137
|
-
suffix = c.encode(part.text, :hexadecimal)
|
142
|
+
suffix = @c.encode(part.text, :hexadecimal)
|
143
|
+
partnum = "#{partnum}–#{subpartnum}" if partnum && subpartnum
|
138
144
|
suffix = "#{part_label(lang)} #{partnum}: " + suffix if partnum
|
139
145
|
main = "#{main} — #{suffix}"
|
140
146
|
end
|
@@ -146,7 +152,8 @@ module IsoDoc
|
|
146
152
|
main = isoxml.at(ns("//title-main[@language='en']"))
|
147
153
|
part = isoxml.at(ns("//title-part[@language='en']"))
|
148
154
|
partnumber = isoxml.at(ns("//project-number/@part"))
|
149
|
-
|
155
|
+
subpartnumber = isoxml.at(ns("//project-number/@subpart"))
|
156
|
+
main = compose_title(main, intro, part, partnumber, subpartnumber, "en")
|
150
157
|
set_metadata(:doctitle, main)
|
151
158
|
end
|
152
159
|
|
@@ -155,8 +162,17 @@ module IsoDoc
|
|
155
162
|
main = isoxml.at(ns("//title-main[@language='fr']"))
|
156
163
|
part = isoxml.at(ns("//title-part[@language='fr']"))
|
157
164
|
partnumber = isoxml.at(ns("//project-number/@part"))
|
158
|
-
|
165
|
+
subpartnumber = isoxml.at(ns("//project-number/@subpart"))
|
166
|
+
main = compose_title(main, intro, part, partnumber, subpartnumber, "fr")
|
159
167
|
set_metadata(:docsubtitle, main)
|
160
168
|
end
|
169
|
+
|
170
|
+
def relations(isoxml, _out)
|
171
|
+
std = isoxml.at(ns("//bibdata/relation[@type = 'obsoletes']")) || return
|
172
|
+
locality = std.at(ns(".//locality"))
|
173
|
+
id = std.at(ns(".//docidentifier"))
|
174
|
+
set_metadata(:obsoletes, id.text)
|
175
|
+
set_metadata(:obsoletes_part, locality.text)
|
176
|
+
end
|
161
177
|
end
|
162
178
|
end
|
data/lib/isodoc/notes.rb
CHANGED
@@ -40,7 +40,7 @@ module IsoDoc
|
|
40
40
|
end.join("\n")
|
41
41
|
end
|
42
42
|
|
43
|
-
def make_generic_footnote_text(node, fnid
|
43
|
+
def make_generic_footnote_text(node, fnid)
|
44
44
|
noko do |xml|
|
45
45
|
xml.aside **{ id: "ftn#{fnid}" } do |div|
|
46
46
|
node.children.each { |n| parse(n, div) }
|
@@ -69,12 +69,12 @@ module IsoDoc
|
|
69
69
|
def footnote_parse(node, out)
|
70
70
|
return table_footnote_parse(node, out) if @in_table || @in_figure
|
71
71
|
fn = node["reference"]
|
72
|
-
out.a **{"epub:type": "footnote", href: "#ftn#{fn}" } do |a|
|
72
|
+
out.a **{ "epub:type": "footnote", href: "#ftn#{fn}" } do |a|
|
73
73
|
a.sup { |sup| sup << fn }
|
74
74
|
end
|
75
|
-
return if @seen_footnote.include?(fn)
|
75
|
+
return if @seen_footnote.include?(fn)
|
76
76
|
@in_footnote = true
|
77
|
-
@footnotes << make_generic_footnote_text(node, fn
|
77
|
+
@footnotes << make_generic_footnote_text(node, fn)
|
78
78
|
@in_footnote = false
|
79
79
|
@seen_footnote << fn
|
80
80
|
end
|
@@ -94,28 +94,28 @@ module IsoDoc
|
|
94
94
|
@in_comment = false
|
95
95
|
end
|
96
96
|
|
97
|
+
def comment_link_attrs(fn, node)
|
98
|
+
{ style: "MsoCommentReference", target: fn,
|
99
|
+
class: "commentLink", from: node["from"],
|
100
|
+
to: node["to"] }
|
101
|
+
end
|
102
|
+
|
97
103
|
# add in from and to links to move the comment into place
|
98
104
|
def make_comment_link(out, fn, node)
|
99
|
-
out.span
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
#s << " "
|
108
|
-
#end
|
109
|
-
end
|
110
|
-
end
|
105
|
+
out.span(**comment_link_attrs(fn, node)) do |s1|
|
106
|
+
s1.span **{ lang: "EN-GB", style: "font-size:9.0pt" } do |s2|
|
107
|
+
s2.a **{ style: "mso-comment-reference:SMC_#{fn};"\
|
108
|
+
"mso-comment-date:#{node['date']}" }
|
109
|
+
s2.span **{ style: "mso-special-character:comment",
|
110
|
+
target: fn } # do |s|
|
111
|
+
end
|
112
|
+
end
|
111
113
|
end
|
112
114
|
|
113
115
|
def make_comment_target(out)
|
114
116
|
out.span **{ style: "MsoCommentReference" } do |s1|
|
115
|
-
s1.span **{ lang: "EN-GB", style: "font-size:9.0pt"} do |s2|
|
116
|
-
s2.span **{ style: "mso-special-character:comment" }
|
117
|
-
# s << " "
|
118
|
-
# end
|
117
|
+
s1.span **{ lang: "EN-GB", style: "font-size:9.0pt" } do |s2|
|
118
|
+
s2.span **{ style: "mso-special-character:comment" }
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
@@ -123,7 +123,7 @@ module IsoDoc
|
|
123
123
|
def make_comment_text(node, fn)
|
124
124
|
noko do |xml|
|
125
125
|
xml.div **{ style: "mso-element:comment", id: fn } do |div|
|
126
|
-
div.span **{ style: %{mso-comment-author:"#{node[
|
126
|
+
div.span **{ style: %{mso-comment-author:"#{node['reviewer']}"} }
|
127
127
|
make_comment_target(div)
|
128
128
|
node.children.each { |n| parse(n, div) }
|
129
129
|
end
|
@@ -138,7 +138,7 @@ module IsoDoc
|
|
138
138
|
|
139
139
|
COMMENT_IN_COMMENT_LIST =
|
140
140
|
'//div[@style="mso-element:comment-list"]//'\
|
141
|
-
'span[@style="MsoCommentReference"]'
|
141
|
+
'span[@style="MsoCommentReference"]'.freeze
|
142
142
|
|
143
143
|
def embed_comment_in_comment_list(docxml)
|
144
144
|
docxml.xpath(COMMENT_IN_COMMENT_LIST).each do |x|
|
@@ -148,7 +148,7 @@ module IsoDoc
|
|
148
148
|
docxml
|
149
149
|
end
|
150
150
|
|
151
|
-
def move_comment_link_to_from1(x, fromlink
|
151
|
+
def move_comment_link_to_from1(x, fromlink)
|
152
152
|
x.remove
|
153
153
|
link = x.at(".//a")
|
154
154
|
fromlink.replace(x)
|
@@ -156,10 +156,10 @@ module IsoDoc
|
|
156
156
|
end
|
157
157
|
|
158
158
|
def comment_attributes(docxml, x)
|
159
|
-
fromlink = docxml.at("//*[@id='#{x[
|
159
|
+
fromlink = docxml.at("//*[@id='#{x['from']}']")
|
160
160
|
return(nil) if fromlink.nil?
|
161
|
-
tolink = docxml.at("//*[@id='#{x[
|
162
|
-
target = docxml.at("//*[@id='#{x[
|
161
|
+
tolink = docxml.at("//*[@id='#{x['to']}']") || fromlink
|
162
|
+
target = docxml.at("//*[@id='#{x['target']}']")
|
163
163
|
{ from: fromlink, to: tolink, target: target }
|
164
164
|
end
|
165
165
|
|
@@ -172,7 +172,7 @@ module IsoDoc
|
|
172
172
|
from["style"] != "mso-special-character:comment"
|
173
173
|
end
|
174
174
|
|
175
|
-
def insert_comment_cont(from, to, target
|
175
|
+
def insert_comment_cont(from, to, target)
|
176
176
|
# includes_to = from.at(".//*[@id='#{to}']")
|
177
177
|
while !from.nil? && from["id"] != to
|
178
178
|
following = from.xpath("./following::*")
|
@@ -187,8 +187,8 @@ module IsoDoc
|
|
187
187
|
def move_comment_link_to_from(docxml)
|
188
188
|
docxml.xpath('//span[@style="MsoCommentReference"][@from]').each do |x|
|
189
189
|
attrs = comment_attributes(docxml, x) || next
|
190
|
-
move_comment_link_to_from1(x, attrs[:from]
|
191
|
-
insert_comment_cont(attrs[:from], x["to"], x["target"]
|
190
|
+
move_comment_link_to_from1(x, attrs[:from])
|
191
|
+
insert_comment_cont(attrs[:from], x["to"], x["target"])
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
@@ -199,11 +199,11 @@ module IsoDoc
|
|
199
199
|
comments << { text: c.remove.to_s, id: c["id"] }
|
200
200
|
end
|
201
201
|
comments.sort! { |a, b| link_order[a[:id]] <=> link_order[b[:id]] }
|
202
|
-
comments
|
202
|
+
# comments
|
203
203
|
end
|
204
204
|
|
205
205
|
COMMENT_TARGET_XREFS =
|
206
|
-
"//span[@style='mso-special-character:comment']/@target"
|
206
|
+
"//span[@style='mso-special-character:comment']/@target".freeze
|
207
207
|
|
208
208
|
def reorder_comments_by_comment_link(docxml)
|
209
209
|
link_order = {}
|
@@ -211,7 +211,7 @@ module IsoDoc
|
|
211
211
|
link_order[target.value] = i
|
212
212
|
end
|
213
213
|
comments = get_comments_from_text(docxml, link_order)
|
214
|
-
list = docxml.at("//*[@style='mso-element:comment-list']")
|
214
|
+
list = docxml.at("//*[@style='mso-element:comment-list']") || return
|
215
215
|
list.children = comments.map { |c| c[:text] }.join("\n")
|
216
216
|
end
|
217
217
|
end
|
@@ -6,7 +6,6 @@ require "pp"
|
|
6
6
|
|
7
7
|
module IsoDoc
|
8
8
|
class Convert
|
9
|
-
|
10
9
|
def postprocess(result, filename, dir)
|
11
10
|
generate_header(filename, dir)
|
12
11
|
result = from_xhtml(cleanup(to_xhtml(result)))
|
@@ -15,49 +14,70 @@ module IsoDoc
|
|
15
14
|
end
|
16
15
|
|
17
16
|
def toWord(result, filename, dir)
|
18
|
-
result = from_xhtml(
|
17
|
+
result = from_xhtml(word_cleanup(to_xhtml(result)))
|
19
18
|
result = populate_template(result, :word)
|
20
|
-
Html2Doc.process(result, filename, @wordstylesheet,
|
21
|
-
|
19
|
+
Html2Doc.process(result, filename: filename, stylesheet: @wordstylesheet,
|
20
|
+
header_file: "header.html", dir: dir,
|
21
|
+
asciimathdelims: [@openmathdelim, @closemathdelim],
|
22
|
+
liststyles: { ul: @ulstyle, ol: @olstyle })
|
22
23
|
end
|
23
24
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
25
|
+
def word_cleanup(docxml)
|
26
|
+
word_preface(docxml)
|
27
|
+
word_annex_cleanup(docxml)
|
28
|
+
word_dl_cleanup(docxml)
|
27
29
|
docxml
|
28
30
|
end
|
29
31
|
|
32
|
+
def word_dl_cleanup1(dtd, tr)
|
33
|
+
dtd[:dt].name = "td"
|
34
|
+
dtd[:dt]["valign"] = "top"
|
35
|
+
dtd[:dt].parent = tr
|
36
|
+
dtd[:dd].name = "td"
|
37
|
+
dtd[:dd]["valign"] = "top"
|
38
|
+
dtd[:dd].parent = tr
|
39
|
+
end
|
40
|
+
|
41
|
+
def word_dl_cleanup(docxml)
|
42
|
+
docxml.xpath("//dl").each do |dl|
|
43
|
+
dl.name = "table"
|
44
|
+
extract_symbols_list(dl).each do |dtd|
|
45
|
+
tr = dl.add_child("<tr></tr>").first
|
46
|
+
word_dl_cleanup1(dtd, tr)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
30
51
|
# force Annex h2 to be p.h2Annex, so it is not picked up by ToC
|
31
|
-
def
|
32
|
-
|
52
|
+
def word_annex_cleanup(docxml)
|
53
|
+
docxml.xpath("//h2[ancestor::*[@class = 'Section3']]").each do |h2|
|
33
54
|
h2.name = "p"
|
34
55
|
h2["class"] = "h2Annex"
|
35
56
|
end
|
36
57
|
end
|
37
58
|
|
38
|
-
def
|
59
|
+
def word_preface(docxml)
|
39
60
|
cover = to_xhtml_fragment(File.read(@wordcoverpage, encoding: "UTF-8"))
|
40
|
-
|
41
|
-
|
42
|
-
intro = to_xhtml_fragment(
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
d.children.first.add_previous_sibling intro.to_xml(encoding: 'US-ASCII')
|
61
|
+
docxml.at('//div[@class="WordSection1"]').children.first.previous =
|
62
|
+
cover.to_xml(encoding: "US-ASCII")
|
63
|
+
intro = to_xhtml_fragment(File.read(@wordintropage, encoding: "UTF-8").
|
64
|
+
sub(/WORDTOC/, make_WordToC(docxml)))
|
65
|
+
docxml.at('//div[@class="WordSection2"]').children.first.previous =
|
66
|
+
intro.to_xml(encoding: "US-ASCII")
|
47
67
|
end
|
48
68
|
|
49
69
|
def populate_template(docxml, _format)
|
50
70
|
meta = get_metadata
|
51
|
-
docxml.
|
52
|
-
gsub(/\[TERMREF\]\s*/, "[
|
53
|
-
gsub(/\s*\[\/TERMREF\]\s*/, "]").
|
54
|
-
gsub(/\s*\[ISOSECTION\]/, ", ").
|
55
|
-
gsub(/\s*\[MODIFICATION\]/, ",
|
71
|
+
docxml = docxml.
|
72
|
+
gsub(/\[TERMREF\]\s*/, l10n("[#{@source_lbl}: ")).
|
73
|
+
gsub(/\s*\[\/TERMREF\]\s*/, l10n("]")).
|
74
|
+
gsub(/\s*\[ISOSECTION\]/, l10n(", ")).
|
75
|
+
gsub(/\s*\[MODIFICATION\]/, l10n(", #{@modified_lbl} — "))
|
56
76
|
template = Liquid::Template.parse(docxml)
|
57
77
|
template.render(meta.map { |k, v| [k.to_s, v] }.to_h)
|
58
78
|
end
|
59
79
|
|
60
|
-
def generate_header(filename,
|
80
|
+
def generate_header(filename, _dir)
|
61
81
|
template = Liquid::Template.parse(File.read(@header, encoding: "UTF-8"))
|
62
82
|
meta = get_metadata
|
63
83
|
meta[:filename] = filename
|
@@ -76,9 +96,10 @@ module IsoDoc
|
|
76
96
|
|
77
97
|
# isodoc.css overrides any CSS injected by Html2Doc, which
|
78
98
|
# is inserted before this CSS.
|
79
|
-
def define_head(html, filename,
|
99
|
+
def define_head(html, filename, _dir)
|
80
100
|
html.head do |head|
|
81
101
|
head.title { |t| t << filename }
|
102
|
+
return unless @standardstylesheet
|
82
103
|
head.style do |style|
|
83
104
|
stylesheet = File.read(@standardstylesheet).
|
84
105
|
gsub("FILENAME", filename)
|
@@ -92,50 +113,49 @@ module IsoDoc
|
|
92
113
|
div.parent.add_child titlepage
|
93
114
|
end
|
94
115
|
|
95
|
-
def
|
116
|
+
def word_toc_entry(toclevel, heading)
|
96
117
|
bookmark = Random.rand(1000000000)
|
97
118
|
<<~TOC
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
119
|
+
<p class="MsoToc#{toclevel}"><span class="MsoHyperlink"><span
|
120
|
+
lang="EN-GB" style='mso-no-proof:yes'>
|
121
|
+
<a href="#_Toc#{bookmark}">#{heading}<span lang="EN-GB"
|
122
|
+
class="MsoTocTextSpan">
|
102
123
|
<span style='mso-tab-count:1 dotted'>. </span>
|
103
|
-
</span><span lang="EN-GB" class="MsoTocTextSpan">
|
124
|
+
</span><span lang="EN-GB" class="MsoTocTextSpan">
|
104
125
|
<span style='mso-element:field-begin'></span></span>
|
105
|
-
<span lang="EN-GB"
|
126
|
+
<span lang="EN-GB"
|
106
127
|
class="MsoTocTextSpan"> PAGEREF _Toc#{bookmark} \\h </span>
|
107
128
|
<span lang="EN-GB" class="MsoTocTextSpan"><span
|
108
129
|
style='mso-element:field-separator'></span></span><span
|
109
130
|
lang="EN-GB" class="MsoTocTextSpan">1</span>
|
110
|
-
<span lang="EN-GB"
|
111
|
-
class="MsoTocTextSpan"></span><span
|
131
|
+
<span lang="EN-GB"
|
132
|
+
class="MsoTocTextSpan"></span><span
|
112
133
|
lang="EN-GB" class="MsoTocTextSpan"><span
|
113
134
|
style='mso-element:field-end'></span></span></a></span></span></p>
|
114
135
|
|
115
136
|
TOC
|
116
137
|
end
|
117
138
|
|
118
|
-
WORD_TOC_PREFACE = <<~TOC
|
139
|
+
WORD_TOC_PREFACE = <<~TOC.freeze
|
119
140
|
<span lang="EN-GB"><span
|
120
|
-
style='mso-element:field-begin'></span><span
|
141
|
+
style='mso-element:field-begin'></span><span
|
121
142
|
style='mso-spacerun:yes'> </span>TOC
|
122
|
-
\\o "1-2" \\h \\z \\u <span
|
143
|
+
\\o "1-2" \\h \\z \\u <span
|
123
144
|
style='mso-element:field-separator'></span></span>
|
124
145
|
TOC
|
125
146
|
|
126
|
-
WORD_TOC_SUFFIX = <<~TOC
|
127
|
-
<p class="MsoToc1"><span lang="EN-GB"><span
|
128
|
-
style='mso-element:field-end'></span></span><span
|
147
|
+
WORD_TOC_SUFFIX = <<~TOC.freeze
|
148
|
+
<p class="MsoToc1"><span lang="EN-GB"><span
|
149
|
+
style='mso-element:field-end'></span></span><span
|
129
150
|
lang="EN-GB"><o:p> </o:p></span></p>
|
130
151
|
TOC
|
131
152
|
|
132
153
|
def header_strip(h)
|
133
154
|
h = h.to_s.gsub(%r{<br/>}, " ").
|
134
155
|
sub(/<h[12][^>]*>/, "").sub(%r{</h[12]>}, "")
|
135
|
-
h1 = to_xhtml_fragment(h)
|
136
|
-
#h1.xpath(".//*[@style = 'MsoCommentReference']").each do |x|
|
156
|
+
h1 = to_xhtml_fragment(h)
|
137
157
|
h1.xpath(".//*").each do |x|
|
138
|
-
if x.name == "span" && x[
|
158
|
+
if x.name == "span" && x["style"] == "MsoCommentReference"
|
139
159
|
x.children.remove
|
140
160
|
x.content = ""
|
141
161
|
end
|
@@ -143,15 +163,14 @@ module IsoDoc
|
|
143
163
|
from_xhtml(h1)
|
144
164
|
end
|
145
165
|
|
146
|
-
def
|
166
|
+
def make_WordToC(docxml)
|
147
167
|
toc = ""
|
148
168
|
docxml.xpath("//h1 | //h2[not(ancestor::*[@class = 'Section3'])]").
|
149
169
|
each do |h|
|
150
|
-
toc +=
|
170
|
+
toc += word_toc_entry(h.name == "h1" ? 1 : 2, header_strip(h))
|
151
171
|
end
|
152
|
-
toc.sub(/(<p class="MsoToc1">)/,
|
172
|
+
toc.sub(/(<p class="MsoToc1">)/,
|
153
173
|
%{\\1#{WORD_TOC_PREFACE}}) + WORD_TOC_SUFFIX
|
154
174
|
end
|
155
|
-
|
156
175
|
end
|
157
176
|
end
|