isodoc 1.5.5 → 1.6.4
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/.github/workflows/rake.yml +2 -12
- data/.hound.yml +3 -1
- data/.rubocop.yml +3 -7
- data/Gemfile +2 -2
- data/Rakefile +2 -2
- data/bin/rspec +1 -2
- data/isodoc.gemspec +11 -11
- data/lib/isodoc-yaml/i18n-ar.yaml +152 -0
- data/lib/isodoc-yaml/i18n-de.yaml +149 -0
- data/lib/isodoc-yaml/i18n-es.yaml +151 -0
- data/lib/isodoc-yaml/i18n-ru.yaml +154 -0
- data/lib/isodoc.rb +0 -2
- 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/common.rb +2 -0
- data/lib/isodoc/convert.rb +30 -17
- data/lib/isodoc/css.rb +43 -34
- data/lib/isodoc/function/blocks.rb +21 -4
- data/lib/isodoc/function/blocks_example_note.rb +2 -2
- data/lib/isodoc/function/cleanup.rb +53 -45
- data/lib/isodoc/function/form.rb +51 -0
- data/lib/isodoc/function/inline.rb +37 -15
- data/lib/isodoc/function/references.rb +55 -42
- data/lib/isodoc/function/section.rb +29 -16
- data/lib/isodoc/function/table.rb +1 -0
- data/lib/isodoc/function/to_word_html.rb +33 -29
- data/lib/isodoc/function/utils.rb +180 -159
- data/lib/isodoc/gem_tasks.rb +30 -31
- data/lib/isodoc/headlesshtml_convert.rb +8 -7
- data/lib/isodoc/html_convert.rb +6 -4
- data/lib/isodoc/html_function/comments.rb +2 -0
- data/lib/isodoc/html_function/footnotes.rb +14 -7
- data/lib/isodoc/html_function/form.rb +62 -0
- data/lib/isodoc/html_function/html.rb +30 -26
- data/lib/isodoc/html_function/postprocess.rb +41 -82
- data/lib/isodoc/html_function/postprocess_footnotes.rb +59 -0
- data/lib/isodoc/i18n.rb +33 -31
- data/lib/isodoc/pdf_convert.rb +12 -16
- data/lib/isodoc/presentation_function/bibdata.rb +54 -30
- data/lib/isodoc/presentation_function/block.rb +17 -8
- data/lib/isodoc/presentation_function/inline.rb +84 -120
- data/lib/isodoc/presentation_function/math.rb +84 -0
- data/lib/isodoc/presentation_function/section.rb +20 -22
- data/lib/isodoc/presentation_xml_convert.rb +2 -1
- data/lib/isodoc/sassc_importer.rb +1 -1
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +28 -24
- data/lib/isodoc/word_function/footnotes.rb +22 -15
- data/lib/isodoc/word_function/postprocess.rb +50 -36
- data/lib/isodoc/xref.rb +9 -10
- data/lib/isodoc/xref/xref_counter.rb +32 -17
- data/lib/isodoc/xref/xref_gen.rb +33 -21
- data/lib/isodoc/xref/xref_gen_seq.rb +60 -35
- data/lib/isodoc/xref/xref_sect_gen.rb +37 -35
- data/lib/isodoc/xslfo_convert.rb +36 -27
- data/spec/assets/scripts_override.html +3 -0
- data/spec/isodoc/blocks_spec.rb +2490 -2591
- data/spec/isodoc/cleanup_spec.rb +1107 -1109
- data/spec/isodoc/footnotes_spec.rb +1 -16
- data/spec/isodoc/form_spec.rb +156 -0
- data/spec/isodoc/i18n_spec.rb +984 -972
- data/spec/isodoc/inline_spec.rb +1129 -912
- data/spec/isodoc/lists_spec.rb +316 -315
- data/spec/isodoc/postproc_spec.rb +1751 -1540
- data/spec/isodoc/presentation_xml_spec.rb +403 -323
- 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 +251 -255
- data/spec/isodoc/xref_spec.rb +3041 -2992
- data/spec/isodoc/xslfo_convert_spec.rb +39 -0
- data/spec/spec_helper.rb +30 -29
- metadata +77 -65
data/lib/isodoc/class_utils.rb
CHANGED
@@ -4,18 +4,19 @@ module IsoDoc
|
|
4
4
|
from = date.at(ns("./from"))
|
5
5
|
to = date.at(ns("./to"))
|
6
6
|
on = date.at(ns("./on"))
|
7
|
-
return date.text unless
|
7
|
+
return date.text unless from || on || to
|
8
8
|
return on.text if on
|
9
|
+
|
9
10
|
ret = "#{from.text}–"
|
10
11
|
ret += to.text if to
|
11
12
|
ret
|
12
13
|
end
|
13
14
|
|
14
15
|
def ns(xpath)
|
15
|
-
xpath.gsub(%r{/([a-zA-z])}, "/xmlns:\\1")
|
16
|
-
gsub(%r{::([a-zA-z])}, "::xmlns:\\1")
|
17
|
-
gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]* ?=)}, "[xmlns:\\1")
|
18
|
-
gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]*\])}, "[xmlns:\\1")
|
16
|
+
xpath.gsub(%r{/([a-zA-z])}, "/xmlns:\\1")
|
17
|
+
.gsub(%r{::([a-zA-z])}, "::xmlns:\\1")
|
18
|
+
.gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]* ?=)}, "[xmlns:\\1")
|
19
|
+
.gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]*\])}, "[xmlns:\\1")
|
19
20
|
end
|
20
21
|
|
21
22
|
def liquid(doc)
|
data/lib/isodoc/common.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative "./function/blocks"
|
2
2
|
require_relative "./function/cleanup"
|
3
|
+
require_relative "./function/form"
|
3
4
|
require_relative "./function/inline"
|
4
5
|
require_relative "./function/lists"
|
5
6
|
require_relative "./function/references"
|
@@ -15,6 +16,7 @@ module IsoDoc
|
|
15
16
|
class Common
|
16
17
|
include Function::Blocks
|
17
18
|
include Function::Cleanup
|
19
|
+
include Function::Form
|
18
20
|
include Function::Inline
|
19
21
|
include Function::Lists
|
20
22
|
include Function::References
|
data/lib/isodoc/convert.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "isodoc/common"
|
3
4
|
require "fileutils"
|
4
5
|
require "tempfile"
|
@@ -7,9 +8,7 @@ require_relative "css"
|
|
7
8
|
|
8
9
|
module IsoDoc
|
9
10
|
class Convert < ::IsoDoc::Common
|
10
|
-
attr_accessor :options
|
11
|
-
attr_accessor :i18n
|
12
|
-
attr_accessor :meta
|
11
|
+
attr_accessor :options, :i18n, :meta, :xrefs
|
13
12
|
|
14
13
|
# htmlstylesheet: Generic stylesheet for HTML
|
15
14
|
# htmlstylesheet_override: Override stylesheet for HTML
|
@@ -33,16 +32,17 @@ module IsoDoc
|
|
33
32
|
# monospace: font to use for monospace text
|
34
33
|
# suppressheadingnumbers: suppress heading numbers for clauses
|
35
34
|
# scripts: Scripts file for HTML
|
35
|
+
# scripts_override: Override scripts file for HTML
|
36
36
|
# scripts_pdf: Scripts file for PDF (not used in XSLT PDF)
|
37
37
|
# datauriimage: Encode images in HTML output as data URIs
|
38
38
|
# break_up_urls_in_tables: whether to insert spaces in URLs in tables
|
39
39
|
# every 40-odd chars
|
40
|
+
# bare: do not insert any prefatory material (coverpage, boilerplate)
|
40
41
|
def initialize(options)
|
41
|
-
@libdir ||= File.dirname(__FILE__)
|
42
|
+
@libdir ||= File.dirname(__FILE__) # rubocop:disable Lint/DisjunctiveAssignmentInConstructor
|
42
43
|
options.merge!(default_fonts(options)) do |_, old, new|
|
43
44
|
old || new
|
44
|
-
end
|
45
|
-
.merge!(default_file_locations(options)) do |_, old, new|
|
45
|
+
end.merge!(default_file_locations(options)) do |_, old, new|
|
46
46
|
old || new
|
47
47
|
end
|
48
48
|
@options = options
|
@@ -53,6 +53,7 @@ module IsoDoc
|
|
53
53
|
@htmlstylesheet_override_name = options[:htmlstylesheet_override]
|
54
54
|
@wordstylesheet_override_name = options[:wordstylesheet_override]
|
55
55
|
@standardstylesheet_name = options[:standardstylesheet]
|
56
|
+
@sourcefilename = options[:sourcefilename]
|
56
57
|
@header = options[:header]
|
57
58
|
@htmlcoverpage = options[:htmlcoverpage]
|
58
59
|
@wordcoverpage = options[:wordcoverpage]
|
@@ -62,15 +63,18 @@ module IsoDoc
|
|
62
63
|
@smallerfontsize = options[:smallerfontsize]
|
63
64
|
@monospacefontsize = options[:monospacefontsize]
|
64
65
|
@footnotefontsize = options[:footnotefontsize]
|
65
|
-
@scripts = options[:scripts]
|
66
|
+
@scripts = options[:scripts] ||
|
67
|
+
File.join(File.dirname(__FILE__), "base_style", "scripts.html")
|
66
68
|
@scripts_pdf = options[:scripts_pdf]
|
69
|
+
@scripts_override = options[:scripts_override]
|
67
70
|
@i18nyaml = options[:i18nyaml]
|
68
71
|
@ulstyle = options[:ulstyle]
|
69
72
|
@olstyle = options[:olstyle]
|
70
73
|
@datauriimage = options[:datauriimage]
|
71
74
|
@suppressheadingnumbers = options[:suppressheadingnumbers]
|
72
|
-
@break_up_urls_in_tables = options[:break_up_urls_in_tables] ==
|
73
|
-
@
|
75
|
+
@break_up_urls_in_tables = options[:break_up_urls_in_tables] == "true"
|
76
|
+
@bare = options[:bare]
|
77
|
+
@termdomain = ""
|
74
78
|
@termexample = false
|
75
79
|
@note = false
|
76
80
|
@sourcecode = false
|
@@ -92,17 +96,17 @@ module IsoDoc
|
|
92
96
|
@wordToClevels = 2 if @wordToClevels.zero?
|
93
97
|
@htmlToClevels = options[:htmltoclevels].to_i
|
94
98
|
@htmlToClevels = 2 if @htmlToClevels.zero?
|
95
|
-
@bookmarks_allocated = {
|
99
|
+
@bookmarks_allocated = { "X" => true }
|
96
100
|
@fn_bookmarks = {}
|
97
101
|
end
|
98
102
|
|
99
103
|
def tmpimagedir_suffix
|
100
|
-
|
104
|
+
"_images"
|
101
105
|
end
|
102
106
|
|
103
107
|
def html_doc_path(*file)
|
104
108
|
file.each do |f|
|
105
|
-
ret = File.join(@libdir, File.join(
|
109
|
+
ret = File.join(@libdir, File.join("html", f))
|
106
110
|
File.exist?(ret) and return ret
|
107
111
|
end
|
108
112
|
nil
|
@@ -112,7 +116,7 @@ module IsoDoc
|
|
112
116
|
@xrefs.parse docxml
|
113
117
|
noko do |xml|
|
114
118
|
xml.html **{ lang: @lang.to_s } do |html|
|
115
|
-
html.parent.add_namespace(
|
119
|
+
html.parent.add_namespace("epub", "http://www.idpf.org/2007/ops")
|
116
120
|
info docxml, nil
|
117
121
|
populate_css
|
118
122
|
html.head { |head| define_head head, filename, dir }
|
@@ -134,8 +138,8 @@ module IsoDoc
|
|
134
138
|
@i18n = I18n.new(lang, script, i18nyaml || @i18nyaml)
|
135
139
|
end
|
136
140
|
|
137
|
-
def l10n(
|
138
|
-
@i18n.l10n(
|
141
|
+
def l10n(expr, lang = @lang, script = @script)
|
142
|
+
@i18n.l10n(expr, lang, script)
|
139
143
|
end
|
140
144
|
|
141
145
|
def convert_init(file, input_filename, debug)
|
@@ -157,14 +161,23 @@ module IsoDoc
|
|
157
161
|
docxml, filename, dir = convert_init(file, input_filename, debug)
|
158
162
|
result = convert1(docxml, filename, dir)
|
159
163
|
return result if debug
|
164
|
+
|
160
165
|
output_filename ||= "#{filename}.#{@suffix}"
|
161
166
|
postprocess(result, output_filename, dir)
|
162
167
|
FileUtils.rm_rf dir
|
163
168
|
end
|
164
169
|
|
165
|
-
def middle_clause(
|
170
|
+
def middle_clause(_docxml = nil)
|
166
171
|
"//clause[parent::sections][not(@type = 'scope')]"\
|
167
|
-
|
172
|
+
"[not(descendant::terms)]"
|
173
|
+
end
|
174
|
+
|
175
|
+
def target_pdf(node)
|
176
|
+
if /#/.match?(node["target"])
|
177
|
+
node["target"].sub(/#/, ".pdf#")
|
178
|
+
else
|
179
|
+
"##{node['target']}"
|
180
|
+
end
|
168
181
|
end
|
169
182
|
end
|
170
183
|
end
|
data/lib/isodoc/css.rb
CHANGED
@@ -6,32 +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 =
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
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))
|
28
36
|
end
|
29
37
|
|
30
38
|
def default_fonts(_options)
|
31
39
|
{
|
32
|
-
bodyfont:
|
33
|
-
headerfont:
|
34
|
-
monospacefont:
|
40
|
+
bodyfont: "Arial",
|
41
|
+
headerfont: "Arial",
|
42
|
+
monospacefont: "Courier",
|
35
43
|
}
|
36
44
|
end
|
37
45
|
|
@@ -43,35 +51,35 @@ module IsoDoc
|
|
43
51
|
|
44
52
|
def fonts_options
|
45
53
|
{
|
46
|
-
|
47
|
-
|
48
|
-
|
54
|
+
"bodyfont" => options[:bodyfont] || "Arial",
|
55
|
+
"headerfont" => options[:headerfont] || "Arial",
|
56
|
+
"monospacefont" => options[:monospacefont] || "Courier",
|
49
57
|
"normalfontsize" => options[:normalfontsize],
|
50
58
|
"monospacefontsize" => options[:monospacefontsize],
|
51
59
|
"smallerfontsize" => options[:smallerfontsize],
|
52
|
-
"footnotefontsize" => options[:footnotefontsize]
|
60
|
+
"footnotefontsize" => options[:footnotefontsize],
|
53
61
|
}
|
54
62
|
end
|
55
63
|
|
56
64
|
def scss_fontheader(is_html_css)
|
57
|
-
b = options[:bodyfont] ||
|
58
|
-
h = options[:headerfont] ||
|
59
|
-
m = options[:monospacefont] ||
|
60
|
-
ns = options[:normalfontsize] || (is_html_css ? "1.0em" :
|
61
|
-
ms = options[:monospacefontsize] || (is_html_css ? "0.8em" :
|
62
|
-
ss = options[:smallerfontsize] || (is_html_css ? "0.9em" :
|
63
|
-
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")
|
64
72
|
"$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"\
|
65
73
|
"$normalfontsize: #{ns};\n$monospacefontsize: #{ms};\n"\
|
66
74
|
"$smallerfontsize: #{ss};\n$footnotefontsize: #{fs};\n"
|
67
75
|
end
|
68
76
|
|
69
77
|
def convert_scss(filename, stylesheet, stripwordcss)
|
70
|
-
require
|
71
|
-
require
|
78
|
+
require "sassc"
|
79
|
+
require "isodoc/sassc_importer"
|
72
80
|
|
73
|
-
[File.join(Gem.loaded_specs[
|
74
|
-
|
81
|
+
[File.join(Gem.loaded_specs["isodoc"].full_gem_path,
|
82
|
+
"lib", "isodoc"),
|
75
83
|
File.dirname(filename)].each do |name|
|
76
84
|
SassC.load_paths << name
|
77
85
|
end
|
@@ -83,15 +91,16 @@ module IsoDoc
|
|
83
91
|
# stripwordcss if HTML stylesheet, !stripwordcss if DOC stylesheet
|
84
92
|
def generate_css(filename, stripwordcss)
|
85
93
|
return nil if filename.nil?
|
94
|
+
|
86
95
|
filename = precompiled_style_or_original(filename)
|
87
|
-
stylesheet = File.read(filename, encoding:
|
96
|
+
stylesheet = File.read(filename, encoding: "UTF-8")
|
88
97
|
stylesheet = populate_template(stylesheet, :word)
|
89
|
-
stylesheet.gsub!(/(\s|\{)mso-[^:]+:[^;]+;/m,
|
90
|
-
if File.extname(filename) ==
|
98
|
+
stylesheet.gsub!(/(\s|\{)mso-[^:]+:[^;]+;/m, "\\1") if stripwordcss
|
99
|
+
if File.extname(filename) == ".scss"
|
91
100
|
stylesheet = convert_scss(filename, stylesheet, stripwordcss)
|
92
101
|
end
|
93
|
-
Tempfile.open([File.basename(filename,
|
94
|
-
encoding:
|
102
|
+
Tempfile.open([File.basename(filename, ".*"), "css"],
|
103
|
+
encoding: "utf-8") do |f|
|
95
104
|
f.write(stylesheet)
|
96
105
|
f
|
97
106
|
end
|
@@ -4,6 +4,16 @@ module IsoDoc::Function
|
|
4
4
|
module Blocks
|
5
5
|
@annotation = false
|
6
6
|
|
7
|
+
def middle_title(_isoxml, out)
|
8
|
+
out.p(**{ class: "zzSTDTitle1" }) { |p| p << @meta.get[:doctitle] }
|
9
|
+
end
|
10
|
+
|
11
|
+
def middle_admonitions(isoxml, out)
|
12
|
+
isoxml.xpath(ns("//sections/note | //sections/admonition")).each do |x|
|
13
|
+
parse(x, out)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
7
17
|
def figure_name_parse(node, div, name)
|
8
18
|
return if name.nil?
|
9
19
|
div.p **{ class: "FigureTitle", style: "text-align:center;" } do |p|
|
@@ -24,6 +34,7 @@ module IsoDoc::Function
|
|
24
34
|
def figure_parse(node, out)
|
25
35
|
return pseudocode_parse(node, out) if node["class"] == "pseudocode" ||
|
26
36
|
node["type"] == "pseudocode"
|
37
|
+
|
27
38
|
@in_figure = true
|
28
39
|
out.div **figure_attrs(node) do |div|
|
29
40
|
node.children.each do |n|
|
@@ -51,6 +62,7 @@ module IsoDoc::Function
|
|
51
62
|
|
52
63
|
def sourcecode_name_parse(node, div, name)
|
53
64
|
return if name.nil?
|
65
|
+
|
54
66
|
div.p **{ class: "SourceTitle", style: "text-align:center;" } do |p|
|
55
67
|
name.children.each { |n| parse(n, p) }
|
56
68
|
end
|
@@ -91,14 +103,15 @@ module IsoDoc::Function
|
|
91
103
|
@annotation = false
|
92
104
|
end
|
93
105
|
|
94
|
-
def admonition_class(
|
106
|
+
def admonition_class(_node)
|
95
107
|
"Admonition"
|
96
108
|
end
|
97
109
|
|
98
110
|
def admonition_name(node, type)
|
99
111
|
name = node&.at(ns("./name")) and return name
|
100
|
-
name = Nokogiri::XML::Node.new(
|
112
|
+
name = Nokogiri::XML::Node.new("name", node.document)
|
101
113
|
return unless type && @i18n.admonition[type]
|
114
|
+
|
102
115
|
name << @i18n.admonition[type]&.upcase
|
103
116
|
name
|
104
117
|
end
|
@@ -119,7 +132,8 @@ module IsoDoc::Function
|
|
119
132
|
|
120
133
|
def formula_where(dl, out)
|
121
134
|
return unless dl
|
122
|
-
|
135
|
+
|
136
|
+
out.p **{ style: "page-break-after:avoid;" } do |p|
|
123
137
|
p << @i18n.where
|
124
138
|
end
|
125
139
|
parse(dl, out)
|
@@ -148,6 +162,7 @@ module IsoDoc::Function
|
|
148
162
|
formula_where(node.at(ns("./dl")), div)
|
149
163
|
node.children.each do |n|
|
150
164
|
next if %w(stem dl name).include? n.name
|
165
|
+
|
151
166
|
parse(n, div)
|
152
167
|
end
|
153
168
|
end
|
@@ -182,6 +197,7 @@ module IsoDoc::Function
|
|
182
197
|
author = node.at(ns("./author"))
|
183
198
|
source = node.at(ns("./source"))
|
184
199
|
return if author.nil? && source.nil?
|
200
|
+
|
185
201
|
out.p **{ class: "QuoteAttribution" } do |p|
|
186
202
|
p << "— #{author.text}" if author
|
187
203
|
p << ", " if author && source
|
@@ -201,8 +217,9 @@ module IsoDoc::Function
|
|
201
217
|
end
|
202
218
|
|
203
219
|
def passthrough_parse(node, out)
|
204
|
-
return if node["format"]
|
220
|
+
return if node["format"] &&
|
205
221
|
!(node["format"].split(/,/).include? @format.to_s)
|
222
|
+
|
206
223
|
out.passthrough node.text
|
207
224
|
end
|
208
225
|
|
@@ -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
|
@@ -1,16 +1,17 @@
|
|
1
1
|
module IsoDoc::Function
|
2
2
|
module Cleanup
|
3
3
|
def textcleanup(docxml)
|
4
|
-
|
4
|
+
termref_cleanup(passthrough_cleanup(docxml))
|
5
5
|
end
|
6
6
|
|
7
7
|
def termref_cleanup(docxml)
|
8
|
-
docxml
|
9
|
-
gsub(/\s*\[MODIFICATION\]\s*\[\/TERMREF\]/,
|
10
|
-
|
11
|
-
gsub(
|
12
|
-
gsub(
|
13
|
-
gsub(
|
8
|
+
docxml
|
9
|
+
.gsub(/\s*\[MODIFICATION\]\s*\[\/TERMREF\]/,
|
10
|
+
l10n(", #{@i18n.modified} [/TERMREF]"))
|
11
|
+
.gsub(%r{\s*\[/TERMREF\]\s*</p>\s*<p>\s*\[TERMREF\]}, "; ")
|
12
|
+
.gsub(/\[TERMREF\]\s*/, l10n("[#{@i18n.source}: "))
|
13
|
+
.gsub(%r{\s*\[/TERMREF\]\s*}, l10n("]"))
|
14
|
+
.gsub(/\s*\[MODIFICATION\]/, l10n(", #{@i18n.modified} — "))
|
14
15
|
end
|
15
16
|
|
16
17
|
def passthrough_cleanup(docxml)
|
@@ -21,7 +22,7 @@ module IsoDoc::Function
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def cleanup(docxml)
|
24
|
-
@i18n ||= i18n_init(@lang, @script)
|
25
|
+
@i18n ||= i18n_init(@lang, @script)
|
25
26
|
comment_cleanup(docxml)
|
26
27
|
footnote_cleanup(docxml)
|
27
28
|
inline_header_cleanup(docxml)
|
@@ -34,30 +35,36 @@ module IsoDoc::Function
|
|
34
35
|
|
35
36
|
def table_long_strings_cleanup(docxml)
|
36
37
|
return unless @break_up_urls_in_tables == true
|
38
|
+
|
37
39
|
docxml.xpath("//td | //th").each do |d|
|
38
40
|
d.traverse do |n|
|
39
41
|
next unless n.text?
|
42
|
+
|
40
43
|
n.replace(HTMLEntities.new.encode(
|
41
|
-
|
44
|
+
break_up_long_strings(n.text),
|
45
|
+
))
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
46
|
-
def break_up_long_strings(
|
47
|
-
return
|
48
|
-
|
49
|
-
|
50
|
+
def break_up_long_strings(text)
|
51
|
+
return text if /^\s*$/.match?(text)
|
52
|
+
|
53
|
+
text.split(/(?=\s)/).map do |w|
|
54
|
+
if /^\s*$/.match(text) || (w.size < 30) then w
|
55
|
+
else
|
50
56
|
w.scan(/.{,30}/).map do |w1|
|
51
|
-
|
52
|
-
|
57
|
+
w1.size < 30 ? w1 : break_up_long_strings1(w1)
|
58
|
+
end.join
|
59
|
+
end
|
53
60
|
end.join
|
54
61
|
end
|
55
62
|
|
56
|
-
def break_up_long_strings1(
|
57
|
-
s =
|
58
|
-
if s.size == 1 then
|
63
|
+
def break_up_long_strings1(text)
|
64
|
+
s = text.split(%r{(?<=[,.?+;/=])})
|
65
|
+
if s.size == 1 then "#{text} "
|
59
66
|
else
|
60
|
-
s[-1] = "
|
67
|
+
s[-1] = " #{s[-1]}"
|
61
68
|
s.join
|
62
69
|
end
|
63
70
|
end
|
@@ -78,11 +85,11 @@ module IsoDoc::Function
|
|
78
85
|
docxml
|
79
86
|
end
|
80
87
|
|
81
|
-
def figure_get_or_make_dl(
|
82
|
-
dl =
|
88
|
+
def figure_get_or_make_dl(elem)
|
89
|
+
dl = elem.at(".//dl")
|
83
90
|
if dl.nil?
|
84
|
-
|
85
|
-
dl =
|
91
|
+
elem.add_child("<p><b>#{@i18n.key}</b></p><dl></dl>")
|
92
|
+
dl = elem.at(".//dl")
|
86
93
|
end
|
87
94
|
dl
|
88
95
|
end
|
@@ -91,10 +98,10 @@ module IsoDoc::Function
|
|
91
98
|
"//div[@class = 'figure'][descendant::aside]"\
|
92
99
|
"[not(descendant::div[@class = 'figure'])]".freeze
|
93
100
|
|
94
|
-
def figure_aside_process(
|
101
|
+
def figure_aside_process(elem, aside, key)
|
95
102
|
# get rid of footnote link, it is in diagram
|
96
|
-
|
97
|
-
fnref =
|
103
|
+
elem&.at("./a[@class='TableFootnoteRef']")&.remove
|
104
|
+
fnref = elem.at(".//span[@class='TableFootnoteRef']/..")
|
98
105
|
dt = key.add_child("<dt></dt>").first
|
99
106
|
dd = key.add_child("<dd></dd>").first
|
100
107
|
fnref.parent = dt
|
@@ -109,6 +116,7 @@ module IsoDoc::Function
|
|
109
116
|
def figure_cleanup(docxml)
|
110
117
|
docxml.xpath(FIGURE_WITH_FOOTNOTES).each do |f|
|
111
118
|
next unless f.at(".//aside[not(ancestor::p[@class = 'FigureTitle'])]")
|
119
|
+
|
112
120
|
key = figure_get_or_make_dl(f)
|
113
121
|
f.xpath(".//aside").each do |aside|
|
114
122
|
figure_aside_process(f, aside, key)
|
@@ -137,12 +145,13 @@ module IsoDoc::Function
|
|
137
145
|
docxml
|
138
146
|
end
|
139
147
|
|
140
|
-
def merge_fnref_into_fn_text(
|
141
|
-
fn =
|
148
|
+
def merge_fnref_into_fn_text(elem)
|
149
|
+
fn = elem.at('.//span[@class="TableFootnoteRef"]/..')
|
142
150
|
n = fn.next_element
|
143
151
|
n&.children&.first&.add_previous_sibling(fn.remove)
|
144
152
|
end
|
145
153
|
|
154
|
+
# preempt html2doc putting MsoNormal under TableFootnote class
|
146
155
|
def table_footnote_cleanup(docxml)
|
147
156
|
docxml.xpath("//table[descendant::aside]").each do |t|
|
148
157
|
t.xpath(".//aside").each do |a|
|
@@ -152,36 +161,36 @@ module IsoDoc::Function
|
|
152
161
|
t << a.remove
|
153
162
|
end
|
154
163
|
end
|
155
|
-
# preempt html2doc putting MsoNormal there
|
156
164
|
docxml.xpath("//p[not(self::*[@class])]"\
|
157
165
|
"[ancestor::*[@class = 'TableFootnote']]").each do |p|
|
158
166
|
p["class"] = "TableFootnote"
|
159
167
|
end
|
160
168
|
end
|
161
169
|
|
162
|
-
def remove_bottom_border(
|
163
|
-
|
164
|
-
|
170
|
+
def remove_bottom_border(cell)
|
171
|
+
cell["style"] =
|
172
|
+
cell["style"].gsub(/border-bottom:[^;]+;/, "border-bottom:0pt;")
|
165
173
|
end
|
166
174
|
|
167
|
-
def table_get_or_make_tfoot(
|
168
|
-
tfoot =
|
175
|
+
def table_get_or_make_tfoot(table)
|
176
|
+
tfoot = table.at(".//tfoot")
|
169
177
|
if tfoot.nil?
|
170
|
-
|
171
|
-
tfoot =
|
178
|
+
table.add_child("<tfoot></tfoot>")
|
179
|
+
tfoot = table.at(".//tfoot")
|
172
180
|
else
|
173
181
|
tfoot.xpath(".//td | .//th").each { |td| remove_bottom_border(td) }
|
174
182
|
end
|
175
183
|
tfoot
|
176
184
|
end
|
177
185
|
|
178
|
-
def new_fullcolspan_row(
|
186
|
+
def new_fullcolspan_row(table, tfoot)
|
179
187
|
# how many columns in the table?
|
180
188
|
cols = 0
|
181
|
-
|
189
|
+
table.at(".//tr").xpath("./td | ./th").each do |td|
|
182
190
|
cols += (td["colspan"] ? td["colspan"].to_i : 1)
|
183
191
|
end
|
184
|
-
style =
|
192
|
+
style =
|
193
|
+
%{border-top:0pt;border-bottom:#{IsoDoc::Function::Table::SW} 1.5pt;}
|
185
194
|
tfoot.add_child("<tr><td colspan='#{cols}' style='#{style}'/></tr>")
|
186
195
|
tfoot.xpath(".//td").last
|
187
196
|
end
|
@@ -204,15 +213,14 @@ module IsoDoc::Function
|
|
204
213
|
docxml
|
205
214
|
end
|
206
215
|
|
207
|
-
def symbols_cleanup(docxml)
|
208
|
-
end
|
216
|
+
def symbols_cleanup(docxml); end
|
209
217
|
|
210
|
-
def table_footnote_reference_format(
|
211
|
-
|
218
|
+
def table_footnote_reference_format(link)
|
219
|
+
link
|
212
220
|
end
|
213
221
|
|
214
|
-
def footnote_reference_format(
|
215
|
-
|
222
|
+
def footnote_reference_format(link)
|
223
|
+
link
|
216
224
|
end
|
217
225
|
end
|
218
226
|
end
|