isodoc 1.6.4 → 1.7.0
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 +1 -1
- data/isodoc.gemspec +2 -1
- data/lib/isodoc-yaml/i18n-ar.yaml +19 -25
- data/lib/isodoc-yaml/i18n-de.yaml +1 -0
- data/lib/isodoc-yaml/i18n-en.yaml +2 -0
- data/lib/isodoc-yaml/i18n-es.yaml +1 -0
- data/lib/isodoc-yaml/i18n-fr.yaml +2 -0
- data/lib/isodoc-yaml/i18n-ru.yaml +1 -0
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +2 -0
- data/lib/isodoc/convert.rb +4 -2
- data/lib/isodoc/function/blocks.rb +6 -5
- data/lib/isodoc/function/references.rb +33 -52
- data/lib/isodoc/function/section.rb +0 -1
- data/lib/isodoc/function/table.rb +21 -22
- data/lib/isodoc/function/terms.rb +6 -7
- data/lib/isodoc/gem_tasks.rb +8 -9
- data/lib/isodoc/html_convert.rb +5 -1
- data/lib/isodoc/html_function/comments.rb +12 -12
- data/lib/isodoc/html_function/html.rb +2 -2
- data/lib/isodoc/html_function/postprocess.rb +195 -185
- data/lib/isodoc/html_function/sectionsplit.rb +244 -0
- data/lib/isodoc/metadata.rb +22 -20
- data/lib/isodoc/metadata_contributor.rb +31 -28
- data/lib/isodoc/presentation_function/bibdata.rb +7 -0
- data/lib/isodoc/presentation_function/block.rb +7 -4
- data/lib/isodoc/presentation_function/inline.rb +7 -12
- data/lib/isodoc/presentation_function/section.rb +38 -1
- data/lib/isodoc/presentation_xml_convert.rb +2 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/xref.rb +10 -7
- data/lib/isodoc/xref/xref_anchor.rb +45 -44
- data/lib/isodoc/xref/xref_counter.rb +113 -103
- data/lib/isodoc/xref/xref_gen.rb +39 -11
- data/spec/isodoc/blocks_spec.rb +184 -447
- data/spec/isodoc/cleanup_spec.rb +40 -42
- data/spec/isodoc/i18n_spec.rb +694 -821
- data/spec/isodoc/inline_spec.rb +197 -208
- data/spec/isodoc/metadata_spec.rb +384 -379
- data/spec/isodoc/postproc_spec.rb +121 -30
- data/spec/isodoc/presentation_xml_spec.rb +4 -4
- data/spec/isodoc/ref_spec.rb +5 -5
- data/spec/isodoc/section_spec.rb +216 -199
- data/spec/isodoc/sectionsplit_spec.rb +190 -0
- data/spec/isodoc/table_spec.rb +41 -42
- data/spec/isodoc/terms_spec.rb +1 -1
- data/spec/isodoc/xref_spec.rb +684 -1020
- metadata +19 -3
@@ -1,17 +1,16 @@
|
|
1
1
|
module IsoDoc::Function
|
2
2
|
module Table
|
3
|
-
|
4
3
|
def table_title_parse(node, out)
|
5
4
|
name = node.at(ns("./name")) or return
|
6
5
|
out.p **{ class: "TableTitle", style: "text-align:center;" } do |p|
|
7
|
-
name
|
6
|
+
name&.children&.each { |n| parse(n, p) }
|
8
7
|
end
|
9
8
|
end
|
10
9
|
|
11
|
-
def thead_parse(node,
|
10
|
+
def thead_parse(node, table)
|
12
11
|
thead = node.at(ns("./thead"))
|
13
12
|
if thead
|
14
|
-
|
13
|
+
table.thead do |h|
|
15
14
|
thead.element_children.each_with_index do |n, i|
|
16
15
|
tr_parse(n, h, i, thead.element_children.size, true)
|
17
16
|
end
|
@@ -19,19 +18,19 @@ module IsoDoc::Function
|
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
|
-
def tbody_parse(node,
|
21
|
+
def tbody_parse(node, table)
|
23
22
|
tbody = node.at(ns("./tbody")) || return
|
24
|
-
|
23
|
+
table.tbody do |h|
|
25
24
|
tbody.element_children.each_with_index do |n, i|
|
26
25
|
tr_parse(n, h, i, tbody.element_children.size, false)
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
31
|
-
def tfoot_parse(node,
|
30
|
+
def tfoot_parse(node, table)
|
32
31
|
tfoot = node.at(ns("./tfoot"))
|
33
32
|
if tfoot
|
34
|
-
|
33
|
+
table.tfoot do |h|
|
35
34
|
tfoot.element_children.each_with_index do |n, i|
|
36
35
|
tr_parse(n, h, i, tfoot.element_children.size, false)
|
37
36
|
end
|
@@ -45,23 +44,23 @@ module IsoDoc::Function
|
|
45
44
|
id: node["id"],
|
46
45
|
class: "MsoISOTable",
|
47
46
|
style: "border-width:1px;border-spacing:0;#{width}#{keep_style(node)}",
|
48
|
-
title: node["alt"]
|
47
|
+
title: node["alt"],
|
49
48
|
)
|
50
49
|
end
|
51
50
|
|
52
|
-
def tcaption(node,
|
51
|
+
def tcaption(node, table)
|
53
52
|
return unless node["summary"]
|
54
53
|
|
55
|
-
|
54
|
+
table.caption do |c|
|
56
55
|
c.span **{ style: "display:none" } do |s|
|
57
56
|
s << node["summary"]
|
58
57
|
end
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
62
|
-
def colgroup(node,
|
61
|
+
def colgroup(node, table)
|
63
62
|
colgroup = node.at(ns("./colgroup")) or return
|
64
|
-
|
63
|
+
table.colgroup do |cg|
|
65
64
|
colgroup.xpath(ns("./col")).each do |c|
|
66
65
|
cg.col **{ style: "width: #{c['width']};" }
|
67
66
|
end
|
@@ -90,19 +89,19 @@ module IsoDoc::Function
|
|
90
89
|
# border-left:#{col.zero? ? "#{SW} 1.5pt;" : "none;"}
|
91
90
|
# border-right:#{SW} #{col == totalcols && !header ? "1.5" : "1.0"}pt;
|
92
91
|
|
93
|
-
def make_tr_attr(
|
94
|
-
style =
|
95
|
-
|
96
|
-
|
97
|
-
rowmax =
|
92
|
+
def make_tr_attr(cell, row, totalrows, header)
|
93
|
+
style = cell.name == "th" ? "font-weight:bold;" : ""
|
94
|
+
cell["align"] and style += "text-align:#{cell['align']};"
|
95
|
+
cell["valign"] and style += "vertical-align:#{cell['valign']};"
|
96
|
+
rowmax = cell["rowspan"] ? row + cell["rowspan"].to_i - 1 : row
|
98
97
|
style += <<~STYLE
|
99
98
|
border-top:#{row.zero? ? "#{SW} 1.5pt;" : 'none;'}
|
100
99
|
border-bottom:#{SW} #{rowmax == totalrows ? '1.5' : '1.0'}pt;
|
101
100
|
STYLE
|
102
|
-
header and scope = (
|
103
|
-
!header and
|
104
|
-
|
105
|
-
{ rowspan:
|
101
|
+
header and scope = (cell["colspan"] ? "colgroup" : "col")
|
102
|
+
!header and cell.name == "th" and scope =
|
103
|
+
(cell["rowspan"] ? "rowgroup" : "row")
|
104
|
+
{ rowspan: cell["rowspan"], colspan: cell["colspan"],
|
106
105
|
style: style.gsub(/\n/, ""), scope: scope }
|
107
106
|
end
|
108
107
|
|
@@ -11,27 +11,27 @@ module IsoDoc::Function
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def deprecated_term_parse(node, out)
|
14
|
-
out.p **{ class: "DeprecatedTerms", style:"text-align:left;" } do |p|
|
14
|
+
out.p **{ class: "DeprecatedTerms", style: "text-align:left;" } do |p|
|
15
15
|
p << l10n("#{@i18n.deprecated}: ")
|
16
16
|
node.children.each { |c| parse(c, p) }
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def admitted_term_parse(node, out)
|
21
|
-
out.p **{ class: "AltTerms", style:"text-align:left;" } do |p|
|
21
|
+
out.p **{ class: "AltTerms", style: "text-align:left;" } do |p|
|
22
22
|
node.children.each { |c| parse(c, p) }
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
def term_parse(node, out)
|
27
|
-
out.p **{ class: "Terms", style:"text-align:left;" } do |p|
|
27
|
+
out.p **{ class: "Terms", style: "text-align:left;" } do |p|
|
28
28
|
node.children.each { |c| parse(c, p) }
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def para_then_remainder(first, node,
|
32
|
+
def para_then_remainder(first, node, para, div)
|
33
33
|
if first.name == "p"
|
34
|
-
first.children.each { |n| parse(n,
|
34
|
+
first.children.each { |n| parse(n, para) }
|
35
35
|
node.elements.drop(1).each { |n| parse(n, div) }
|
36
36
|
else
|
37
37
|
node.elements.each { |n| parse(n, div) }
|
@@ -72,7 +72,6 @@ module IsoDoc::Function
|
|
72
72
|
node.children.each { |n| parse(n, out) }
|
73
73
|
end
|
74
74
|
|
75
|
-
def termdocsource_parse(_node, _out)
|
76
|
-
end
|
75
|
+
def termdocsource_parse(_node, _out); end
|
77
76
|
end
|
78
77
|
end
|
data/lib/isodoc/gem_tasks.rb
CHANGED
@@ -12,12 +12,10 @@ module IsoDoc
|
|
12
12
|
|
13
13
|
def install
|
14
14
|
rule ".css" => [proc { |tn| tn.sub(/\.css$/, ".scss") }] do |current_task|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
notify_borken_compilation(e, current_task)
|
20
|
-
end
|
15
|
+
puts(current_task)
|
16
|
+
compile_scss_task(current_task)
|
17
|
+
rescue StandardError => e
|
18
|
+
notify_borken_compilation(e, current_task)
|
21
19
|
end
|
22
20
|
|
23
21
|
scss_files = Rake::FileList["lib/**/*.scss"]
|
@@ -88,7 +86,7 @@ module IsoDoc
|
|
88
86
|
text
|
89
87
|
.gsub("/* LIQUID_COMMENT", "")
|
90
88
|
.gsub("LIQUID_COMMENT */", "")
|
91
|
-
.gsub('"{{',
|
89
|
+
.gsub('"{{', "{{").gsub('}}"', "}}")
|
92
90
|
end
|
93
91
|
|
94
92
|
def fonts_placeholder
|
@@ -107,7 +105,8 @@ module IsoDoc
|
|
107
105
|
require "sassc"
|
108
106
|
|
109
107
|
isodoc_path = if Gem.loaded_specs["isodoc"]
|
110
|
-
File.join(Gem.loaded_specs["isodoc"].full_gem_path,
|
108
|
+
File.join(Gem.loaded_specs["isodoc"].full_gem_path,
|
109
|
+
"lib", "isodoc")
|
111
110
|
else
|
112
111
|
File.join("lib", "isodoc")
|
113
112
|
end
|
@@ -119,7 +118,7 @@ module IsoDoc
|
|
119
118
|
SassC::Engine.new(fonts_placeholder + sheet_content,
|
120
119
|
syntax: :scss,
|
121
120
|
importer: SasscImporter)
|
122
|
-
|
121
|
+
.render
|
123
122
|
end
|
124
123
|
|
125
124
|
def compile_scss_task(current_task)
|
data/lib/isodoc/html_convert.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require_relative "html_function/comments"
|
2
2
|
require_relative "html_function/footnotes"
|
3
3
|
require_relative "html_function/html"
|
4
|
-
require_relative "html_function/form"
|
5
4
|
require_relative "html_function/postprocess"
|
5
|
+
require_relative "html_function/sectionsplit"
|
6
|
+
require_relative "html_function/form"
|
6
7
|
|
7
8
|
module IsoDoc
|
8
9
|
class HtmlConvert < ::IsoDoc::Convert
|
@@ -23,6 +24,9 @@ module IsoDoc
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def convert(filename, file = nil, debug = false, output_filename = nil)
|
27
|
+
@sectionsplit and
|
28
|
+
return sectionsplit_convert(filename, file, debug, output_filename)
|
29
|
+
|
26
30
|
ret = super
|
27
31
|
Dir.exists?(tmpimagedir) and Dir["#{tmpimagedir}/*"].empty? and
|
28
32
|
FileUtils.rm_r tmpimagedir
|
@@ -24,16 +24,16 @@ module IsoDoc::HtmlFunction
|
|
24
24
|
=end
|
25
25
|
end
|
26
26
|
|
27
|
-
def comment_link_attrs(
|
28
|
-
{ style: "MsoCommentReference", target:
|
27
|
+
def comment_link_attrs(fnote, node)
|
28
|
+
{ style: "MsoCommentReference", target: fnote,
|
29
29
|
class: "commentLink", from: node["from"],
|
30
30
|
to: node["to"] }
|
31
31
|
end
|
32
32
|
|
33
33
|
# add in from and to links to move the comment into place
|
34
|
-
def make_comment_link(out,
|
35
|
-
out.span(**comment_link_attrs(
|
36
|
-
s1.a **{ style: "mso-comment-reference:SMC_#{
|
34
|
+
def make_comment_link(out, fnote, node)
|
35
|
+
out.span(**comment_link_attrs(fnote, node)) do |s1|
|
36
|
+
s1.a **{ style: "mso-comment-reference:SMC_#{fnote};"\
|
37
37
|
"mso-comment-date:#{node['date'].gsub(/[-:Z]/, '')}" }
|
38
38
|
end
|
39
39
|
end
|
@@ -44,9 +44,9 @@ module IsoDoc::HtmlFunction
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def make_comment_text(node,
|
47
|
+
def make_comment_text(node, fnote)
|
48
48
|
noko do |xml|
|
49
|
-
xml.div **{ style: "mso-element:comment", id:
|
49
|
+
xml.div **{ style: "mso-element:comment", id: fnote } do |div|
|
50
50
|
div.span **{ style: %{mso-comment-author:"#{node['reviewer']}"} }
|
51
51
|
make_comment_target(div)
|
52
52
|
node.children.each { |n| parse(n, div) }
|
@@ -99,13 +99,13 @@ module IsoDoc::HtmlFunction
|
|
99
99
|
from["style"] != "mso-special-character:comment"
|
100
100
|
end
|
101
101
|
|
102
|
-
def insert_comment_cont(from,
|
103
|
-
# includes_to = from.at(".//*[@id='#{
|
104
|
-
while !from.nil? && from["id"] !=
|
102
|
+
def insert_comment_cont(from, upto, target)
|
103
|
+
# includes_to = from.at(".//*[@id='#{upto}']")
|
104
|
+
while !from.nil? && from["id"] != upto
|
105
105
|
following = from.xpath("./following::*")
|
106
|
-
(from = following.shift) && incl_to = from.at(".//*[@id='#{
|
106
|
+
(from = following.shift) && incl_to = from.at(".//*[@id='#{upto}']")
|
107
107
|
while !incl_to.nil? && !from.nil? && skip_comment_wrap(from)
|
108
|
-
(from = following.shift) && incl_to = from.at(".//*[@id='#{
|
108
|
+
(from = following.shift) && incl_to = from.at(".//*[@id='#{upto}']")
|
109
109
|
end
|
110
110
|
wrap_comment_cont(from, target) if !from.nil?
|
111
111
|
end
|
@@ -64,8 +64,8 @@ module IsoDoc::HtmlFunction
|
|
64
64
|
<script type="text/javascript">#{toclevel}</script>
|
65
65
|
|
66
66
|
<!--Google fonts-->
|
67
|
-
|
68
|
-
|
67
|
+
<link rel="preconnect" href="https://fonts.gstatic.com">#{' '}
|
68
|
+
#{googlefonts}
|
69
69
|
<!--Font awesome import for the link icon-->
|
70
70
|
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" crossorigin="anonymous">
|
71
71
|
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css" integrity="sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P" crossorigin="anonymous">
|
@@ -1,227 +1,237 @@
|
|
1
1
|
require "isodoc/html_function/mathvariant_to_plain"
|
2
2
|
require_relative "postprocess_footnotes"
|
3
3
|
|
4
|
-
module IsoDoc
|
5
|
-
module
|
6
|
-
|
7
|
-
result
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
module IsoDoc
|
5
|
+
module HtmlFunction
|
6
|
+
module Html
|
7
|
+
def postprocess(result, filename, _dir)
|
8
|
+
result = from_xhtml(cleanup(to_xhtml(textcleanup(result))))
|
9
|
+
toHTML(result, filename)
|
10
|
+
@files_to_delete.each { |f| FileUtils.rm_rf f }
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
def script_cdata(result)
|
14
|
+
result.gsub(%r{<script([^>]*)>\s*<!\[CDATA\[}m, "<script\\1>")
|
15
|
+
.gsub(%r{\]\]>\s*</script>}, "</script>")
|
16
|
+
.gsub(%r{<!\[CDATA\[\s*<script([^>]*)>}m, "<script\\1>")
|
17
|
+
.gsub(%r{</script>\s*\]\]>}, "</script>")
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
20
|
+
def toHTML(result, filename)
|
21
|
+
result = from_xhtml(html_cleanup(to_xhtml(result)))
|
22
|
+
result = from_xhtml(move_images(to_xhtml(result)))
|
23
|
+
result = html5(script_cdata(inject_script(result)))
|
24
|
+
File.open(filename, "w:UTF-8") { |f| f.write(result) }
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
def html5(doc)
|
28
|
+
doc.sub(%r{<!DOCTYPE html [^>]+>}, "<!DOCTYPE html>")
|
29
|
+
.sub(%r{<\?xml[^>]+>}, "")
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
footnote_format(
|
35
|
-
|
36
|
-
|
37
|
-
term_header(html_footnote_filter(html_preface(htmlstyle(html)))),
|
38
|
-
),
|
39
|
-
),
|
40
|
-
),
|
41
|
-
)
|
42
|
-
end
|
32
|
+
def html_cleanup(html)
|
33
|
+
html = term_header(html_footnote_filter(html_preface(htmlstyle(html))))
|
34
|
+
html = footnote_format(footnote_backlinks(html_toc(html)))
|
35
|
+
mathml(html_list_clean(remove_placeholder_paras(html)))
|
36
|
+
end
|
43
37
|
|
44
|
-
|
45
|
-
|
46
|
-
|
38
|
+
def remove_placeholder_paras(html)
|
39
|
+
%w(title-section prefatory-section).each do |s|
|
40
|
+
html&.at("//div[@class = '#{s}']/p[last()]")&.remove
|
41
|
+
end
|
42
|
+
html
|
43
|
+
end
|
47
44
|
|
48
|
-
|
49
|
-
|
45
|
+
def html_list_clean(html)
|
46
|
+
html.xpath("//ol/div | //ul/div").each do |div|
|
47
|
+
li = div&.xpath("./preceding-sibling::li")&.last ||
|
48
|
+
div.at("./following-sibling::li")
|
49
|
+
div.parent = li
|
50
|
+
end
|
51
|
+
html
|
52
|
+
end
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
xml.children.first << Nokogiri::XML::Comment.new(xml, "\n#{stylesheet}\n")
|
55
|
-
file.close
|
56
|
-
file.unlink if file.is_a?(Tempfile)
|
57
|
-
xml.root.to_s
|
58
|
-
end
|
54
|
+
def mathml(docxml)
|
55
|
+
IsoDoc::HtmlFunction::MathvariantToPlain.new(docxml).convert
|
56
|
+
end
|
59
57
|
|
60
|
-
|
61
|
-
|
58
|
+
def htmlstylesheet(file)
|
59
|
+
return if file.nil?
|
60
|
+
|
61
|
+
file.open if file.is_a?(Tempfile)
|
62
|
+
stylesheet = file.read
|
63
|
+
xml = Nokogiri::XML("<style/>")
|
64
|
+
xml.children.first << Nokogiri::XML::Comment
|
65
|
+
.new(xml, "\n#{stylesheet}\n")
|
66
|
+
file.close
|
67
|
+
file.unlink if file.is_a?(Tempfile)
|
68
|
+
xml.root.to_s
|
69
|
+
end
|
62
70
|
|
63
|
-
|
64
|
-
|
65
|
-
s = htmlstylesheet(@htmlstylesheet_override) and head << s
|
66
|
-
docxml
|
67
|
-
end
|
71
|
+
def htmlstyle(docxml)
|
72
|
+
return docxml unless @htmlstylesheet
|
68
73
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
html_main(docxml)
|
75
|
-
authority_cleanup(docxml)
|
76
|
-
docxml
|
77
|
-
end
|
74
|
+
head = docxml.at("//*[local-name() = 'head']")
|
75
|
+
head << htmlstylesheet(@htmlstylesheet)
|
76
|
+
s = htmlstylesheet(@htmlstylesheet_override) and head << s
|
77
|
+
docxml
|
78
|
+
end
|
78
79
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
80
|
+
def html_preface(docxml)
|
81
|
+
html_cover(docxml) if @htmlcoverpage && !@bare
|
82
|
+
html_intro(docxml) if @htmlintropage && !@bare
|
83
|
+
docxml.at("//body") << mathjax(@openmathdelim, @closemathdelim)
|
84
|
+
docxml.at("//body") << sourcecode_highlighter
|
85
|
+
html_main(docxml)
|
86
|
+
authority_cleanup(docxml)
|
87
|
+
docxml
|
88
|
+
end
|
87
89
|
|
88
|
-
|
89
|
-
|
90
|
-
|
90
|
+
def authority_cleanup1(docxml, klass)
|
91
|
+
dest = docxml.at("//div[@id = 'boilerplate-#{klass}-destination']")
|
92
|
+
auth = docxml.at("//div[@id = 'boilerplate-#{klass}' or "\
|
93
|
+
"@class = 'boilerplate-#{klass}']")
|
94
|
+
auth&.xpath(".//h1[not(text())] | .//h2[not(text())]")&.each(&:remove)
|
95
|
+
auth&.xpath(".//h1 | .//h2")&.each { |h| h["class"] = "IntroTitle" }
|
96
|
+
dest and auth and dest.replace(auth.remove)
|
91
97
|
end
|
92
|
-
end
|
93
98
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
populate_template(doc.to_xml(encoding: "US-ASCII"), :html),
|
100
|
-
)
|
101
|
-
end
|
99
|
+
def authority_cleanup(docxml)
|
100
|
+
%w(copyright license legal feedback).each do |t|
|
101
|
+
authority_cleanup1(docxml, t)
|
102
|
+
end
|
103
|
+
end
|
102
104
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
end
|
105
|
+
def html_cover(docxml)
|
106
|
+
doc = to_xhtml_fragment(File.read(@htmlcoverpage, encoding: "UTF-8"))
|
107
|
+
d = docxml.at('//div[@class="title-section"]')
|
108
|
+
d.children.first.add_previous_sibling(
|
109
|
+
populate_template(doc.to_xml(encoding: "US-ASCII"), :html),
|
110
|
+
)
|
111
|
+
end
|
111
112
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
113
|
+
def html_intro(docxml)
|
114
|
+
doc = to_xhtml_fragment(File.read(@htmlintropage, encoding: "UTF-8"))
|
115
|
+
d = docxml.at('//div[@class="prefatory-section"]')
|
116
|
+
d.children.first.add_previous_sibling(
|
117
|
+
populate_template(doc.to_xml(encoding: "US-ASCII"), :html),
|
118
|
+
)
|
119
|
+
end
|
116
120
|
|
117
|
-
|
118
|
-
|
119
|
-
|
121
|
+
def html_toc_entry(level, header)
|
122
|
+
%(<li class="#{level}"><a href="##{header['id']}">\
|
123
|
+
#{header_strip(header)}</a></li>)
|
124
|
+
end
|
120
125
|
|
121
|
-
|
122
|
-
|
123
|
-
"#{l}:not(:empty):not(.TermNum):not(.noTOC)"
|
126
|
+
def toclevel_classes
|
127
|
+
(1..@htmlToClevels).reduce([]) { |m, i| m << "h#{i}" }
|
124
128
|
end
|
125
|
-
<<~HEAD.freeze
|
126
|
-
function toclevel() { return "#{ret.join(',')}";}
|
127
|
-
HEAD
|
128
|
-
end
|
129
129
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
130
|
+
def toclevel
|
131
|
+
ret = toclevel_classes.map do |l|
|
132
|
+
"#{l}:not(:empty):not(.TermNum):not(.noTOC)"
|
133
|
+
end
|
134
|
+
<<~HEAD.freeze
|
135
|
+
function toclevel() { return "#{ret.join(',')}";}
|
136
|
+
HEAD
|
136
137
|
end
|
137
|
-
|
138
|
-
|
139
|
-
|
138
|
+
|
139
|
+
# needs to be same output as toclevel
|
140
|
+
def html_toc(docxml)
|
141
|
+
idx = docxml.at("//div[@id = 'toc']") or return docxml
|
142
|
+
toc = "<ul>"
|
143
|
+
path = toclevel_classes.map do |l|
|
144
|
+
"//main//#{l}[not(@class = 'TermNum')][not(@class = 'noTOC')][text()]"
|
145
|
+
end
|
146
|
+
docxml.xpath(path.join(" | ")).each_with_index do |h, tocidx|
|
147
|
+
h["id"] ||= "toc#{tocidx}"
|
148
|
+
toc += html_toc_entry(h.name, h)
|
149
|
+
end
|
150
|
+
idx.children = "#{toc}</ul>"
|
151
|
+
docxml
|
140
152
|
end
|
141
|
-
idx.children = "#{toc}</ul>"
|
142
|
-
docxml
|
143
|
-
end
|
144
153
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
154
|
+
# presupposes that the image source is local
|
155
|
+
def move_images(docxml)
|
156
|
+
FileUtils.rm_rf tmpimagedir
|
157
|
+
FileUtils.mkdir tmpimagedir
|
158
|
+
docxml.xpath("//*[local-name() = 'img']").each do |i|
|
159
|
+
i["width"], i["height"] = Html2Doc.image_resize(i, image_localfile(i),
|
160
|
+
@maxheight, @maxwidth)
|
161
|
+
next if /^data:/.match? i["src"]
|
153
162
|
|
154
|
-
|
163
|
+
@datauriimage ? datauri(i) : move_image1(i)
|
164
|
+
end
|
165
|
+
docxml
|
155
166
|
end
|
156
|
-
docxml
|
157
|
-
end
|
158
167
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
168
|
+
def datauri(img)
|
169
|
+
type = img["src"].split(".")[-1]
|
170
|
+
supertype = type == "xml" ? "application" : "image"
|
171
|
+
bin = IO.binread(image_localfile(img))
|
172
|
+
data = Base64.strict_encode64(bin)
|
173
|
+
img["src"] = "data:#{supertype}/#{type};base64,#{data}"
|
174
|
+
end
|
166
175
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
176
|
+
def image_suffix(img)
|
177
|
+
type = img["mimetype"]&.sub(%r{^[^/*]+/}, "")
|
178
|
+
matched = /\.(?<suffix>[^. \r\n\t]+)$/.match img["src"]
|
179
|
+
type and !type.empty? and return type
|
171
180
|
|
172
|
-
|
173
|
-
|
174
|
-
|
181
|
+
!matched.nil? and matched[:suffix] and return matched[:suffix]
|
182
|
+
"png"
|
183
|
+
end
|
175
184
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
+
def move_image1(img)
|
186
|
+
suffix = image_suffix(img)
|
187
|
+
uuid = UUIDTools::UUID.random_create.to_s
|
188
|
+
fname = "#{uuid}.#{suffix}"
|
189
|
+
new_full_filename = File.join(tmpimagedir, fname)
|
190
|
+
local_filename = image_localfile(img)
|
191
|
+
FileUtils.cp local_filename, new_full_filename
|
192
|
+
img["src"] = File.join(rel_tmpimagedir, fname)
|
193
|
+
end
|
185
194
|
|
186
|
-
|
187
|
-
|
195
|
+
def inject_script(doc)
|
196
|
+
return doc unless @scripts
|
188
197
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
198
|
+
scripts = File.read(@scripts, encoding: "UTF-8")
|
199
|
+
scripts_override = ""
|
200
|
+
@scripts_override and
|
201
|
+
scripts_override = File.read(@scripts_override, encoding: "UTF-8")
|
202
|
+
a = doc.split(%r{</body>})
|
203
|
+
"#{a[0]}#{scripts}#{scripts_override}</body>#{a[1]}"
|
204
|
+
end
|
196
205
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
206
|
+
def sourcecode_highlighter
|
207
|
+
'<script src="https://cdn.rawgit.com/google/code-prettify/master/'\
|
208
|
+
'loader/run_prettify.js"></script>'
|
209
|
+
end
|
201
210
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
211
|
+
MATHJAX_ADDR =
|
212
|
+
"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js".freeze
|
213
|
+
MATHJAX = <<~"MATHJAX".freeze
|
214
|
+
<script type="text/x-mathjax-config">
|
215
|
+
MathJax.Hub.Config({
|
216
|
+
"HTML-CSS": { preferredFont: "STIX" },
|
217
|
+
asciimath2jax: { delimiters: [['OPEN', 'CLOSE']] }
|
218
|
+
});
|
219
|
+
</script>
|
220
|
+
<script src="#{MATHJAX_ADDR}?config=MML_HTMLorMML-full" async="async"></script>
|
221
|
+
MATHJAX
|
222
|
+
|
223
|
+
def mathjax(open, close)
|
224
|
+
MATHJAX.gsub("OPEN", open).gsub("CLOSE", close)
|
225
|
+
end
|
217
226
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
227
|
+
def term_header(docxml)
|
228
|
+
%w(h1 h2 h3 h4 h5 h6 h7 h8).each do |h|
|
229
|
+
docxml.xpath("//p[@class = 'TermNum'][../#{h}]").each do |p|
|
230
|
+
p.name = "h#{h[1].to_i + 1}"
|
231
|
+
end
|
222
232
|
end
|
233
|
+
docxml
|
223
234
|
end
|
224
|
-
docxml
|
225
235
|
end
|
226
236
|
end
|
227
237
|
end
|