isodoc 1.5.5 → 1.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +2 -12
  3. data/.hound.yml +3 -1
  4. data/.rubocop.yml +3 -7
  5. data/Gemfile +2 -2
  6. data/Rakefile +2 -2
  7. data/bin/rspec +1 -2
  8. data/isodoc.gemspec +11 -11
  9. data/lib/isodoc-yaml/i18n-ar.yaml +152 -0
  10. data/lib/isodoc-yaml/i18n-de.yaml +149 -0
  11. data/lib/isodoc-yaml/i18n-es.yaml +151 -0
  12. data/lib/isodoc-yaml/i18n-ru.yaml +154 -0
  13. data/lib/isodoc.rb +0 -2
  14. data/lib/isodoc/base_style/all.css +7 -0
  15. data/lib/isodoc/base_style/metanorma_word.css +7 -0
  16. data/lib/isodoc/base_style/metanorma_word.scss +8 -0
  17. data/lib/isodoc/base_style/reset.css +7 -0
  18. data/lib/isodoc/base_style/reset.scss +9 -0
  19. data/lib/isodoc/base_style/scripts.html +187 -0
  20. data/lib/isodoc/class_utils.rb +6 -5
  21. data/lib/isodoc/common.rb +2 -0
  22. data/lib/isodoc/convert.rb +30 -17
  23. data/lib/isodoc/css.rb +43 -34
  24. data/lib/isodoc/function/blocks.rb +21 -4
  25. data/lib/isodoc/function/blocks_example_note.rb +2 -2
  26. data/lib/isodoc/function/cleanup.rb +53 -45
  27. data/lib/isodoc/function/form.rb +51 -0
  28. data/lib/isodoc/function/inline.rb +37 -15
  29. data/lib/isodoc/function/references.rb +55 -42
  30. data/lib/isodoc/function/section.rb +29 -16
  31. data/lib/isodoc/function/table.rb +1 -0
  32. data/lib/isodoc/function/to_word_html.rb +33 -29
  33. data/lib/isodoc/function/utils.rb +180 -159
  34. data/lib/isodoc/gem_tasks.rb +30 -31
  35. data/lib/isodoc/headlesshtml_convert.rb +8 -7
  36. data/lib/isodoc/html_convert.rb +6 -4
  37. data/lib/isodoc/html_function/comments.rb +2 -0
  38. data/lib/isodoc/html_function/footnotes.rb +14 -7
  39. data/lib/isodoc/html_function/form.rb +62 -0
  40. data/lib/isodoc/html_function/html.rb +30 -26
  41. data/lib/isodoc/html_function/postprocess.rb +41 -82
  42. data/lib/isodoc/html_function/postprocess_footnotes.rb +59 -0
  43. data/lib/isodoc/i18n.rb +33 -31
  44. data/lib/isodoc/pdf_convert.rb +12 -16
  45. data/lib/isodoc/presentation_function/bibdata.rb +54 -30
  46. data/lib/isodoc/presentation_function/block.rb +17 -8
  47. data/lib/isodoc/presentation_function/inline.rb +84 -120
  48. data/lib/isodoc/presentation_function/math.rb +84 -0
  49. data/lib/isodoc/presentation_function/section.rb +20 -22
  50. data/lib/isodoc/presentation_xml_convert.rb +2 -1
  51. data/lib/isodoc/sassc_importer.rb +1 -1
  52. data/lib/isodoc/version.rb +1 -1
  53. data/lib/isodoc/word_function/body.rb +28 -24
  54. data/lib/isodoc/word_function/footnotes.rb +22 -15
  55. data/lib/isodoc/word_function/postprocess.rb +50 -36
  56. data/lib/isodoc/xref.rb +9 -10
  57. data/lib/isodoc/xref/xref_counter.rb +32 -17
  58. data/lib/isodoc/xref/xref_gen.rb +33 -21
  59. data/lib/isodoc/xref/xref_gen_seq.rb +60 -35
  60. data/lib/isodoc/xref/xref_sect_gen.rb +37 -35
  61. data/lib/isodoc/xslfo_convert.rb +36 -27
  62. data/spec/assets/scripts_override.html +3 -0
  63. data/spec/isodoc/blocks_spec.rb +2490 -2591
  64. data/spec/isodoc/cleanup_spec.rb +1107 -1109
  65. data/spec/isodoc/footnotes_spec.rb +1 -16
  66. data/spec/isodoc/form_spec.rb +156 -0
  67. data/spec/isodoc/i18n_spec.rb +984 -972
  68. data/spec/isodoc/inline_spec.rb +1129 -912
  69. data/spec/isodoc/lists_spec.rb +316 -315
  70. data/spec/isodoc/postproc_spec.rb +1751 -1540
  71. data/spec/isodoc/presentation_xml_spec.rb +403 -323
  72. data/spec/isodoc/ref_spec.rb +718 -723
  73. data/spec/isodoc/section_spec.rb +910 -902
  74. data/spec/isodoc/table_spec.rb +566 -556
  75. data/spec/isodoc/terms_spec.rb +251 -255
  76. data/spec/isodoc/xref_spec.rb +3041 -2992
  77. data/spec/isodoc/xslfo_convert_spec.rb +39 -0
  78. data/spec/spec_helper.rb +30 -29
  79. metadata +77 -65
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'sassc'
4
- require 'isodoc/sassc_importer'
5
- require 'rake/clean'
3
+ require "sassc"
4
+ require "isodoc/sassc_importer"
5
+ require "rake/clean"
6
6
 
7
7
  module IsoDoc
8
8
  module GemTasks
@@ -11,7 +11,7 @@ module IsoDoc
11
11
  module_function
12
12
 
13
13
  def install
14
- rule '.css' => [proc { |tn| tn.sub(/\.css$/, '.scss') }] do |current_task|
14
+ rule ".css" => [proc { |tn| tn.sub(/\.css$/, ".scss") }] do |current_task|
15
15
  begin
16
16
  puts(current_task)
17
17
  compile_scss_task(current_task)
@@ -20,23 +20,23 @@ module IsoDoc
20
20
  end
21
21
  end
22
22
 
23
- scss_files = Rake::FileList['lib/**/*.scss']
24
- source_files = scss_files.ext('.css')
23
+ scss_files = Rake::FileList["lib/**/*.scss"]
24
+ source_files = scss_files.ext(".css")
25
25
 
26
26
  task :comment_out_liquid do
27
27
  process_css_files(scss_files) do |file_name|
28
- comment_out_liquid(File.read(file_name, encoding: 'UTF-8'))
28
+ comment_out_liquid(File.read(file_name, encoding: "UTF-8"))
29
29
  end
30
30
  end
31
31
 
32
32
  task build_scss: [:comment_out_liquid].push(*source_files) do
33
33
  process_css_files(scss_files) do |file_name|
34
- uncomment_out_liquid(File.read(file_name, encoding: 'UTF-8'))
34
+ uncomment_out_liquid(File.read(file_name, encoding: "UTF-8"))
35
35
  end
36
- git_cache_compiled_files && puts('Built scss!')
36
+ git_cache_compiled_files && puts("Built scss!")
37
37
  end
38
38
 
39
- Rake::Task['build'].enhance [:build_scss] do
39
+ Rake::Task["build"].enhance [:build_scss] do
40
40
  git_rm_compiled_files
41
41
  Rake::Task[:clean].invoke
42
42
  end
@@ -44,7 +44,7 @@ module IsoDoc
44
44
 
45
45
  def notify_borken_compilation(error, current_task)
46
46
  puts("Cannot compile #{current_task} because of #{error.message}")
47
- puts('continue anyway[y|n]?')
47
+ puts("continue anyway[y|n]?")
48
48
  answer = STDIN.gets.strip
49
49
  if %w[y yes].include?(answer.strip.downcase)
50
50
  puts("Cannot compile #{current_task} because of #{error.message}")
@@ -68,7 +68,7 @@ module IsoDoc
68
68
  def process_css_files(scss_files)
69
69
  scss_files.each do |file_name|
70
70
  result = yield(file_name)
71
- File.open(file_name, 'w', encoding: 'UTF-8') do |file|
71
+ File.open(file_name, "w", encoding: "UTF-8") do |file|
72
72
  file.puts(result)
73
73
  end
74
74
  end
@@ -81,42 +81,41 @@ module IsoDoc
81
81
  else
82
82
  line
83
83
  end
84
- end
85
- .join("\n")
84
+ end.join("\n")
86
85
  end
87
86
 
88
87
  def uncomment_out_liquid(text)
89
88
  text
90
- .gsub('/* LIQUID_COMMENT', '')
91
- .gsub('LIQUID_COMMENT */', '')
92
- .gsub('"{{', '{{').gsub('}}"', '}}')
89
+ .gsub("/* LIQUID_COMMENT", "")
90
+ .gsub("LIQUID_COMMENT */", "")
91
+ .gsub('"{{', '{{').gsub('}}"', "}}")
93
92
  end
94
93
 
95
94
  def fonts_placeholder
96
95
  <<~TEXT
97
- $bodyfont: '{{bodyfont}}';
98
- $headerfont: '{{headerfont}}';
99
- $monospacefont: '{{monospacefont}}';
100
- $normalfontsize: '{{normalfontsize}}';
101
- $smallerfontsize: '{{smallerfontsize}}';
102
- $footnotefontsize: '{{footnotefontsize}}';
103
- $monospacefontsize: '{{monospacefontsize}}';
96
+ $bodyfont: "{{bodyfont}}";
97
+ $headerfont: "{{headerfont}}";
98
+ $monospacefont: "{{monospacefont}}";
99
+ $normalfontsize: "{{normalfontsize}}";
100
+ $smallerfontsize: "{{smallerfontsize}}";
101
+ $footnotefontsize: "{{footnotefontsize}}";
102
+ $monospacefontsize: "{{monospacefontsize}}";
104
103
  TEXT
105
104
  end
106
105
 
107
106
  def compile_scss(filename)
108
- require 'sassc'
107
+ require "sassc"
109
108
 
110
- isodoc_path = if Gem.loaded_specs['isodoc']
111
- File.join(Gem.loaded_specs['isodoc'].full_gem_path, 'lib', 'isodoc')
109
+ isodoc_path = if Gem.loaded_specs["isodoc"]
110
+ File.join(Gem.loaded_specs["isodoc"].full_gem_path, "lib", "isodoc")
112
111
  else
113
- File.join('lib', 'isodoc')
112
+ File.join("lib", "isodoc")
114
113
  end
115
114
  [isodoc_path,
116
115
  File.dirname(filename)].each do |name|
117
116
  SassC.load_paths << name
118
117
  end
119
- sheet_content = File.read(filename, encoding: 'UTF-8')
118
+ sheet_content = File.read(filename, encoding: "UTF-8")
120
119
  SassC::Engine.new(fonts_placeholder + sheet_content,
121
120
  syntax: :scss,
122
121
  importer: SasscImporter)
@@ -125,10 +124,10 @@ module IsoDoc
125
124
 
126
125
  def compile_scss_task(current_task)
127
126
  filename = current_task.source
128
- basename = File.basename(filename, '.*')
127
+ basename = File.basename(filename, ".*")
129
128
  compiled_path = File.join(File.dirname(filename), "#{basename}.css")
130
129
  content = uncomment_out_liquid(compile_scss(filename))
131
- File.open(compiled_path, 'w:UTF-8') do |f|
130
+ File.open(compiled_path, "w:UTF-8") do |f|
132
131
  f.write(content)
133
132
  end
134
133
  CLEAN << compiled_path
@@ -1,11 +1,10 @@
1
- require_relative "html_function/comments.rb"
2
- require_relative "html_function/footnotes.rb"
3
- require_relative "html_function/html.rb"
1
+ require_relative "html_function/comments"
2
+ require_relative "html_function/footnotes"
3
+ require_relative "html_function/html"
4
4
  require "fileutils"
5
5
 
6
6
  module IsoDoc
7
7
  class HeadlessHtmlConvert < ::IsoDoc::Convert
8
-
9
8
  include HtmlFunction::Comments
10
9
  include HtmlFunction::Footnotes
11
10
  include HtmlFunction::Html
@@ -26,16 +25,18 @@ module IsoDoc
26
25
  docxml, filename, dir = convert_init(file, input_filename, debug)
27
26
  result = convert1(docxml, filename, dir)
28
27
  return result if debug
29
- postprocess(result, filename + ".tmp.html", dir)
28
+
29
+ postprocess(result, "#{filename}.tmp.html", dir)
30
30
  FileUtils.rm_rf dir
31
- strip_head(filename + ".tmp.html", output_filename || "#{filename}.#{@suffix}")
31
+ strip_head("#{filename}.tmp.html",
32
+ output_filename || "#{filename}.#{@suffix}")
32
33
  FileUtils.rm_rf ["#{filename}.tmp.html", tmpimagedir]
33
34
  end
34
35
 
35
36
  def strip_head(input, output)
36
37
  file = File.read(input, encoding: "utf-8")
37
38
  doc = Nokogiri::XML(file)
38
- doc.xpath("//head").each { |x| x.remove }
39
+ doc.xpath("//head").each(&:remove)
39
40
  doc.xpath("//html").each { |x| x.name = "div" }
40
41
  body = doc.at("//body")
41
42
  body.replace(body.children)
@@ -1,13 +1,15 @@
1
- require_relative "html_function/comments.rb"
2
- require_relative "html_function/footnotes.rb"
3
- require_relative "html_function/html.rb"
4
- require_relative "html_function/postprocess.rb"
1
+ require_relative "html_function/comments"
2
+ require_relative "html_function/footnotes"
3
+ require_relative "html_function/html"
4
+ require_relative "html_function/form"
5
+ require_relative "html_function/postprocess"
5
6
 
6
7
  module IsoDoc
7
8
  class HtmlConvert < ::IsoDoc::Convert
8
9
 
9
10
  include HtmlFunction::Comments
10
11
  include HtmlFunction::Footnotes
12
+ include HtmlFunction::Form
11
13
  include HtmlFunction::Html
12
14
 
13
15
  def tmpimagedir_suffix
@@ -84,6 +84,7 @@ module IsoDoc::HtmlFunction
84
84
  def comment_attributes(docxml, x)
85
85
  fromlink = docxml.at("//*[@id='#{x['from']}']")
86
86
  return(nil) if fromlink.nil?
87
+
87
88
  tolink = docxml.at("//*[@id='#{x['to']}']") || fromlink
88
89
  target = docxml.at("//*[@id='#{x['target']}']")
89
90
  { from: fromlink, to: tolink, target: target }
@@ -122,6 +123,7 @@ module IsoDoc::HtmlFunction
122
123
  comments = []
123
124
  docxml.xpath("//div[@style='mso-element:comment']").each do |c|
124
125
  next unless c["id"] && !link_order[c["id"]].nil?
126
+
125
127
  comments << { text: c.remove.to_s, id: c["id"] }
126
128
  end
127
129
  comments.sort! { |a, b| link_order[a[:id]] <=> link_order[b[:id]] }
@@ -3,6 +3,7 @@ module IsoDoc::HtmlFunction
3
3
 
4
4
  def footnotes(div)
5
5
  return if @footnotes.empty?
6
+
6
7
  @footnotes.each { |fn| div.parent << fn }
7
8
  end
8
9
 
@@ -44,15 +45,19 @@ module IsoDoc::HtmlFunction
44
45
  def get_table_ancestor_id(node)
45
46
  table = node.ancestors("table") || node.ancestors("figure")
46
47
  return UUIDTools::UUID.random_create.to_s if table.empty?
48
+
47
49
  table.last["id"]
48
50
  end
49
51
 
52
+ # @seen_footnote:
53
+ # do not output footnote text if we have already seen it for this table
54
+
50
55
  def table_footnote_parse(node, out)
51
56
  fn = node["reference"] || UUIDTools::UUID.random_create.to_s
52
57
  tid = get_table_ancestor_id(node)
53
58
  make_table_footnote_link(out, tid + fn, fn)
54
- # do not output footnote text if we have already seen it for this table
55
59
  return if @seen_footnote.include?(tid + fn)
60
+
56
61
  @in_footnote = true
57
62
  out.aside **{ class: "footnote" } do |a|
58
63
  a << make_table_footnote_text(node, tid + fn, fn)
@@ -62,8 +67,9 @@ module IsoDoc::HtmlFunction
62
67
  end
63
68
 
64
69
  def footnote_parse(node, out)
65
- return table_footnote_parse(node, out) if (@in_table || @in_figure) &&
66
- !node.ancestors.map {|m| m.name }.include?("name")
70
+ return table_footnote_parse(node, out) if (@in_table || @in_figure) &&
71
+ !node.ancestors.map(&:name).include?("name")
72
+
67
73
  fn = node["reference"] || UUIDTools::UUID.random_create.to_s
68
74
  attrs = { class: "FootnoteRef", href: "#fn:#{fn}" }
69
75
  out.a **attrs do |a|
@@ -72,12 +78,13 @@ module IsoDoc::HtmlFunction
72
78
  make_footnote(node, fn)
73
79
  end
74
80
 
75
- def make_footnote(node, fn)
76
- return if @seen_footnote.include?(fn)
81
+ def make_footnote(node, fnote)
82
+ return if @seen_footnote.include?(fnote)
83
+
77
84
  @in_footnote = true
78
- @footnotes << make_generic_footnote_text(node, fn)
85
+ @footnotes << make_generic_footnote_text(node, fnote)
79
86
  @in_footnote = false
80
- @seen_footnote << fn
87
+ @seen_footnote << fnote
81
88
  end
82
89
  end
83
90
  end
@@ -0,0 +1,62 @@
1
+ module IsoDoc::HtmlFunction
2
+ module Form
3
+ def form_parse(node, out)
4
+ out.form **attr_code(id: node["id"], name: node["name"],
5
+ action: node["action"]) do |div|
6
+ node.children.each do |n|
7
+ parse(n, div)
8
+ end
9
+ end
10
+ end
11
+
12
+ def input_parse(node, out)
13
+ out.input nil, **attr_code(
14
+ id: node["id"], name: node["name"], type: node["type"],
15
+ value: node["value"], disabled: node["disabled"],
16
+ readonly: node["readonly"], checked: node["checked"],
17
+ maxlength: node["maxlength"], minlength: node["minlength"]
18
+ )
19
+ end
20
+
21
+ def select_parse(node, out)
22
+ selected = node.at(ns("./option[@value = '#{node['value']}']"))
23
+ selected and selected["selected"] = true
24
+ out.select **attr_code(
25
+ id: node["id"], name: node["name"], size: node["size"],
26
+ disabled: node["disabled"], multiple: node["multiple"]
27
+ ) do |div|
28
+ node.children.each do |n|
29
+ parse(n, div)
30
+ end
31
+ end
32
+ end
33
+
34
+ def label_parse(node, out)
35
+ out.label **attr_code(for: node["for"]) do |div|
36
+ node.children.each do |n|
37
+ parse(n, div)
38
+ end
39
+ end
40
+ end
41
+
42
+ def option_parse(node, out)
43
+ out.option **attr_code(
44
+ disabled: node["disabled"], selected: node["selected"],
45
+ value: node["value"]
46
+ ) do |o|
47
+ node.children.each do |n|
48
+ parse(n, o)
49
+ end
50
+ end
51
+ end
52
+
53
+ def textarea_parse(node, out)
54
+ out.textarea **attr_code(
55
+ id: node["id"], name: node["name"], rows: node["rows"],
56
+ cols: node["cols"]
57
+ ) do |div|
58
+ node["value"] and div << node["value"]
59
+ end
60
+ end
61
+ end
62
+ end
@@ -5,9 +5,9 @@ module IsoDoc::HtmlFunction
5
5
  module Html
6
6
  def convert1(docxml, filename, dir)
7
7
  noko do |xml|
8
- xml.html **{ lang: "#{@lang}" } do |html|
8
+ xml.html **{ lang: @lang.to_s } do |html|
9
9
  info docxml, nil
10
- populate_css()
10
+ populate_css
11
11
  html.head { |head| define_head head, filename, dir }
12
12
  make_body(html, docxml)
13
13
  end
@@ -15,13 +15,17 @@ module IsoDoc::HtmlFunction
15
15
  end
16
16
 
17
17
  def make_body1(body, _docxml)
18
+ return if @bare
19
+
18
20
  body.div **{ class: "title-section" } do |div1|
19
21
  div1.p { |p| p << "&nbsp;" } # placeholder
20
22
  end
21
23
  section_break(body)
22
24
  end
23
25
 
24
- def make_body2(body, docxml)
26
+ def make_body2(body, _docxml)
27
+ return if @bare
28
+
25
29
  body.div **{ class: "prefatory-section" } do |div2|
26
30
  div2.p { |p| p << "&nbsp;" } # placeholder
27
31
  end
@@ -43,46 +47,47 @@ module IsoDoc::HtmlFunction
43
47
  end
44
48
  end
45
49
 
46
- def googlefonts()
50
+ def googlefonts
47
51
  <<~HEAD.freeze
48
- <link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet">
49
- <link href="https://fonts.googleapis.com/css?family=Lato:400,400i,700,900" rel="stylesheet">
52
+ <link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet">
53
+ <link href="https://fonts.googleapis.com/css?family=Lato:400,400i,700,900" rel="stylesheet">
50
54
  HEAD
51
55
  end
52
56
 
53
- def html_head()
57
+ def html_head
54
58
  <<~HEAD.freeze
55
- <title>#{@meta&.get&.dig(:doctitle)}</title>
56
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
57
-
58
- <!--TOC script import-->
59
- <script type="text/javascript" src="https://cdn.rawgit.com/jgallen23/toc/0.3.2/dist/toc.min.js"></script>
60
- <script type="text/javascript">#{toclevel}</script>
61
-
62
- <!--Google fonts-->
63
- <link rel="preconnect" href="https://fonts.gstatic.com">
64
- #{googlefonts}
65
- <!--Font awesome import for the link icon-->
66
- <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" crossorigin="anonymous">
67
- <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css" integrity="sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P" crossorigin="anonymous">
68
- <style class="anchorjs"></style>
59
+ <title>#{@meta&.get&.dig(:doctitle)}</title>
60
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
61
+
62
+ <!--TOC script import-->
63
+ <script type="text/javascript" src="https://cdn.rawgit.com/jgallen23/toc/0.3.2/dist/toc.min.js"></script>
64
+ <script type="text/javascript">#{toclevel}</script>
65
+
66
+ <!--Google fonts-->
67
+ <link rel="preconnect" href="https://fonts.gstatic.com">#{' '}
68
+ #{googlefonts}
69
+ <!--Font awesome import for the link icon-->
70
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" crossorigin="anonymous">
71
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css" integrity="sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P" crossorigin="anonymous">
72
+ <style class="anchorjs"></style>
69
73
  HEAD
70
74
  end
71
75
 
72
- def html_button()
76
+ def html_button
73
77
  '<button onclick="topFunction()" id="myBtn" '\
74
78
  'title="Go to top">Top</button>'.freeze
75
79
  end
76
80
 
77
81
  def html_main(docxml)
78
- docxml.at("//head").add_child(html_head())
82
+ docxml.at("//head").add_child(html_head)
79
83
  d = docxml.at('//div[@class="main-section"]')
80
84
  d.name = "main"
81
- d.children.empty? or d.children.first.previous = html_button()
85
+ d.children.empty? or d.children.first.previous = html_button
82
86
  end
83
87
 
84
88
  def sourcecodelang(lang)
85
89
  return unless lang
90
+
86
91
  case lang.downcase
87
92
  when "javascript" then "lang-js"
88
93
  when "c" then "lang-c"
@@ -117,7 +122,6 @@ module IsoDoc::HtmlFunction
117
122
  end
118
123
  end
119
124
 
120
- def table_long_strings_cleanup(docxml)
121
- end
125
+ def table_long_strings_cleanup(docxml); end
122
126
  end
123
127
  end
@@ -1,4 +1,5 @@
1
1
  require "isodoc/html_function/mathvariant_to_plain"
2
+ require_relative "postprocess_footnotes"
2
3
 
3
4
  module IsoDoc::HtmlFunction
4
5
  module Html
@@ -28,15 +29,15 @@ module IsoDoc::HtmlFunction
28
29
  .sub(%r{<\?xml[^>]+>}, "")
29
30
  end
30
31
 
31
- def html_cleanup(x)
32
+ def html_cleanup(html)
32
33
  mathml(
33
34
  footnote_format(
34
35
  footnote_backlinks(
35
36
  html_toc(
36
- term_header(html_footnote_filter(html_preface(htmlstyle(x))))
37
- )
38
- )
39
- )
37
+ term_header(html_footnote_filter(html_preface(htmlstyle(html)))),
38
+ ),
39
+ ),
40
+ ),
40
41
  )
41
42
  end
42
43
 
@@ -46,6 +47,7 @@ module IsoDoc::HtmlFunction
46
47
 
47
48
  def htmlstylesheet(file)
48
49
  return if file.nil?
50
+
49
51
  file.open if file.is_a?(Tempfile)
50
52
  stylesheet = file.read
51
53
  xml = Nokogiri::XML("<style/>")
@@ -57,7 +59,7 @@ module IsoDoc::HtmlFunction
57
59
 
58
60
  def htmlstyle(docxml)
59
61
  return docxml unless @htmlstylesheet
60
- title = docxml.at("//*[local-name() = 'head']/*[local-name() = 'title']")
62
+
61
63
  head = docxml.at("//*[local-name() = 'head']")
62
64
  head << htmlstylesheet(@htmlstylesheet)
63
65
  s = htmlstylesheet(@htmlstylesheet_override) and head << s
@@ -65,8 +67,8 @@ module IsoDoc::HtmlFunction
65
67
  end
66
68
 
67
69
  def html_preface(docxml)
68
- html_cover(docxml) if @htmlcoverpage
69
- html_intro(docxml) if @htmlintropage
70
+ html_cover(docxml) if @htmlcoverpage && !@bare
71
+ html_intro(docxml) if @htmlintropage && !@bare
70
72
  docxml.at("//body") << mathjax(@openmathdelim, @closemathdelim)
71
73
  docxml.at("//body") << sourcecode_highlighter
72
74
  html_main(docxml)
@@ -76,8 +78,9 @@ module IsoDoc::HtmlFunction
76
78
 
77
79
  def authority_cleanup1(docxml, klass)
78
80
  dest = docxml.at("//div[@id = 'boilerplate-#{klass}-destination']")
79
- auth = docxml.at("//div[@id = 'boilerplate-#{klass}' or @class = 'boilerplate-#{klass}']")
80
- auth&.xpath(".//h1[not(text())] | .//h2[not(text())]")&.each { |h| h.remove }
81
+ auth = docxml.at("//div[@id = 'boilerplate-#{klass}' or "\
82
+ "@class = 'boilerplate-#{klass}']")
83
+ auth&.xpath(".//h1[not(text())] | .//h2[not(text())]")&.each(&:remove)
81
84
  auth&.xpath(".//h1 | .//h2")&.each { |h| h["class"] = "IntroTitle" }
82
85
  dest and auth and dest.replace(auth.remove)
83
86
  end
@@ -92,14 +95,18 @@ module IsoDoc::HtmlFunction
92
95
  doc = to_xhtml_fragment(File.read(@htmlcoverpage, encoding: "UTF-8"))
93
96
  d = docxml.at('//div[@class="title-section"]')
94
97
  # d.children.first.add_previous_sibling doc.to_xml(encoding: "US-ASCII")
95
- d.children.first.add_previous_sibling populate_template(doc.to_xml(encoding: "US-ASCII"), :html)
98
+ d.children.first.add_previous_sibling(
99
+ populate_template(doc.to_xml(encoding: "US-ASCII"), :html),
100
+ )
96
101
  end
97
102
 
98
103
  def html_intro(docxml)
99
104
  doc = to_xhtml_fragment(File.read(@htmlintropage, encoding: "UTF-8"))
100
105
  d = docxml.at('//div[@class="prefatory-section"]')
101
106
  # d.children.first.add_previous_sibling doc.to_xml(encoding: "US-ASCII")
102
- d.children.first.add_previous_sibling populate_template(doc.to_xml(encoding: "US-ASCII"), :html)
107
+ d.children.first.add_previous_sibling(
108
+ populate_template(doc.to_xml(encoding: "US-ASCII"), :html),
109
+ )
103
110
  end
104
111
 
105
112
  def html_toc_entry(level, header)
@@ -112,7 +119,9 @@ module IsoDoc::HtmlFunction
112
119
  end
113
120
 
114
121
  def toclevel
115
- ret = toclevel_classes.map { |l| "#{l}:not(:empty):not(.TermNum):not(.noTOC)" }
122
+ ret = toclevel_classes.map do |l|
123
+ "#{l}:not(:empty):not(.TermNum):not(.noTOC)"
124
+ end
116
125
  <<~HEAD.freeze
117
126
  function toclevel() { return "#{ret.join(',')}";}
118
127
  HEAD
@@ -140,99 +149,49 @@ module IsoDoc::HtmlFunction
140
149
  docxml.xpath("//*[local-name() = 'img']").each do |i|
141
150
  i["width"], i["height"] = Html2Doc.image_resize(i, image_localfile(i),
142
151
  @maxheight, @maxwidth)
143
- next if /^data:/.match i["src"]
152
+ next if /^data:/.match? i["src"]
153
+
144
154
  @datauriimage ? datauri(i) : move_image1(i)
145
155
  end
146
156
  docxml
147
157
  end
148
158
 
149
- def datauri(i)
150
- type = i["src"].split(".")[-1]
159
+ def datauri(img)
160
+ type = img["src"].split(".")[-1]
151
161
  supertype = type == "xml" ? "application" : "image"
152
- bin = IO.binread(image_localfile(i))
162
+ bin = IO.binread(image_localfile(img))
153
163
  data = Base64.strict_encode64(bin)
154
- i["src"] = "data:#{supertype}/#{type};base64,#{data}"
164
+ img["src"] = "data:#{supertype}/#{type};base64,#{data}"
155
165
  end
156
166
 
157
- def image_suffix(i)
158
- type = i["mimetype"]&.sub(%r{^[^/*]+/}, "")
159
- matched = /\.(?<suffix>[^. \r\n\t]+)$/.match i["src"]
167
+ def image_suffix(img)
168
+ type = img["mimetype"]&.sub(%r{^[^/*]+/}, "")
169
+ matched = /\.(?<suffix>[^. \r\n\t]+)$/.match img["src"]
160
170
  type and !type.empty? and return type
171
+
161
172
  !matched.nil? and matched[:suffix] and return matched[:suffix]
162
173
  "png"
163
174
  end
164
175
 
165
- def move_image1(i)
166
- suffix = image_suffix(i)
176
+ def move_image1(img)
177
+ suffix = image_suffix(img)
167
178
  uuid = UUIDTools::UUID.random_create.to_s
168
179
  fname = "#{uuid}.#{suffix}"
169
180
  new_full_filename = File.join(tmpimagedir, fname)
170
- local_filename = image_localfile(i)
181
+ local_filename = image_localfile(img)
171
182
  FileUtils.cp local_filename, new_full_filename
172
- i["src"] = File.join(rel_tmpimagedir, fname)
183
+ img["src"] = File.join(rel_tmpimagedir, fname)
173
184
  end
174
185
 
175
186
  def inject_script(doc)
176
187
  return doc unless @scripts
188
+
177
189
  scripts = File.read(@scripts, encoding: "UTF-8")
190
+ scripts_override = ""
191
+ @scripts_override and
192
+ scripts_override = File.read(@scripts_override, encoding: "UTF-8")
178
193
  a = doc.split(%r{</body>})
179
- a[0] + scripts + "</body>" + a[1]
180
- end
181
-
182
- def update_footnote_filter(fn, x, i, seen)
183
- if seen[fn.text]
184
- x.at("./sup").content = seen[fn.text][:num].to_s
185
- fn.remove unless x["href"] == seen[fn.text][:href]
186
- x["href"] = seen[fn.text][:href]
187
- else
188
- seen[fn.text] = { num: i, href: x["href"] }
189
- x.at("./sup").content = i.to_s
190
- i += 1
191
- end
192
- [i, seen]
193
- end
194
-
195
- def html_footnote_filter(docxml)
196
- seen = {}
197
- i = 1
198
- docxml.xpath('//a[@class = "FootnoteRef"]').each do |x|
199
- fn = docxml.at(%<//*[@id = '#{x['href'].sub(/^#/, '')}']>) || next
200
- i, seen = update_footnote_filter(fn, x, i, seen)
201
- end
202
- docxml
203
- end
204
-
205
- def footnote_backlinks1(x, fn)
206
- xdup = x.dup
207
- xdup.remove["id"]
208
- if fn.elements.empty?
209
- fn.children.first.previous = xdup
210
- else
211
- fn.elements.first.children.first.previous = xdup
212
- end
213
- end
214
-
215
- def footnote_backlinks(docxml)
216
- seen = {}
217
- docxml.xpath('//a[@class = "FootnoteRef"]').each_with_index do |x, i|
218
- seen[x["href"]] and next or seen[x["href"]] = true
219
- fn = docxml.at(%<//*[@id = '#{x['href'].sub(/^#/, '')}']>) || next
220
- footnote_backlinks1(x, fn)
221
- x["id"] ||= "fnref:#{i + 1}"
222
- fn.add_child "<a href='##{x['id']}'>&#x21A9;</a>"
223
- end
224
- docxml
225
- end
226
-
227
- def footnote_format(docxml)
228
- docxml.xpath("//a[@class = 'FootnoteRef']/sup").each do |x|
229
- footnote_reference_format(x)
230
- end
231
- docxml.xpath("//a[@class = 'TableFootnoteRef'] | "\
232
- "//span[@class = 'TableFootnoteRef']").each do |x|
233
- table_footnote_reference_format(x)
234
- end
235
- docxml
194
+ "#{a[0]}#{scripts}#{scripts_override}</body>#{a[1]}"
236
195
  end
237
196
 
238
197
  def sourcecode_highlighter