isodoc 1.0.26 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +12 -8
  3. data/.github/workflows/ubuntu.yml +26 -16
  4. data/.github/workflows/windows.yml +12 -8
  5. data/isodoc.gemspec +2 -2
  6. data/lib/isodoc.rb +2 -0
  7. data/lib/isodoc/common.rb +0 -4
  8. data/lib/isodoc/convert.rb +18 -8
  9. data/lib/isodoc/function/blocks.rb +43 -54
  10. data/lib/isodoc/function/blocks_example_note.rb +108 -0
  11. data/lib/isodoc/function/cleanup.rb +14 -2
  12. data/lib/isodoc/function/i18n.rb +1 -0
  13. data/lib/isodoc/function/inline.rb +76 -82
  14. data/lib/isodoc/function/inline_simple.rb +72 -0
  15. data/lib/isodoc/function/lists.rb +12 -6
  16. data/lib/isodoc/function/references.rb +65 -57
  17. data/lib/isodoc/function/reqt.rb +14 -5
  18. data/lib/isodoc/function/section.rb +8 -11
  19. data/lib/isodoc/function/table.rb +4 -5
  20. data/lib/isodoc/function/terms.rb +3 -3
  21. data/lib/isodoc/function/to_word_html.rb +22 -13
  22. data/lib/isodoc/function/utils.rb +9 -3
  23. data/lib/isodoc/headlesshtml_convert.rb +7 -6
  24. data/lib/isodoc/html_convert.rb +2 -1
  25. data/lib/isodoc/html_function/footnotes.rb +1 -1
  26. data/lib/isodoc/html_function/html.rb +16 -1
  27. data/lib/isodoc/html_function/postprocess.rb +6 -5
  28. data/lib/isodoc/metadata.rb +6 -0
  29. data/lib/isodoc/pdf_convert.rb +8 -6
  30. data/lib/isodoc/presentation_xml_convert.rb +29 -0
  31. data/lib/isodoc/version.rb +1 -1
  32. data/lib/isodoc/word_convert.rb +2 -1
  33. data/lib/isodoc/word_function/body.rb +14 -48
  34. data/lib/isodoc/word_function/footnotes.rb +1 -1
  35. data/lib/isodoc/word_function/inline.rb +75 -0
  36. data/lib/isodoc/word_function/postprocess.rb +1 -0
  37. data/lib/isodoc/word_function/table.rb +3 -3
  38. data/lib/isodoc/xref.rb +59 -0
  39. data/lib/isodoc/{function → xref}/xref_anchor.rb +10 -21
  40. data/lib/isodoc/xref/xref_counter.rb +74 -0
  41. data/lib/isodoc/{function → xref}/xref_gen.rb +9 -22
  42. data/lib/isodoc/{function → xref}/xref_gen_seq.rb +41 -32
  43. data/lib/isodoc/{function → xref}/xref_sect_gen.rb +33 -23
  44. data/lib/isodoc/xslfo_convert.rb +16 -4
  45. data/spec/assets/i18n.yaml +4 -1
  46. data/spec/assets/odf.emf +0 -0
  47. data/spec/assets/odf.svg +4 -0
  48. data/spec/assets/odf1.svg +4 -0
  49. data/spec/isodoc/blocks_spec.rb +240 -59
  50. data/spec/isodoc/cleanup_spec.rb +139 -17
  51. data/spec/isodoc/footnotes_spec.rb +20 -5
  52. data/spec/isodoc/inline_spec.rb +296 -1
  53. data/spec/isodoc/lists_spec.rb +8 -8
  54. data/spec/isodoc/metadata_spec.rb +110 -3
  55. data/spec/isodoc/postproc_spec.rb +10 -14
  56. data/spec/isodoc/presentation_xml_spec.rb +20 -0
  57. data/spec/isodoc/ref_spec.rb +119 -50
  58. data/spec/isodoc/section_spec.rb +84 -18
  59. data/spec/isodoc/table_spec.rb +28 -28
  60. data/spec/isodoc/terms_spec.rb +7 -7
  61. data/spec/isodoc/xref_spec.rb +177 -57
  62. metadata +24 -17
  63. data/lib/isodoc/function/blocks_example.rb +0 -53
  64. data/lib/isodoc/function/xref_counter.rb +0 -50
@@ -32,6 +32,7 @@ xmlns:m="http://schemas.microsoft.com/office/2004/12/omml">
32
32
  end
33
33
 
34
34
  def postprocess(result, filename, dir)
35
+ filename = filename.sub(/\.doc$/, "")
35
36
  header = generate_header(filename, dir)
36
37
  result = from_xhtml(cleanup(to_xhtml(textcleanup(result))))
37
38
  toWord(result, filename, dir, header)
@@ -33,12 +33,12 @@ module IsoDoc::WordFunction
33
33
  align: td["align"], style: style.gsub(/\n/, "") }
34
34
  end
35
35
 
36
- def make_table_attr(node)
36
+ def table_attrs(node)
37
37
  super.merge(attr_code({
38
38
  summary: node["summary"],
39
39
  width: node["width"],
40
40
  style: "mso-table-anchor-horizontal:column;"\
41
- "mso-table-overlap:never;border-spacing:0;border-width:1px;"
41
+ "mso-table-overlap:never;border-spacing:0;border-width:1px;#{keep_style(node)}"
42
42
  }))
43
43
  end
44
44
 
@@ -46,7 +46,7 @@ module IsoDoc::WordFunction
46
46
  @in_table = true
47
47
  table_title_parse(node, out)
48
48
  out.div **{ align: "center", class: "table_container" } do |div|
49
- div.table **make_table_attr(node) do |t|
49
+ div.table **table_attrs(node) do |t|
50
50
  thead_parse(node, t)
51
51
  tbody_parse(node, t)
52
52
  tfoot_parse(node, t)
@@ -0,0 +1,59 @@
1
+ require_relative "xref/xref_anchor"
2
+ require_relative "xref/xref_counter"
3
+ require_relative "xref/xref_gen_seq"
4
+ require_relative "xref/xref_gen"
5
+ require_relative "xref/xref_sect_gen"
6
+ require_relative "class_utils"
7
+
8
+ module IsoDoc
9
+ class Xref
10
+ include XrefGen::Anchor
11
+ include XrefGen::Blocks
12
+ include XrefGen::Sections
13
+
14
+ def initialize(lang, script, klass, labels, options = {})
15
+ @anchors = {}
16
+ @lang = lang
17
+ @script = script
18
+ @klass = klass
19
+ @labels = labels
20
+ @options = options
21
+ end
22
+
23
+ def get
24
+ @anchors
25
+ end
26
+
27
+ def anchor(id, lbl, warning = true)
28
+ return nil if id.nil? || id.empty?
29
+ unless @anchors[id]
30
+ if warning
31
+ @seen ||= Seen_Anchor.instance
32
+ @seen.seen(id) or warn "No label has been processed for ID #{id}"
33
+ @seen.add(id)
34
+ return "[#{id}]"
35
+ end
36
+ end
37
+ @anchors.dig(id, lbl)
38
+ end
39
+
40
+ # extract names for all anchors, xref and label
41
+ def parse(docxml)
42
+ initial_anchor_names(docxml)
43
+ back_anchor_names(docxml)
44
+ # preempt clause notes with all other types of note (ISO default)
45
+ note_anchor_names(docxml.xpath(ns("//table | //figure")))
46
+ note_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
47
+ example_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
48
+ list_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
49
+ end
50
+
51
+ def ns(xpath)
52
+ Common::ns(xpath)
53
+ end
54
+
55
+ def l10n(a, lang = @lang, script = @script)
56
+ IsoDoc::Function::I18n::l10n(a, lang, script)
57
+ end
58
+ end
59
+ end
@@ -1,7 +1,7 @@
1
1
  require "singleton"
2
2
 
3
- module IsoDoc::Function
4
- module XrefGen
3
+ module IsoDoc::XrefGen
4
+ module Anchor
5
5
  class Seen_Anchor
6
6
  include Singleton
7
7
 
@@ -12,34 +12,23 @@ module IsoDoc::Function
12
12
  def seen(x)
13
13
  @seen.has_key?(x)
14
14
  end
15
-
15
+
16
16
  def add(x)
17
17
  @seen[x] = true
18
18
  end
19
19
  end
20
20
 
21
- @anchors = {}
21
+ def initialize()
22
+ @anchors = {}
23
+ end
22
24
 
23
25
  def get_anchors
24
26
  @anchors
25
27
  end
26
28
 
27
- def anchor(id, lbl, warning = true)
28
- return nil if id.nil? || id.empty?
29
- unless @anchors[id]
30
- if warning
31
- @seen ||= Seen_Anchor.instance
32
- @seen.seen(id) or warn "No label has been processed for ID #{id}"
33
- @seen.add(id)
34
- return "[#{id}]"
35
- end
36
- end
37
- @anchors.dig(id, lbl)
38
- end
39
-
40
29
  def anchor_struct_label(lbl, elem)
41
30
  case elem
42
- when @appendix_lbl then l10n("#{elem} #{lbl}")
31
+ when @labels["appendix"] then l10n("#{elem} #{lbl}")
43
32
  else
44
33
  lbl.to_s
45
34
  end
@@ -47,8 +36,8 @@ module IsoDoc::Function
47
36
 
48
37
  def anchor_struct_xref(lbl, elem)
49
38
  case elem
50
- when @formula_lbl then l10n("#{elem} (#{lbl})")
51
- when @inequality_lbl then l10n("#{elem} (#{lbl})")
39
+ when @labels["formula"] then l10n("#{elem} (#{lbl})")
40
+ when @labels["inequality"] then l10n("#{elem} (#{lbl})")
52
41
  else
53
42
  l10n("#{elem} #{lbl}")
54
43
  end
@@ -59,7 +48,7 @@ module IsoDoc::Function
59
48
  ret[:label] = unnumbered == "true" ? nil : anchor_struct_label(lbl, elem)
60
49
  ret[:xref] = anchor_struct_xref(unnumbered == "true" ? "(??)" : lbl, elem)
61
50
  ret[:xref].gsub!(/ $/, "")
62
- ret[:container] = get_clause_id(container) unless container.nil?
51
+ ret[:container] = @klass.get_clause_id(container) unless container.nil?
63
52
  ret[:type] = type
64
53
  ret
65
54
  end
@@ -0,0 +1,74 @@
1
+ require "roman-numerals"
2
+
3
+ module IsoDoc::XrefGen
4
+ class Counter
5
+ def initialize
6
+ @num = 0
7
+ @letter = ""
8
+ @subseq = ""
9
+ @letter_override = nil
10
+ @number_override = nil
11
+ end
12
+
13
+ def new_subseq_increment(node)
14
+ @subseq = node["subsequence"]
15
+ @num += 1
16
+ @letter = node["subsequence"] ? "a" : ""
17
+ if node["number"]
18
+ /^(?<n>\d*)(?<a>[a-z]*)$/ =~ node["number"]
19
+ if n || a
20
+ @letter_override = @letter = a if a
21
+ @number_override = @num = n.to_i if n
22
+ else
23
+ @letter_override = node["number"]
24
+ @letter = @letter_override if /^[a-z]$/.match(@letter_override)
25
+ end
26
+ end
27
+ end
28
+
29
+ def sequence_increment(node)
30
+ if node["number"]
31
+ @number_override = node["number"]
32
+ @num = @number_override.to_i if /^\d+$/.match(@number_override)
33
+ else
34
+ @num += 1
35
+ end
36
+ end
37
+
38
+ def subsequence_increment(node)
39
+ if node["number"]
40
+ @letter_override = node["number"]
41
+ @letter = @letter_override if /^[a-z]$/.match(@letter_override)
42
+ else
43
+ @letter = (@letter.ord + 1).chr.to_s
44
+ end
45
+ end
46
+
47
+ def increment(node)
48
+ return self if node["unnumbered"]
49
+ @letter_override = nil
50
+ @number_override = nil
51
+ if node["subsequence"] != @subseq
52
+ new_subseq_increment(node)
53
+ elsif @letter.empty?
54
+ sequence_increment(node)
55
+ else
56
+ subsequence_increment(node)
57
+ end
58
+ self
59
+ end
60
+
61
+ def print
62
+ "#{@number_override || @num}#{@letter_override || @letter}"
63
+ end
64
+
65
+ def listlabel(depth)
66
+ return @num.to_s if [2, 7].include? depth
67
+ return (96 + @num).chr.to_s if [1, 6].include? depth
68
+ return (64 + @num).chr.to_s if [4, 9].include? depth
69
+ return RomanNumerals.to_roman(@num).downcase if [3, 8].include? depth
70
+ return RomanNumerals.to_roman(@num).upcase if [5, 10].include? depth
71
+ return @num.to_s
72
+ end
73
+ end
74
+ end
@@ -1,11 +1,9 @@
1
- require_relative "xref_counter"
2
- require_relative "xref_anchor"
3
- require_relative "xref_gen_seq"
1
+ require_relative "xref_gen_seq.rb"
4
2
 
5
- module IsoDoc::Function
6
- module XrefGen
3
+ module IsoDoc::XrefGen
4
+ module Blocks
7
5
  def termnote_label(n)
8
- @termnote_lbl.gsub(/%/, n.to_s)
6
+ @labels["termnote"].gsub(/%/, n.to_s)
9
7
  end
10
8
 
11
9
  def termnote_anchor_names(docxml)
@@ -17,7 +15,7 @@ module IsoDoc::Function
17
15
  @anchors[n["id"]] =
18
16
  { label: termnote_label(c.print), type: "termnote",
19
17
  xref: l10n("#{anchor(t['id'], :xref)}, "\
20
- "#{@note_xref_lbl} #{c.print}") }
18
+ "#{@labels["note_xref"]} #{c.print}") }
21
19
  end
22
20
  end
23
21
  end
@@ -33,7 +31,7 @@ module IsoDoc::Function
33
31
  @anchors[n["id"]] = {
34
32
  type: "termexample", label: idx,
35
33
  xref: l10n("#{anchor(t['id'], :xref)}, "\
36
- "#{@example_xref_lbl} #{c.print}") }
34
+ "#{@labels["example_xref"]} #{c.print}") }
37
35
  end
38
36
  end
39
37
  end
@@ -57,7 +55,7 @@ module IsoDoc::Function
57
55
  notes.each do |n|
58
56
  next if @anchors[n["id"]] || n["id"].nil? || n["id"].empty?
59
57
  idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
60
- @anchors[n["id"]] = anchor_struct(idx, n, @note_xref_lbl,
58
+ @anchors[n["id"]] = anchor_struct(idx, n, @labels["note_xref"],
61
59
  "note", false)
62
60
  end
63
61
  note_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
@@ -79,7 +77,7 @@ module IsoDoc::Function
79
77
  next if @anchors[n["id"]]
80
78
  next if n["id"].nil? || n["id"].empty?
81
79
  idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
82
- @anchors[n["id"]] = anchor_struct(idx, n, @example_xref_lbl,
80
+ @anchors[n["id"]] = anchor_struct(idx, n, @labels["example_xref"],
83
81
  "example", n["unnumbered"])
84
82
  end
85
83
  example_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
@@ -94,7 +92,7 @@ module IsoDoc::Function
94
92
  notes.each do |n|
95
93
  next if n["id"].nil? || n["id"].empty?
96
94
  idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
97
- @anchors[n["id"]] = anchor_struct(idx, n, @list_lbl, "list", false)
95
+ @anchors[n["id"]] = anchor_struct(idx, n, @labels["list"], "list", false)
98
96
  list_item_anchor_names(n, @anchors[n["id"]], 1, "", notes.size != 1)
99
97
  end
100
98
  list_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
@@ -115,16 +113,5 @@ module IsoDoc::Function
115
113
  end
116
114
  end
117
115
  end
118
-
119
- # extract names for all anchors, xref and label
120
- def anchor_names(docxml)
121
- initial_anchor_names(docxml)
122
- back_anchor_names(docxml)
123
- # preempt clause notes with all other types of note (ISO default)
124
- note_anchor_names(docxml.xpath(ns("//table | //figure")))
125
- note_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
126
- example_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
127
- list_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
128
- end
129
116
  end
130
117
  end
@@ -1,19 +1,32 @@
1
- module IsoDoc::Function
2
- module XrefGen
1
+ module IsoDoc::XrefGen
2
+ module Blocks
3
+ def hiersep
4
+ "."
5
+ end
6
+
7
+ def hierfigsep
8
+ "-"
9
+ end
10
+
11
+ def subfigure_increment(j, c, t)
12
+ if t.parent.name == "figure" then j += 1
13
+ else
14
+ j = 0
15
+ c.increment(t)
16
+ end
17
+ j
18
+ end
19
+
3
20
  def sequential_figure_names(clause)
4
21
  c = Counter.new
5
22
  j = 0
6
23
  clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]")).
7
24
  each do |t|
8
- if t.parent.name == "figure" then j += 1
9
- else
10
- j = 0
11
- c.increment(t)
12
- end
25
+ j = subfigure_increment(j, c, t)
13
26
  label = c.print + (j.zero? ? "" : "-#{j}")
14
27
  next if t["id"].nil? || t["id"].empty?
15
28
  @anchors[t["id"]] =
16
- anchor_struct(label, nil, @figure_lbl, "figure", t["unnumbered"])
29
+ anchor_struct(label, nil, @labels["figure"], "figure", t["unnumbered"])
17
30
  end
18
31
  end
19
32
 
@@ -22,7 +35,7 @@ module IsoDoc::Function
22
35
  clause.xpath(ns(".//table")).each do |t|
23
36
  next if t["id"].nil? || t["id"].empty?
24
37
  @anchors[t["id"]] = anchor_struct(c.increment(t).print, nil,
25
- @table_lbl, "table", t["unnumbered"])
38
+ @labels["table"], "table", t["unnumbered"])
26
39
  end
27
40
  end
28
41
 
@@ -32,7 +45,7 @@ module IsoDoc::Function
32
45
  next if t["id"].nil? || t["id"].empty?
33
46
  @anchors[t["id"]] =
34
47
  anchor_struct(c.increment(t).print, t,
35
- t["inequality"] ? @inequality_lbl : @formula_lbl,
48
+ t["inequality"] ? @labels["inequality"] : @labels["formula"],
36
49
  "formula", t["unnumbered"])
37
50
  end
38
51
  end
@@ -51,9 +64,9 @@ module IsoDoc::Function
51
64
  end
52
65
 
53
66
  def sequential_permission_names2(t, id)
54
- sequential_permission_names1(t, id, "permission", @permission_lbl)
55
- sequential_permission_names1(t, id, "requirement", @requirement_lbl)
56
- sequential_permission_names1(t, id, "recommendation", @recommendation_lbl)
67
+ sequential_permission_names1(t, id, "permission", @labels["permission"])
68
+ sequential_permission_names1(t, id, "requirement", @labels["requirement"])
69
+ sequential_permission_names1(t, id, "recommendation", @labels["recommendation"])
57
70
  end
58
71
 
59
72
  def sequential_permission_names1(block, lbl, klass, label)
@@ -70,9 +83,9 @@ module IsoDoc::Function
70
83
  sequential_table_names(clause)
71
84
  sequential_figure_names(clause)
72
85
  sequential_formula_names(clause)
73
- sequential_permission_names(clause, "permission", @permission_lbl)
74
- sequential_permission_names(clause, "requirement", @requirement_lbl)
75
- sequential_permission_names(clause, "recommendation", @recommendation_lbl)
86
+ sequential_permission_names(clause, "permission", @labels["permission"])
87
+ sequential_permission_names(clause, "requirement", @labels["requirement"])
88
+ sequential_permission_names(clause, "recommendation", @labels["recommendation"])
76
89
  end
77
90
 
78
91
  def hierarchical_figure_names(clause, num)
@@ -80,15 +93,11 @@ module IsoDoc::Function
80
93
  j = 0
81
94
  clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]")).
82
95
  each do |t|
83
- if t.parent.name == "figure" then j += 1
84
- else
85
- j = 0
86
- c.increment(t)
87
- end
96
+ j = subfigure_increment(j, c, t)
88
97
  label = "#{num}#{hiersep}#{c.print}" +
89
98
  (j.zero? ? "" : "#{hierfigsep}#{j}")
90
99
  next if t["id"].nil? || t["id"].empty?
91
- @anchors[t["id"]] = anchor_struct(label, nil, @figure_lbl, "figure",
100
+ @anchors[t["id"]] = anchor_struct(label, nil, @labels["figure"], "figure",
92
101
  t["unnumbered"])
93
102
  end
94
103
  end
@@ -99,7 +108,7 @@ module IsoDoc::Function
99
108
  next if t["id"].nil? || t["id"].empty?
100
109
  @anchors[t["id"]] =
101
110
  anchor_struct("#{num}#{hiersep}#{c.increment(t).print}",
102
- nil, @table_lbl, "table", t["unnumbered"])
111
+ nil, @labels["table"], "table", t["unnumbered"])
103
112
  end
104
113
  end
105
114
 
@@ -107,11 +116,11 @@ module IsoDoc::Function
107
116
  hierarchical_table_names(clause, num)
108
117
  hierarchical_figure_names(clause, num)
109
118
  hierarchical_formula_names(clause, num)
110
- hierarchical_permission_names(clause, num, "permission", @permission_lbl)
119
+ hierarchical_permission_names(clause, num, "permission", @labels["permission"])
111
120
  hierarchical_permission_names(clause, num, "requirement",
112
- @requirement_lbl)
121
+ @labels["requirement"])
113
122
  hierarchical_permission_names(clause, num, "recommendation",
114
- @recommendation_lbl)
123
+ @labels["recommendation"])
115
124
  end
116
125
 
117
126
  def hierarchical_formula_names(clause, num)
@@ -120,7 +129,7 @@ module IsoDoc::Function
120
129
  next if t["id"].nil? || t["id"].empty?
121
130
  @anchors[t["id"]] =
122
131
  anchor_struct("#{num}#{hiersep}#{c.increment(t).print}", nil,
123
- t["inequality"] ? @inequality_lbl : @formula_lbl,
132
+ t["inequality"] ? @labels["inequality"] : @labels["formula"],
124
133
  "formula", t["unnumbered"])
125
134
  end
126
135
  end
@@ -135,13 +144,13 @@ module IsoDoc::Function
135
144
  end
136
145
  end
137
146
 
138
- def hierarchical_permission_names2(t, id)
139
- hierarchical_permission_names1(t, id, "permission", @permission_lbl)
140
- hierarchical_permission_names1(t, id, "requirement", @requirement_lbl)
141
- hierarchical_permission_names1(t, id, "recommendation", @recommendation_lbl)
147
+ def hierarchical_permission_names2(t, id)
148
+ hierarchical_permission_names1(t, id, "permission", @labels["permission"])
149
+ hierarchical_permission_names1(t, id, "requirement", @labels["requirement"])
150
+ hierarchical_permission_names1(t, id, "recommendation", @labels["recommendation"])
142
151
  end
143
152
 
144
- def hierarchical_permission_names1(block, lbl, klass, label)
153
+ def hierarchical_permission_names1(block, lbl, klass, label)
145
154
  c = Counter.new
146
155
  block.xpath(ns("./#{klass}")).each do |t|
147
156
  next if t["id"].nil? || t["id"].empty?