isodoc 1.5.4 → 1.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -4
  3. data/Gemfile +2 -2
  4. data/Rakefile +2 -2
  5. data/bin/rspec +1 -2
  6. data/isodoc.gemspec +11 -11
  7. data/lib/isodoc-yaml/i18n-ar.yaml +152 -0
  8. data/lib/isodoc-yaml/i18n-de.yaml +149 -0
  9. data/lib/isodoc-yaml/i18n-es.yaml +151 -0
  10. data/lib/isodoc-yaml/i18n-ru.yaml +154 -0
  11. data/lib/isodoc/base_style/all.css +7 -0
  12. data/lib/isodoc/base_style/metanorma_word.css +7 -0
  13. data/lib/isodoc/base_style/metanorma_word.scss +8 -0
  14. data/lib/isodoc/base_style/reset.css +7 -0
  15. data/lib/isodoc/base_style/reset.scss +9 -0
  16. data/lib/isodoc/base_style/scripts.html +187 -0
  17. data/lib/isodoc/class_utils.rb +6 -5
  18. data/lib/isodoc/common.rb +2 -0
  19. data/lib/isodoc/convert.rb +30 -17
  20. data/lib/isodoc/css.rb +42 -28
  21. data/lib/isodoc/function/blocks.rb +21 -4
  22. data/lib/isodoc/function/blocks_example_note.rb +2 -2
  23. data/lib/isodoc/function/cleanup.rb +1 -2
  24. data/lib/isodoc/function/form.rb +51 -0
  25. data/lib/isodoc/function/inline.rb +32 -10
  26. data/lib/isodoc/function/references.rb +55 -42
  27. data/lib/isodoc/function/table.rb +1 -0
  28. data/lib/isodoc/function/to_word_html.rb +29 -28
  29. data/lib/isodoc/function/utils.rb +41 -38
  30. data/lib/isodoc/gem_tasks.rb +30 -31
  31. data/lib/isodoc/html_convert.rb +6 -4
  32. data/lib/isodoc/html_function/form.rb +62 -0
  33. data/lib/isodoc/html_function/postprocess.rb +35 -76
  34. data/lib/isodoc/html_function/postprocess_footnotes.rb +59 -0
  35. data/lib/isodoc/i18n.rb +33 -31
  36. data/lib/isodoc/pdf_convert.rb +1 -3
  37. data/lib/isodoc/presentation_function/bibdata.rb +13 -10
  38. data/lib/isodoc/presentation_function/block.rb +17 -8
  39. data/lib/isodoc/presentation_function/inline.rb +75 -118
  40. data/lib/isodoc/presentation_function/math.rb +84 -0
  41. data/lib/isodoc/presentation_function/section.rb +20 -22
  42. data/lib/isodoc/presentation_xml_convert.rb +2 -1
  43. data/lib/isodoc/sassc_importer.rb +1 -1
  44. data/lib/isodoc/version.rb +1 -1
  45. data/lib/isodoc/word_function/body.rb +28 -24
  46. data/lib/isodoc/word_function/footnotes.rb +22 -15
  47. data/lib/isodoc/word_function/postprocess.rb +16 -6
  48. data/lib/isodoc/xref.rb +10 -11
  49. data/lib/isodoc/xref/xref_counter.rb +32 -17
  50. data/lib/isodoc/xref/xref_gen.rb +45 -32
  51. data/lib/isodoc/xref/xref_sect_gen.rb +33 -31
  52. data/lib/isodoc/xslfo_convert.rb +36 -25
  53. data/spec/assets/html_override.css +1 -0
  54. data/spec/assets/word_override.css +1 -0
  55. data/spec/isodoc/blocks_spec.rb +2518 -2570
  56. data/spec/isodoc/cleanup_spec.rb +1107 -1109
  57. data/spec/isodoc/footnotes_spec.rb +1 -16
  58. data/spec/isodoc/form_spec.rb +156 -0
  59. data/spec/isodoc/i18n_spec.rb +984 -972
  60. data/spec/isodoc/inline_spec.rb +984 -920
  61. data/spec/isodoc/lists_spec.rb +316 -315
  62. data/spec/isodoc/postproc_spec.rb +1692 -1538
  63. data/spec/isodoc/presentation_xml_spec.rb +345 -342
  64. data/spec/isodoc/ref_spec.rb +718 -723
  65. data/spec/isodoc/section_spec.rb +910 -902
  66. data/spec/isodoc/table_spec.rb +566 -556
  67. data/spec/isodoc/terms_spec.rb +252 -256
  68. data/spec/isodoc/xref_spec.rb +3040 -2985
  69. data/spec/isodoc/xslfo_convert_spec.rb +39 -0
  70. data/spec/spec_helper.rb +30 -29
  71. metadata +80 -70
  72. data/.rubocop.ribose.yml +0 -65
  73. data/.rubocop.tb.yml +0 -650
  74. data/lib/twitter-cldr/patch.rb +0 -39
@@ -2,16 +2,17 @@ require "roman-numerals"
2
2
 
3
3
  module IsoDoc::XrefGen
4
4
  class Counter
5
- def initialize(num = 0, opts = {numerals: :arabic})
5
+ def initialize(num = 0, opts = { numerals: :arabic })
6
6
  @num = num
7
7
  @letter = ""
8
8
  @subseq = ""
9
9
  @letter_override = nil
10
10
  @number_override = nil
11
11
  @style = opts[:numerals]
12
+ @skip_i = opts[:skip_i]
12
13
  @base = ""
13
14
  if num.is_a? String
14
- if /^\d+$/.match(num)
15
+ if /^\d+$/.match?(num)
15
16
  @num = num.to_i
16
17
  else
17
18
  @num = nil
@@ -34,7 +35,7 @@ module IsoDoc::XrefGen
34
35
  @base = b
35
36
  else
36
37
  @letter_override = node["number"]
37
- @letter = @letter_override if /^[a-zA-Z]$/.match(@letter_override)
38
+ @letter = @letter_override if /^[a-zA-Z]$/.match?(@letter_override)
38
39
  end
39
40
  end
40
41
  end
@@ -48,8 +49,7 @@ module IsoDoc::XrefGen
48
49
  @base = node["number"][0..-2]
49
50
  @letter = @letter_override = node["number"][-1]
50
51
  else
51
- @number_override = node["number"]
52
- @num = n.to_i
52
+ @number_override = @num = n.to_i
53
53
  @base = b
54
54
  @letter = ""
55
55
  end
@@ -64,7 +64,7 @@ module IsoDoc::XrefGen
64
64
  @letter_override = node["number"]
65
65
  /^(?<b>.*?)(?<n>\d*)(?<a>[a-zA-Z])$/ =~ node["number"]
66
66
  if blank?(a)
67
- if /^\d+$/.match(node["number"])
67
+ if /^\d+$/.match?(node["number"])
68
68
  @letter_override = @letter = ""
69
69
  @number_override = @num = node["number"].to_i
70
70
  else
@@ -80,32 +80,46 @@ module IsoDoc::XrefGen
80
80
  @number_override = @num = n.to_i unless n.empty?
81
81
  end
82
82
  else
83
- @letter = (@letter.ord + 1).chr.to_s
83
+ increment_letter
84
+ end
85
+ end
86
+
87
+ def increment_letter
88
+ case @letter
89
+ when "Z"
90
+ @letter = "@"
91
+ @base = @base.empty? ? "A" : @base[0..-2] + (@base[-1].ord + 1).chr.to_s
92
+ when "z"
93
+ @letter = "`"
94
+ @base = @base.empty? ? "a" : @base[0..-2] + (@base[-1].ord + 1).chr.to_s
84
95
  end
96
+ @letter = (@letter.ord + 1).chr.to_s
97
+ @skip_i && %w(i I).include?(@letter) and
98
+ @letter = (@letter.ord + 1).chr.to_s
85
99
  end
86
100
 
87
- def blank?(x)
88
- x.nil? || x.empty?
101
+ def blank?(str)
102
+ str.nil? || str.empty?
89
103
  end
90
104
 
91
105
  def increment(node)
92
106
  return self if node["unnumbered"]
107
+
93
108
  @letter_override = nil
94
109
  @number_override = nil
95
- if node["subsequence"] != @subseq && !(blank?(node["subsequence"]) && blank?(@subseq))
110
+ if node["subsequence"] != @subseq &&
111
+ !(blank?(node["subsequence"]) && blank?(@subseq))
96
112
  new_subseq_increment(node)
97
- elsif @letter.empty?
98
- sequence_increment(node)
99
- else
100
- subsequence_increment(node)
113
+ elsif @letter.empty? then sequence_increment(node)
114
+ else subsequence_increment(node)
101
115
  end
102
116
  self
103
117
  end
104
118
 
105
119
  def print
106
120
  num = @number_override || @num
107
- num_out = @style == :roman && !num.nil? ? RomanNumerals.to_roman(num) : num
108
- "#{@base}#{num_out}#{@letter_override || @letter}"
121
+ out = @style == :roman && !num.nil? ? RomanNumerals.to_roman(num) : num
122
+ "#{@base}#{out}#{@letter_override || @letter}"
109
123
  end
110
124
 
111
125
  def ol_type(list, depth)
@@ -115,7 +129,8 @@ module IsoDoc::XrefGen
115
129
  return :alphabet_upper if [4, 9].include? depth
116
130
  return :roman if [3, 8].include? depth
117
131
  return :roman_upper if [5, 10].include? depth
118
- return :arabic
132
+
133
+ :arabic
119
134
  end
120
135
 
121
136
  def listlabel(list, depth)
@@ -1,4 +1,4 @@
1
- require_relative "xref_gen_seq.rb"
1
+ require_relative "xref_gen_seq"
2
2
 
3
3
  module IsoDoc::XrefGen
4
4
  module Blocks
@@ -10,35 +10,43 @@ module IsoDoc::XrefGen
10
10
  autonum = amend_autonums(a)
11
11
  NUMBERED_BLOCKS.each do |b|
12
12
  a.xpath(ns("./newcontent//#{b}")).each_with_index do |e, i|
13
- autonum[b] and i == 0 and e["number"] = autonum[b]
13
+ autonum[b] && i.zero? and e["number"] = autonum[b]
14
14
  !autonum[b] and e["unnumbered"] = "true"
15
15
  end
16
16
  end
17
17
  end
18
18
  end
19
19
 
20
- def amend_autonums(a)
20
+ def amend_autonums(amend)
21
21
  autonum = {}
22
- a.xpath(ns("./autonumber")).each do |n|
22
+ amend.xpath(ns("./autonumber")).each do |n|
23
23
  autonum[n["type"]] = n.text
24
24
  end
25
25
  autonum
26
26
  end
27
27
 
28
- def termnote_label(n)
29
- @labels["termnote"].gsub(/%/, n.to_s)
28
+ def termnote_label(note)
29
+ @labels["termnote"].gsub(/%/, note.to_s)
30
+ end
31
+
32
+ def increment_label(elems, node, counter, increment = true)
33
+ return "" if elems.size == 1 && !node["number"]
34
+
35
+ counter.increment(node) if increment
36
+ " #{counter.print}"
30
37
  end
31
38
 
32
39
  def termnote_anchor_names(docxml)
33
40
  docxml.xpath(ns("//term[descendant::termnote]")).each do |t|
34
41
  c = Counter.new
35
42
  t.xpath(ns(".//termnote")).each do |n|
36
- return if n["id"].nil? || n["id"].empty?
43
+ next if n["id"].nil? || n["id"].empty?
44
+
37
45
  c.increment(n)
38
46
  @anchors[n["id"]] =
39
47
  { label: termnote_label(c.print), type: "termnote", value: c.print,
40
48
  xref: l10n("#{anchor(t['id'], :xref)}, "\
41
- "#{@labels["note_xref"]} #{c.print}") }
49
+ "#{@labels['note_xref']} #{c.print}") }
42
50
  end
43
51
  end
44
52
  end
@@ -48,13 +56,14 @@ module IsoDoc::XrefGen
48
56
  examples = t.xpath(ns(".//termexample"))
49
57
  c = Counter.new
50
58
  examples.each do |n|
51
- return if n["id"].nil? || n["id"].empty?
59
+ next if n["id"].nil? || n["id"].empty?
60
+
52
61
  c.increment(n)
53
- idx = examples.size == 1 && !n["number"] ? "" : c.print
62
+ idx = increment_label(examples, n, c, false)
54
63
  @anchors[n["id"]] = {
55
64
  type: "termexample", label: idx, value: c.print,
56
65
  xref: l10n("#{anchor(t['id'], :xref)}, "\
57
- "#{@labels["example_xref"]} #{c.print}") }
66
+ "#{@labels['example_xref']} #{c.print}") }
58
67
  end
59
68
  end
60
69
  end
@@ -81,9 +90,10 @@ module IsoDoc::XrefGen
81
90
  c = Counter.new
82
91
  notes.each do |n|
83
92
  next if @anchors[n["id"]] || n["id"].nil? || n["id"].empty?
84
- idx = notes.size == 1 && !n["number"] ? "" : " #{c.increment(n).print}"
85
- @anchors[n["id"]] = anchor_struct(idx, n, @labels["note_xref"],
86
- "note", false)
93
+
94
+ @anchors[n["id"]] =
95
+ anchor_struct(increment_label(notes, n, c), n,
96
+ @labels["note_xref"], "note", false)
87
97
  end
88
98
  note_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
89
99
  end
@@ -94,18 +104,19 @@ module IsoDoc::XrefGen
94
104
  "not(self::xmlns:terms) and not(self::xmlns:definitions)]//"\
95
105
  "xmlns:example | ./xmlns:example".freeze
96
106
 
97
- CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | ./references"
107
+ CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | "\
108
+ "./references"
98
109
 
99
110
  def example_anchor_names(sections)
100
111
  sections.each do |s|
101
112
  notes = s.xpath(CHILD_EXAMPLES_XPATH)
102
113
  c = Counter.new
103
114
  notes.each do |n|
104
- next if @anchors[n["id"]]
105
- next if n["id"].nil? || n["id"].empty?
106
- idx = notes.size == 1 && !n["number"] ? "" : " #{c.increment(n).print}"
107
- @anchors[n["id"]] = anchor_struct(idx, n, @labels["example_xref"],
108
- "example", n["unnumbered"])
115
+ next if @anchors[n["id"]] || n["id"].nil? || n["id"].empty?
116
+
117
+ @anchors[n["id"]] =
118
+ anchor_struct(increment_label(notes, n, c), n,
119
+ @labels["example_xref"], "example", n["unnumbered"])
109
120
  end
110
121
  example_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
111
122
  end
@@ -118,8 +129,9 @@ module IsoDoc::XrefGen
118
129
  c = Counter.new
119
130
  notes.each do |n|
120
131
  next if n["id"].nil? || n["id"].empty?
121
- idx = notes.size == 1 && !n["number"] ? "" : " #{c.increment(n).print}"
122
- @anchors[n["id"]] = anchor_struct(idx, n, @labels["list"], "list", false)
132
+
133
+ @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n,
134
+ @labels["list"], "list", false)
123
135
  list_item_anchor_names(n, @anchors[n["id"]], 1, "", notes.size != 1)
124
136
  end
125
137
  list_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
@@ -141,17 +153,18 @@ module IsoDoc::XrefGen
141
153
  end
142
154
  end
143
155
 
144
- def bookmark_anchor_names(sections)
145
- sections.each do |s|
146
- notes = s.xpath(ns(".//bookmark")) - s.xpath(ns(".//clause//bookmark")) -
147
- s.xpath(ns(".//appendix//bookmark"))
148
- notes.each do |n|
149
- next if n["id"].nil? || n["id"].empty?
150
- @anchors[n["id"]] = {
151
- type: "bookmark", label: nil, value: nil,
152
- xref: @anchors[s["id"]][:xref] }
156
+ def bookmark_anchor_names(docxml)
157
+ docxml.xpath(ns(".//bookmark")).each do |n|
158
+ next if n["id"].nil? || n["id"].empty?
159
+
160
+ parent = nil
161
+ n.ancestors.each do |a|
162
+ next unless a["id"] && parent = @anchors.dig(a["id"], :xref)
163
+
164
+ break
153
165
  end
154
- bookmark_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
166
+ @anchors[n["id"]] = { type: "bookmark", label: nil, value: nil,
167
+ xref: parent || "???" }
155
168
  end
156
169
  end
157
170
  end
@@ -14,25 +14,24 @@ module IsoDoc::XrefGen
14
14
  end
15
15
  end
16
16
 
17
- def initial_anchor_names(d)
18
- d.xpath(ns("//preface/*")).each { |c| c.element? and preface_names(c) }
17
+ def initial_anchor_names(doc)
18
+ doc.xpath(ns("//preface/*")).each { |c| c.element? and preface_names(c) }
19
19
  # potentially overridden in middle_section_asset_names()
20
- sequential_asset_names(d.xpath(ns("//preface/*")))
20
+ sequential_asset_names(doc.xpath(ns("//preface/*")))
21
21
  n = Counter.new
22
- n = section_names(d.at(ns("//clause[@type = 'scope']")), n, 1)
23
- n = section_names(d.at(ns(@klass.norm_ref_xpath)), n, 1)
24
- n = section_names(d.at(ns("//sections/terms | "\
22
+ n = section_names(doc.at(ns("//clause[@type = 'scope']")), n, 1)
23
+ n = section_names(doc.at(ns(@klass.norm_ref_xpath)), n, 1)
24
+ n = section_names(doc.at(ns("//sections/terms | "\
25
25
  "//sections/clause[descendant::terms]")), n, 1)
26
- n = section_names(d.at(ns("//sections/definitions")), n, 1)
27
- clause_names(d, n)
28
- middle_section_asset_names(d)
29
- termnote_anchor_names(d)
30
- termexample_anchor_names(d)
26
+ n = section_names(doc.at(ns("//sections/definitions")), n, 1)
27
+ clause_names(doc, n)
28
+ middle_section_asset_names(doc)
29
+ termnote_anchor_names(doc)
30
+ termexample_anchor_names(doc)
31
31
  end
32
32
 
33
- def preface_clause_name(c)
34
- ret = c.at(ns("./title"))&.text || c.name.capitalize
35
- ret
33
+ def preface_clause_name(clause)
34
+ clause.at(ns("./title"))&.text || clause.name.capitalize
36
35
  end
37
36
 
38
37
  SUBCLAUSES =
@@ -41,12 +40,13 @@ module IsoDoc::XrefGen
41
40
  # in StanDoc, prefaces have no numbering; they are referenced only by title
42
41
  def preface_names(clause)
43
42
  return if clause.nil?
43
+
44
44
  @anchors[clause["id"]] =
45
45
  { label: nil, level: 1, xref: preface_clause_name(clause),
46
46
  type: "clause" }
47
47
  clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i|
48
48
  preface_names1(c, c.at(ns("./title"))&.text,
49
- "#{preface_clause_name(clause)}, #{i+1}", 2)
49
+ "#{preface_clause_name(clause)}, #{i + 1}", 2)
50
50
  end
51
51
  end
52
52
 
@@ -55,7 +55,7 @@ module IsoDoc::XrefGen
55
55
  @anchors[clause["id"]] =
56
56
  { label: nil, level: level, xref: label, type: "clause" }
57
57
  clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i|
58
- preface_names1(c, c.at(ns("./title"))&.text, "#{label} #{i+1}",
58
+ preface_names1(c, c.at(ns("./title"))&.text, "#{label} #{i + 1}",
59
59
  level + 1)
60
60
  end
61
61
  end
@@ -69,17 +69,18 @@ module IsoDoc::XrefGen
69
69
  end
70
70
 
71
71
  def clause_names(docxml, n)
72
- docxml.xpath(ns(@klass.middle_clause(docxml))).each_with_index do |c, i|
72
+ docxml.xpath(ns(@klass.middle_clause(docxml))).each_with_index do |c, _i|
73
73
  section_names(c, n, 1)
74
74
  end
75
75
  end
76
76
 
77
77
  def section_names(clause, num, lvl)
78
78
  return num if clause.nil?
79
+
79
80
  num.increment(clause)
80
81
  @anchors[clause["id"]] =
81
- { label: num.print, xref: l10n("#{@labels["clause"]} #{num.print}"), level: lvl,
82
- type: "clause" }
82
+ { label: num.print, xref: l10n("#{@labels['clause']} #{num.print}"),
83
+ level: lvl, type: "clause" }
83
84
  i = Counter.new
84
85
  clause.xpath(ns(SUBCLAUSES)).each do |c|
85
86
  i.increment(c)
@@ -90,7 +91,7 @@ module IsoDoc::XrefGen
90
91
 
91
92
  def section_names1(clause, num, level)
92
93
  @anchors[clause["id"]] =
93
- { label: num, level: level, xref: l10n("#{@labels["clause"]} #{num}"),
94
+ { label: num, level: level, xref: l10n("#{@labels['clause']} #{num}"),
94
95
  type: "clause" }
95
96
  i = Counter.new
96
97
  clause.xpath(ns(SUBCLAUSES)).each do |c|
@@ -100,26 +101,27 @@ module IsoDoc::XrefGen
100
101
  end
101
102
 
102
103
  def annex_name_lbl(clause, num)
103
- obl = l10n("(#{@labels["inform_annex"]})")
104
- obl = l10n("(#{@labels["norm_annex"]})") if clause["obligation"] == "normative"
105
- l10n("<strong>#{@labels["annex"]} #{num}</strong><br/>#{obl}")
104
+ obl = l10n("(#{@labels['inform_annex']})")
105
+ clause["obligation"] == "normative" and
106
+ obl = l10n("(#{@labels['norm_annex']})")
107
+ l10n("<strong>#{@labels['annex']} #{num}</strong><br/>#{obl}")
106
108
  end
107
109
 
108
110
  def single_annex_special_section(clause)
109
111
  a = clause.xpath(ns("./references | ./terms | ./definitions"))
110
112
  a.size == 1 or return nil
111
113
  clause.xpath(ns("./clause | ./p | ./table | ./ol | ./ul | ./dl | "\
112
- "./note | ./admonition | ./figure")).size == 0 or
113
- return nil
114
+ "./note | ./admonition | ./figure")).empty? or
115
+ return nil
114
116
  a[0]
115
117
  end
116
118
 
117
119
  def annex_names(clause, num)
118
120
  @anchors[clause["id"]] = { label: annex_name_lbl(clause, num),
119
121
  type: "clause", value: num.to_s,
120
- xref: "#{@labels["annex"]} #{num}", level: 1 }
122
+ xref: "#{@labels['annex']} #{num}", level: 1 }
121
123
  if a = single_annex_special_section(clause)
122
- annex_names1(a, "#{num}", 1)
124
+ annex_names1(a, num.to_s, 1)
123
125
  else
124
126
  i = Counter.new
125
127
  clause.xpath(ns(SUBCLAUSES)).each do |c|
@@ -131,10 +133,10 @@ module IsoDoc::XrefGen
131
133
  end
132
134
 
133
135
  def annex_names1(clause, num, level)
134
- @anchors[clause["id"]] = { label: num, xref: "#{@labels["annex"]} #{num}",
136
+ @anchors[clause["id"]] = { label: num, xref: "#{@labels['annex']} #{num}",
135
137
  level: level, type: "clause" }
136
138
  i = Counter.new
137
- clause.xpath(ns(SUBCLAUSES)).each_with_index do |c|
139
+ clause.xpath(ns(SUBCLAUSES)).each do |c|
138
140
  i.increment(c)
139
141
  annex_names1(c, "#{num}.#{i.print}", level + 1)
140
142
  end
@@ -147,10 +149,10 @@ module IsoDoc::XrefGen
147
149
  "xmlns:name = 'International Electrotechnical Commission']".freeze
148
150
 
149
151
  def reference_names(ref)
150
- isopub = ref.at(ns(ISO_PUBLISHER_XPATH))
152
+ # isopub = ref.at(ns(ISO_PUBLISHER_XPATH))
151
153
  ids = @klass.bibitem_ref_code(ref)
152
154
  identifiers = @klass.render_identifier(ids)
153
- date = ref.at(ns("./date[@type = 'published']"))
155
+ # date = ref.at(ns("./date[@type = 'published']"))
154
156
  reference = @klass.docid_l10n(identifiers[0] || identifiers[1])
155
157
  @anchors[ref["id"]] = { xref: reference }
156
158
  end
@@ -2,50 +2,61 @@ require "metanorma"
2
2
 
3
3
  module IsoDoc
4
4
  class XslfoPdfConvert < ::IsoDoc::Convert
5
+ MN2PDF_OPTIONS = :mn2pdf
6
+ MN2PDF_FONT_MANIFEST = :font_manifest_file
5
7
 
6
8
  def initialize(options)
9
+ @format = :pdf
10
+ @suffix = "pdf"
7
11
  super
8
- @maxwidth = 500
9
- @maxheight = 800
10
12
  end
11
13
 
12
14
  def tmpimagedir_suffix
13
15
  "_pdfimages"
14
16
  end
15
17
 
16
- def initialize(options)
17
- @format = :pdf
18
- @suffix = "pdf"
19
- super
20
- end
21
-
22
- def pdf_stylesheet(docxml)
18
+ def pdf_stylesheet(_docxml)
23
19
  nil
24
20
  end
25
21
 
26
- def pdf_options(docxml)
27
- ""
22
+ def pdf_options(_docxml)
23
+ if font_manifest_file = @options.dig(MN2PDF_OPTIONS,
24
+ MN2PDF_FONT_MANIFEST)
25
+ "--font-manifest #{font_manifest_file}"
26
+ else
27
+ ""
28
+ end
28
29
  end
29
30
 
30
- def convert(input_filename, file = nil, debug = false, output_filename = nil)
31
+ def convert(input_filename, file = nil, debug = false,
32
+ output_filename = nil)
31
33
  file = File.read(input_filename, encoding: "utf-8") if file.nil?
32
- docxml, filename, dir = convert_init(file, input_filename, debug)
33
- /\.xml$/.match(input_filename) or
34
- input_filename = Tempfile.open([filename, ".xml"], encoding: "utf-8") do |f|
35
- f.write file
34
+ input_filename, docxml, filename = input_xml_path(input_filename,
35
+ file, debug)
36
+ ::Metanorma::Output::XslfoPdf.new.convert(
37
+ input_filename,
38
+ output_filename || "#{filename}.#{@suffix}",
39
+ File.join(@libdir, pdf_stylesheet(docxml)),
40
+ pdf_options(docxml)
41
+ )
42
+ end
43
+
44
+ def xref_parse(node, out)
45
+ out.a(**{ "href": target_pdf(node) }) { |l| l << get_linkend(node) }
46
+ end
47
+
48
+ def input_xml_path(input_filename, xml_file, debug)
49
+ docxml, filename, dir = convert_init(xml_file, input_filename, debug)
50
+ unless /\.xml$/.match?(input_filename)
51
+ input_filename = Tempfile.open([filename, ".xml"],
52
+ encoding: "utf-8") do |f|
53
+ f.write xml_file
36
54
  f.path
37
55
  end
56
+ end
38
57
  FileUtils.rm_rf dir
39
- ::Metanorma::Output::XslfoPdf.new.convert(input_filename,
40
- output_filename || "#{filename}.#{@suffix}",
41
- File.join(@libdir, pdf_stylesheet(docxml)),
42
- pdf_options(docxml))
43
- end
44
58
 
45
- def xref_parse(node, out)
46
- target = /#/.match(node["target"]) ? node["target"].sub(/#/, ".pdf#") :
47
- "##{node["target"]}"
48
- out.a(**{ "href": target }) { |l| l << get_linkend(node) }
59
+ [input_filename, docxml, filename]
49
60
  end
50
61
  end
51
62
  end