isodoc 1.5.2 → 1.6.1
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 +1 -1
- data/.rubocop.yml +6 -2
- data/Gemfile +2 -2
- data/bin/rspec +1 -2
- data/isodoc.gemspec +11 -11
- data/lib/isodoc/base_style/all.css +7 -0
- data/lib/isodoc/base_style/metanorma_word.css +7 -0
- data/lib/isodoc/base_style/metanorma_word.scss +8 -0
- data/lib/isodoc/base_style/reset.css +7 -0
- data/lib/isodoc/base_style/reset.scss +9 -0
- data/lib/isodoc/base_style/scripts.html +187 -0
- data/lib/isodoc/class_utils.rb +6 -5
- data/lib/isodoc/convert.rb +30 -17
- data/lib/isodoc/css.rb +42 -28
- data/lib/isodoc/function/blocks.rb +15 -4
- data/lib/isodoc/function/blocks_example_note.rb +2 -2
- data/lib/isodoc/function/cleanup.rb +1 -2
- data/lib/isodoc/function/inline.rb +31 -10
- data/lib/isodoc/function/references.rb +1 -1
- data/lib/isodoc/function/to_word_html.rb +19 -8
- data/lib/isodoc/function/utils.rb +41 -38
- data/lib/isodoc/gem_tasks.rb +30 -31
- data/lib/isodoc/html_convert.rb +4 -4
- data/lib/isodoc/html_function/postprocess.rb +35 -76
- data/lib/isodoc/html_function/postprocess_footnotes.rb +59 -0
- data/lib/isodoc/i18n.rb +20 -20
- data/lib/isodoc/pdf_convert.rb +1 -3
- data/lib/isodoc/presentation_function/block.rb +26 -11
- data/lib/isodoc/presentation_function/inline.rb +44 -38
- data/lib/isodoc/presentation_xml_convert.rb +1 -1
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/footnotes.rb +22 -15
- data/lib/isodoc/word_function/inline.rb +6 -0
- data/lib/isodoc/word_function/postprocess.rb +16 -6
- data/lib/isodoc/xref.rb +10 -11
- data/lib/isodoc/xref/xref_counter.rb +31 -15
- data/lib/isodoc/xref/xref_gen.rb +28 -22
- data/lib/isodoc/xref/xref_sect_gen.rb +22 -20
- data/lib/isodoc/xslfo_convert.rb +36 -25
- data/spec/assets/html_override.css +1 -0
- data/spec/assets/word_override.css +1 -0
- data/spec/isodoc/blocks_spec.rb +2599 -2503
- data/spec/isodoc/cleanup_spec.rb +1107 -1109
- data/spec/isodoc/footnotes_spec.rb +1 -16
- data/spec/isodoc/i18n_spec.rb +984 -972
- data/spec/isodoc/inline_spec.rb +34 -0
- data/spec/isodoc/lists_spec.rb +316 -315
- data/spec/isodoc/postproc_spec.rb +1655 -1521
- data/spec/isodoc/presentation_xml_spec.rb +345 -338
- data/spec/isodoc/ref_spec.rb +718 -723
- data/spec/isodoc/section_spec.rb +910 -902
- data/spec/isodoc/table_spec.rb +566 -556
- data/spec/isodoc/terms_spec.rb +252 -256
- data/spec/isodoc/xref_spec.rb +3040 -2985
- data/spec/isodoc/xslfo_convert_spec.rb +39 -0
- data/spec/spec_helper.rb +30 -29
- metadata +72 -69
- data/.rubocop.ribose.yml +0 -65
- data/.rubocop.tb.yml +0 -650
data/lib/isodoc/css.rb
CHANGED
@@ -6,26 +6,40 @@ module IsoDoc
|
|
6
6
|
def precompiled_style_or_original(stylesheet_path)
|
7
7
|
# Already have compiled stylesheet, use it
|
8
8
|
return stylesheet_path if stylesheet_path.nil? ||
|
9
|
-
File.extname(stylesheet_path) ==
|
10
|
-
|
9
|
+
File.extname(stylesheet_path) == ".css"
|
10
|
+
|
11
|
+
basename = File.basename(stylesheet_path, ".*")
|
11
12
|
compiled_path = File.join(File.dirname(stylesheet_path),
|
12
13
|
"#{basename}.css")
|
13
14
|
return stylesheet_path unless File.file?(compiled_path)
|
15
|
+
|
14
16
|
compiled_path
|
15
17
|
end
|
16
18
|
|
19
|
+
def localpath(path)
|
20
|
+
return path if %r{^[A-Z]:|^/|^file:/}.match?(path)
|
21
|
+
return path unless (@sourcedir || @localdir) && path
|
22
|
+
|
23
|
+
File.expand_path(File.join((@sourcedir || @localdir), path))
|
24
|
+
end
|
25
|
+
|
17
26
|
# run this after @meta is populated
|
18
27
|
def populate_css
|
19
|
-
@htmlstylesheet = generate_css(@htmlstylesheet_name, true)
|
20
|
-
@wordstylesheet = generate_css(@wordstylesheet_name, false)
|
21
|
-
@standardstylesheet =
|
28
|
+
@htmlstylesheet = generate_css(localpath(@htmlstylesheet_name), true)
|
29
|
+
@wordstylesheet = generate_css(localpath(@wordstylesheet_name), false)
|
30
|
+
@standardstylesheet =
|
31
|
+
generate_css(localpath(@standardstylesheet_name), false)
|
32
|
+
@htmlstylesheet_override_name and @htmlstylesheet_override =
|
33
|
+
File.open(localpath(@htmlstylesheet_override_name))
|
34
|
+
@wordstylesheet_override_name and @wordstylesheet_override =
|
35
|
+
File.open(localpath(@wordstylesheet_override_name))
|
22
36
|
end
|
23
37
|
|
24
38
|
def default_fonts(_options)
|
25
39
|
{
|
26
|
-
bodyfont:
|
27
|
-
headerfont:
|
28
|
-
monospacefont:
|
40
|
+
bodyfont: "Arial",
|
41
|
+
headerfont: "Arial",
|
42
|
+
monospacefont: "Courier",
|
29
43
|
}
|
30
44
|
end
|
31
45
|
|
@@ -37,35 +51,35 @@ module IsoDoc
|
|
37
51
|
|
38
52
|
def fonts_options
|
39
53
|
{
|
40
|
-
|
41
|
-
|
42
|
-
|
54
|
+
"bodyfont" => options[:bodyfont] || "Arial",
|
55
|
+
"headerfont" => options[:headerfont] || "Arial",
|
56
|
+
"monospacefont" => options[:monospacefont] || "Courier",
|
43
57
|
"normalfontsize" => options[:normalfontsize],
|
44
58
|
"monospacefontsize" => options[:monospacefontsize],
|
45
59
|
"smallerfontsize" => options[:smallerfontsize],
|
46
|
-
"footnotefontsize" => options[:footnotefontsize]
|
60
|
+
"footnotefontsize" => options[:footnotefontsize],
|
47
61
|
}
|
48
62
|
end
|
49
63
|
|
50
64
|
def scss_fontheader(is_html_css)
|
51
|
-
b = options[:bodyfont] ||
|
52
|
-
h = options[:headerfont] ||
|
53
|
-
m = options[:monospacefont] ||
|
54
|
-
ns = options[:normalfontsize] || (is_html_css ? "1.0em" :
|
55
|
-
ms = options[:monospacefontsize] || (is_html_css ? "0.8em" :
|
56
|
-
ss = options[:smallerfontsize] || (is_html_css ? "0.9em" :
|
57
|
-
fs = options[:footnotefontsize] || (is_html_css ? "0.9em" :
|
65
|
+
b = options[:bodyfont] || "Arial"
|
66
|
+
h = options[:headerfont] || "Arial"
|
67
|
+
m = options[:monospacefont] || "Courier"
|
68
|
+
ns = options[:normalfontsize] || (is_html_css ? "1.0em" : "12.0pt")
|
69
|
+
ms = options[:monospacefontsize] || (is_html_css ? "0.8em" : "11.0pt")
|
70
|
+
ss = options[:smallerfontsize] || (is_html_css ? "0.9em" : "10.0pt")
|
71
|
+
fs = options[:footnotefontsize] || (is_html_css ? "0.9em" : "9.0pt")
|
58
72
|
"$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"\
|
59
73
|
"$normalfontsize: #{ns};\n$monospacefontsize: #{ms};\n"\
|
60
74
|
"$smallerfontsize: #{ss};\n$footnotefontsize: #{fs};\n"
|
61
75
|
end
|
62
76
|
|
63
77
|
def convert_scss(filename, stylesheet, stripwordcss)
|
64
|
-
require
|
65
|
-
require
|
78
|
+
require "sassc"
|
79
|
+
require "isodoc/sassc_importer"
|
66
80
|
|
67
|
-
[File.join(Gem.loaded_specs[
|
68
|
-
|
81
|
+
[File.join(Gem.loaded_specs["isodoc"].full_gem_path,
|
82
|
+
"lib", "isodoc"),
|
69
83
|
File.dirname(filename)].each do |name|
|
70
84
|
SassC.load_paths << name
|
71
85
|
end
|
@@ -79,14 +93,14 @@ module IsoDoc
|
|
79
93
|
return nil if filename.nil?
|
80
94
|
|
81
95
|
filename = precompiled_style_or_original(filename)
|
82
|
-
stylesheet = File.read(filename, encoding:
|
96
|
+
stylesheet = File.read(filename, encoding: "UTF-8")
|
83
97
|
stylesheet = populate_template(stylesheet, :word)
|
84
|
-
stylesheet.gsub!(/(\s|\{)mso-[^:]+:[^;]+;/m,
|
85
|
-
if File.extname(filename) ==
|
98
|
+
stylesheet.gsub!(/(\s|\{)mso-[^:]+:[^;]+;/m, "\\1") if stripwordcss
|
99
|
+
if File.extname(filename) == ".scss"
|
86
100
|
stylesheet = convert_scss(filename, stylesheet, stripwordcss)
|
87
101
|
end
|
88
|
-
Tempfile.open([File.basename(filename,
|
89
|
-
encoding:
|
102
|
+
Tempfile.open([File.basename(filename, ".*"), "css"],
|
103
|
+
encoding: "utf-8") do |f|
|
90
104
|
f.write(stylesheet)
|
91
105
|
f
|
92
106
|
end
|
@@ -24,6 +24,7 @@ module IsoDoc::Function
|
|
24
24
|
def figure_parse(node, out)
|
25
25
|
return pseudocode_parse(node, out) if node["class"] == "pseudocode" ||
|
26
26
|
node["type"] == "pseudocode"
|
27
|
+
|
27
28
|
@in_figure = true
|
28
29
|
out.div **figure_attrs(node) do |div|
|
29
30
|
node.children.each do |n|
|
@@ -51,6 +52,7 @@ module IsoDoc::Function
|
|
51
52
|
|
52
53
|
def sourcecode_name_parse(node, div, name)
|
53
54
|
return if name.nil?
|
55
|
+
|
54
56
|
div.p **{ class: "SourceTitle", style: "text-align:center;" } do |p|
|
55
57
|
name.children.each { |n| parse(n, p) }
|
56
58
|
end
|
@@ -91,14 +93,15 @@ module IsoDoc::Function
|
|
91
93
|
@annotation = false
|
92
94
|
end
|
93
95
|
|
94
|
-
def admonition_class(
|
96
|
+
def admonition_class(_node)
|
95
97
|
"Admonition"
|
96
98
|
end
|
97
99
|
|
98
100
|
def admonition_name(node, type)
|
99
101
|
name = node&.at(ns("./name")) and return name
|
100
|
-
name = Nokogiri::XML::Node.new(
|
102
|
+
name = Nokogiri::XML::Node.new("name", node.document)
|
101
103
|
return unless type && @i18n.admonition[type]
|
104
|
+
|
102
105
|
name << @i18n.admonition[type]&.upcase
|
103
106
|
name
|
104
107
|
end
|
@@ -119,7 +122,8 @@ module IsoDoc::Function
|
|
119
122
|
|
120
123
|
def formula_where(dl, out)
|
121
124
|
return unless dl
|
122
|
-
|
125
|
+
|
126
|
+
out.p **{ style: "page-break-after:avoid;" } do |p|
|
123
127
|
p << @i18n.where
|
124
128
|
end
|
125
129
|
parse(dl, out)
|
@@ -148,6 +152,7 @@ module IsoDoc::Function
|
|
148
152
|
formula_where(node.at(ns("./dl")), div)
|
149
153
|
node.children.each do |n|
|
150
154
|
next if %w(stem dl name).include? n.name
|
155
|
+
|
151
156
|
parse(n, div)
|
152
157
|
end
|
153
158
|
end
|
@@ -182,6 +187,7 @@ module IsoDoc::Function
|
|
182
187
|
author = node.at(ns("./author"))
|
183
188
|
source = node.at(ns("./source"))
|
184
189
|
return if author.nil? && source.nil?
|
190
|
+
|
185
191
|
out.p **{ class: "QuoteAttribution" } do |p|
|
186
192
|
p << "— #{author.text}" if author
|
187
193
|
p << ", " if author && source
|
@@ -201,9 +207,14 @@ module IsoDoc::Function
|
|
201
207
|
end
|
202
208
|
|
203
209
|
def passthrough_parse(node, out)
|
204
|
-
return if node["format"]
|
210
|
+
return if node["format"] &&
|
205
211
|
!(node["format"].split(/,/).include? @format.to_s)
|
212
|
+
|
206
213
|
out.passthrough node.text
|
207
214
|
end
|
215
|
+
|
216
|
+
def svg_parse(node, out)
|
217
|
+
out << node.to_xml
|
218
|
+
end
|
208
219
|
end
|
209
220
|
end
|
@@ -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
|
@@ -23,21 +23,26 @@ module IsoDoc::Function
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def xref_parse(node, out)
|
26
|
-
target = /#/.match(node["target"])
|
27
|
-
|
28
|
-
|
26
|
+
target = if /#/.match?(node["target"])
|
27
|
+
node["target"].sub(/#/, ".html#")
|
28
|
+
else
|
29
|
+
"##{node['target']}"
|
30
|
+
end
|
31
|
+
out.a(**{ "href": target }) { |l| no_locality_parse(node, l) }
|
29
32
|
end
|
30
33
|
|
31
34
|
def suffix_url(url)
|
32
|
-
return url if %r{^
|
35
|
+
return url if %r{^https?://}.match?(url)
|
36
|
+
|
33
37
|
url.sub(/#{File.extname(url)}$/, ".html")
|
34
38
|
end
|
35
39
|
|
36
40
|
def eref_target(node)
|
37
|
-
href = "
|
41
|
+
href = "##{node['bibitemid']}"
|
38
42
|
url = node.at(ns("//bibitem[@id = '#{node['bibitemid']}']/"\
|
39
43
|
"uri[@type = 'citation']"))
|
40
44
|
return href unless url
|
45
|
+
|
41
46
|
href = suffix_url(url.text)
|
42
47
|
anchor = node&.at(ns(".//locality[@type = 'anchor']"))&.text&.strip
|
43
48
|
anchor and href += "##{anchor}"
|
@@ -68,10 +73,11 @@ module IsoDoc::Function
|
|
68
73
|
end
|
69
74
|
|
70
75
|
def stem_parse(node, out)
|
71
|
-
ooml =
|
76
|
+
ooml = case node["type"]
|
77
|
+
when "AsciiMath"
|
72
78
|
"#{@openmathdelim}#{HTMLEntities.new.encode(node.text)}"\
|
73
79
|
"#{@closemathdelim}"
|
74
|
-
|
80
|
+
when "MathML" then node.first_element_child.to_s
|
75
81
|
else
|
76
82
|
HTMLEntities.new.encode(node.text)
|
77
83
|
end
|
@@ -93,7 +99,7 @@ module IsoDoc::Function
|
|
93
99
|
height: node["height"] || "auto",
|
94
100
|
width: node["width"] || "auto",
|
95
101
|
title: node["title"],
|
96
|
-
alt: node["alt"]
|
102
|
+
alt: node["alt"] }
|
97
103
|
out.img **attr_code(attrs)
|
98
104
|
image_title_parse(out, caption)
|
99
105
|
end
|
@@ -106,12 +112,27 @@ module IsoDoc::Function
|
|
106
112
|
|
107
113
|
def text_parse(node, out)
|
108
114
|
return if node.nil? || node.text.nil?
|
115
|
+
|
109
116
|
text = node.to_s
|
110
|
-
|
111
|
-
gsub(
|
117
|
+
if in_sourcecode
|
118
|
+
text = text.gsub("\n", "<br/>").gsub("<br/> ", "<br/> ")
|
119
|
+
.gsub(/ (?= )/, " ")
|
120
|
+
end
|
112
121
|
out << text
|
113
122
|
end
|
114
123
|
|
124
|
+
def add_parse(node, out)
|
125
|
+
out.span **{class: "addition"} do |e|
|
126
|
+
node.children.each { |n| parse(n, e) }
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def del_parse(node, out)
|
131
|
+
out.span **{class: "deletion"} do |e|
|
132
|
+
node.children.each { |n| parse(n, e) }
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
115
136
|
def error_parse(node, out)
|
116
137
|
text = node.to_xml.gsub(/</, "<").gsub(/>/, ">")
|
117
138
|
out.para do |p|
|
@@ -87,7 +87,7 @@ module IsoDoc::Function
|
|
87
87
|
|
88
88
|
def omit_docid_prefix(prefix)
|
89
89
|
return true if prefix.nil? || prefix.empty?
|
90
|
-
return %w(ISO IEC IEV ITU W3C metanorma).include? prefix
|
90
|
+
return %w(ISO IEC IEV ITU W3C csd metanorma rfc-anchor).include? prefix
|
91
91
|
end
|
92
92
|
|
93
93
|
def date_note_process(b, ref)
|
@@ -19,14 +19,21 @@ module IsoDoc::Function
|
|
19
19
|
def init_file(filename, debug)
|
20
20
|
filepath = Pathname.new(filename)
|
21
21
|
filename = filepath.sub_ext('').sub(/\.presentation$/, "").to_s
|
22
|
+
dir = init_dir(filename, debug)
|
23
|
+
@filename = filename
|
24
|
+
@localdir = filepath.parent.to_s + '/'
|
25
|
+
@sourcedir = @localdir
|
26
|
+
@sourcefilename and @sourcedir = Pathname.new(@sourcefilename).parent.to_s + '/'
|
27
|
+
[filename, dir]
|
28
|
+
end
|
29
|
+
|
30
|
+
def init_dir(filename, debug)
|
22
31
|
dir = "#{filename}_files"
|
23
32
|
unless debug
|
24
33
|
Dir.mkdir(dir, 0777) unless File.exists?(dir)
|
25
34
|
FileUtils.rm_rf "#{dir}/*"
|
26
35
|
end
|
27
|
-
|
28
|
-
@localdir = filepath.parent.to_s + '/'
|
29
|
-
[filename, dir]
|
36
|
+
dir
|
30
37
|
end
|
31
38
|
|
32
39
|
# tmp image dir is same directory as @filename
|
@@ -44,15 +51,16 @@ module IsoDoc::Function
|
|
44
51
|
if @standardstylesheet
|
45
52
|
head.style do |style|
|
46
53
|
@standardstylesheet.open
|
47
|
-
stylesheet = @standardstylesheet.read.
|
48
|
-
|
54
|
+
stylesheet = @standardstylesheet.read.gsub(
|
55
|
+
"FILENAME", File.basename(filename).sub(/\.presentation$/, "")
|
56
|
+
)
|
49
57
|
style.comment "\n#{stylesheet}\n"
|
50
58
|
end
|
51
59
|
end
|
52
60
|
end
|
53
61
|
|
54
62
|
def body_attr
|
55
|
-
{ lang:
|
63
|
+
{ lang: @lang.to_s }
|
56
64
|
end
|
57
65
|
|
58
66
|
def make_body(xml, docxml)
|
@@ -125,7 +133,7 @@ module IsoDoc::Function
|
|
125
133
|
i = scope isoxml, out, 0
|
126
134
|
i = norm_ref isoxml, out, i
|
127
135
|
i = terms_defs isoxml, out, i
|
128
|
-
|
136
|
+
symbols_abbrevs isoxml, out, i
|
129
137
|
clause isoxml, out
|
130
138
|
annex isoxml, out
|
131
139
|
bibliography isoxml, out
|
@@ -133,7 +141,7 @@ module IsoDoc::Function
|
|
133
141
|
|
134
142
|
def boilerplate(node, out)
|
135
143
|
boilerplate = node.at(ns("//boilerplate")) or return
|
136
|
-
out.div **{class: "authority"} do |s|
|
144
|
+
out.div **{ class: "authority" } do |s|
|
137
145
|
boilerplate.children.each do |n|
|
138
146
|
if n.name == "title"
|
139
147
|
s.h1 do |h|
|
@@ -225,6 +233,9 @@ module IsoDoc::Function
|
|
225
233
|
when "passthrough" then passthrough_parse(node, out)
|
226
234
|
when "amend" then amend_parse(node, out)
|
227
235
|
when "tab" then clausedelimspace(out) # in Presentation XML only
|
236
|
+
when "svg" then svg_parse(node, out) # in Presentation XML only
|
237
|
+
when "add" then add_parse(node, out)
|
238
|
+
when "del" then del_parse(node, out)
|
228
239
|
else
|
229
240
|
error_parse(node, out)
|
230
241
|
end
|
@@ -28,10 +28,10 @@ module IsoDoc::Function
|
|
28
28
|
# to allow for HTMLentities
|
29
29
|
def noko(&block)
|
30
30
|
doc = ::Nokogiri::XML.parse(NOKOHEAD)
|
31
|
-
fragment = doc.fragment(
|
31
|
+
fragment = doc.fragment("")
|
32
32
|
::Nokogiri::XML::Builder.with fragment, &block
|
33
|
-
fragment.to_xml(encoding:
|
34
|
-
l.gsub(/\s*\n/,
|
33
|
+
fragment.to_xml(encoding: "US-ASCII").lines.map do |l|
|
34
|
+
l.gsub(/\s*\n/, "")
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -46,17 +46,18 @@ module IsoDoc::Function
|
|
46
46
|
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
|
47
47
|
|
48
48
|
def to_xhtml(xml)
|
49
|
-
xml.gsub!(/<\?xml[^>]*>/,
|
49
|
+
xml.gsub!(/<\?xml[^>]*>/, "")
|
50
50
|
/<!DOCTYPE /.match(xml) || (xml = DOCTYPE_HDR + xml)
|
51
51
|
xml = xml.split(/(\&[^ \r\n\t#;]+;)/).map do |t|
|
52
52
|
/^(\&[^ \t\r\n#;]+;)/.match?(t) ?
|
53
53
|
HTMLEntities.new.encode(HTMLEntities.new.decode(t), :hexadecimal) : t
|
54
|
-
end.join(
|
54
|
+
end.join("")
|
55
55
|
begin
|
56
56
|
Nokogiri::XML.parse(xml, &:strict)
|
57
57
|
rescue Nokogiri::XML::SyntaxError => e
|
58
|
-
File.open("#{@filename}.#{@format}.err",
|
59
|
-
abort "Malformed Output XML for #{@format}: #{e}
|
58
|
+
File.open("#{@filename}.#{@format}.err", "w:UTF-8") { |f| f.write xml }
|
59
|
+
abort "Malformed Output XML for #{@format}: #{e} "\
|
60
|
+
"(see #{@filename}.#{@format}.err)"
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
@@ -67,11 +68,12 @@ module IsoDoc::Function
|
|
67
68
|
end
|
68
69
|
|
69
70
|
def from_xhtml(xml)
|
70
|
-
xml.to_xml.sub(%r{ xmlns="http://www.w3.org/1999/xhtml"},
|
71
|
+
xml.to_xml.sub(%r{ xmlns="http://www.w3.org/1999/xhtml"}, "")
|
71
72
|
end
|
72
73
|
|
73
74
|
CLAUSE_ANCESTOR =
|
74
75
|
".//ancestor::*[local-name() = 'annex' or "\
|
76
|
+
"local-name() = 'definitions' or "\
|
75
77
|
"local-name() = 'acknowledgements' or local-name() = 'term' or "\
|
76
78
|
"local-name() = 'appendix' or local-name() = 'foreword' or "\
|
77
79
|
"local-name() = 'introduction' or local-name() = 'terms' or "\
|
@@ -102,31 +104,32 @@ module IsoDoc::Function
|
|
102
104
|
else
|
103
105
|
@i18n.l10n("#{array[0..-2].join(', ')} "\
|
104
106
|
"#{@i18n.and} #{array.last}",
|
105
|
-
|
107
|
+
@lang, @script)
|
106
108
|
end
|
107
109
|
end
|
108
110
|
|
109
111
|
# avoid `; avoid {{ (Liquid Templates); avoid [[ (Javascript)
|
110
112
|
def extract_delims(text)
|
111
|
-
@openmathdelim =
|
112
|
-
@closemathdelim =
|
113
|
+
@openmathdelim = "(#("
|
114
|
+
@closemathdelim = ")#)"
|
113
115
|
while text.include?(@openmathdelim) || text.include?(@closemathdelim)
|
114
|
-
@openmathdelim +=
|
115
|
-
@closemathdelim +=
|
116
|
+
@openmathdelim += "("
|
117
|
+
@closemathdelim += ")"
|
116
118
|
end
|
117
119
|
[@openmathdelim, @closemathdelim]
|
118
120
|
end
|
119
121
|
|
120
122
|
def header_strip(h)
|
121
|
-
h = h.to_s.gsub(%r{<br\s*/>},
|
122
|
-
|
123
|
+
h = h.to_s.gsub(%r{<br\s*/>}, " ").gsub(/<\/?h[123456][^>]*>/, "")
|
124
|
+
.gsub(/<\/?b[^>]*>/, "")
|
123
125
|
h1 = to_xhtml_fragment(h.dup)
|
124
126
|
h1.traverse do |x|
|
125
|
-
x.replace(
|
126
|
-
x.remove if x.name ==
|
127
|
-
x.remove if x.name ==
|
128
|
-
x.remove if x.name ==
|
129
|
-
x.
|
127
|
+
x.replace(" ") if x.name == "span" && /mso-tab-count/.match(x["style"])
|
128
|
+
x.remove if x.name == "img"
|
129
|
+
x.remove if x.name == "span" && x["class"] == "MsoCommentReference"
|
130
|
+
x.remove if x.name == "a" && x["class"] == "FootnoteRef"
|
131
|
+
x.remove if x.name == "span" && /mso-bookmark/.match(x["style"])
|
132
|
+
x.replace(x.children) if x.name == "a"
|
130
133
|
end
|
131
134
|
from_xhtml(h1)
|
132
135
|
end
|
@@ -138,9 +141,9 @@ module IsoDoc::Function
|
|
138
141
|
def liquid(doc)
|
139
142
|
# unescape HTML escapes in doc
|
140
143
|
doc = doc.split(%r<(\{%|%\})>).each_slice(4).map do |a|
|
141
|
-
a[2] = a[2].gsub(/\</,
|
142
|
-
a.join(
|
143
|
-
end.join(
|
144
|
+
a[2] = a[2].gsub(/\</, "<").gsub(/\>/, ">") if a.size > 2
|
145
|
+
a.join("")
|
146
|
+
end.join("")
|
144
147
|
Liquid::Template.parse(doc)
|
145
148
|
end
|
146
149
|
|
@@ -151,20 +154,20 @@ module IsoDoc::Function
|
|
151
154
|
|
152
155
|
def populate_template(docxml, _format = nil)
|
153
156
|
meta = @meta
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
157
|
+
.get
|
158
|
+
.merge(@labels ? {labels: @labels} : {})
|
159
|
+
.merge(@meta.labels ? {labels: @meta.labels} : {})
|
160
|
+
.merge(fonts_options || {})
|
158
161
|
template = liquid(docxml)
|
159
162
|
template.render(meta.map { |k, v| [k.to_s, empty2nil(v)] }.to_h)
|
160
|
-
|
163
|
+
.gsub("<", "<").gsub(">", ">").gsub("&", "&")
|
161
164
|
end
|
162
165
|
|
163
166
|
def save_dataimage(uri, _relative_dir = true)
|
164
167
|
%r{^data:(image|application)/(?<imgtype>[^;]+);base64,(?<imgdata>.+)$} =~ uri
|
165
|
-
imgtype.sub!(/\+[a-z0-9]+$/,
|
166
|
-
imgtype =
|
167
|
-
Tempfile.open([
|
168
|
+
imgtype.sub!(/\+[a-z0-9]+$/, "") # svg+xml
|
169
|
+
imgtype = "png" unless /^[a-z0-9]+$/.match imgtype
|
170
|
+
Tempfile.open(["image", ".#{imgtype}"]) do |f|
|
168
171
|
f.binmode
|
169
172
|
f.write(Base64.strict_decode64(imgdata))
|
170
173
|
@tempfile_cache << f # persist to the end
|
@@ -173,18 +176,18 @@ module IsoDoc::Function
|
|
173
176
|
end
|
174
177
|
|
175
178
|
def image_localfile(i)
|
176
|
-
if /^data:/.match? i[
|
177
|
-
save_dataimage(i[
|
178
|
-
elsif %r{^([A-Z]:)?/}.match? i[
|
179
|
-
i[
|
179
|
+
if /^data:/.match? i["src"]
|
180
|
+
save_dataimage(i["src"], false)
|
181
|
+
elsif %r{^([A-Z]:)?/}.match? i["src"]
|
182
|
+
i["src"]
|
180
183
|
else
|
181
|
-
File.join(@localdir, i[
|
184
|
+
File.join(@localdir, i["src"])
|
182
185
|
end
|
183
186
|
end
|
184
187
|
|
185
188
|
def labelled_ancestor(node)
|
186
|
-
!node.ancestors(
|
187
|
-
|
189
|
+
!node.ancestors("example, requirement, recommendation, permission, "\
|
190
|
+
"note, table, figure, sourcecode").empty?
|
188
191
|
end
|
189
192
|
end
|
190
193
|
end
|