coradoc 1.1.5 → 1.1.7

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.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +1 -0
  3. data/.irbrc +1 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +5 -1
  6. data/.rubocop_todo.yml +179 -0
  7. data/Gemfile +11 -0
  8. data/README.adoc +5 -7
  9. data/coradoc.gemspec +5 -16
  10. data/exe/reverse_adoc +1 -1
  11. data/exe/w2a +1 -1
  12. data/flake.lock +114 -0
  13. data/flake.nix +135 -0
  14. data/lib/coradoc/cli.rb +1 -1
  15. data/lib/coradoc/converter.rb +4 -5
  16. data/lib/coradoc/element/attribute.rb +10 -1
  17. data/lib/coradoc/element/attribute_list.rb +4 -3
  18. data/lib/coradoc/element/audio.rb +1 -1
  19. data/lib/coradoc/element/author.rb +2 -2
  20. data/lib/coradoc/element/base.rb +14 -2
  21. data/lib/coradoc/element/bibliography.rb +1 -1
  22. data/lib/coradoc/element/bibliography_entry.rb +1 -1
  23. data/lib/coradoc/element/block/open.rb +1 -1
  24. data/lib/coradoc/element/block.rb +1 -1
  25. data/lib/coradoc/element/document_attributes.rb +8 -2
  26. data/lib/coradoc/element/image/block_image.rb +3 -2
  27. data/lib/coradoc/element/image/core.rb +5 -4
  28. data/lib/coradoc/element/inline/attribute_reference.rb +19 -0
  29. data/lib/coradoc/element/inline/cross_reference.rb +4 -3
  30. data/lib/coradoc/element/inline/footnote.rb +24 -0
  31. data/lib/coradoc/element/inline/small.rb +19 -0
  32. data/lib/coradoc/element/inline/span.rb +37 -0
  33. data/lib/coradoc/element/inline/underline.rb +19 -0
  34. data/lib/coradoc/element/inline.rb +5 -1
  35. data/lib/coradoc/element/list/core.rb +2 -2
  36. data/lib/coradoc/element/list/ordered.rb +1 -0
  37. data/lib/coradoc/element/list/unordered.rb +1 -0
  38. data/lib/coradoc/element/list_item.rb +19 -20
  39. data/lib/coradoc/element/table.rb +4 -2
  40. data/lib/coradoc/element/term.rb +1 -0
  41. data/lib/coradoc/element/text_element.rb +4 -1
  42. data/lib/coradoc/element/title.rb +1 -1
  43. data/lib/coradoc/element/video.rb +2 -2
  44. data/lib/coradoc/input/adoc.rb +20 -18
  45. data/lib/coradoc/input/docx.rb +25 -23
  46. data/lib/coradoc/input/html/README.adoc +1 -1
  47. data/lib/coradoc/input/html/cleaner.rb +121 -117
  48. data/lib/coradoc/input/html/config.rb +58 -56
  49. data/lib/coradoc/input/html/converters/a.rb +44 -39
  50. data/lib/coradoc/input/html/converters/aside.rb +12 -8
  51. data/lib/coradoc/input/html/converters/audio.rb +24 -20
  52. data/lib/coradoc/input/html/converters/base.rb +103 -99
  53. data/lib/coradoc/input/html/converters/blockquote.rb +18 -14
  54. data/lib/coradoc/input/html/converters/br.rb +11 -7
  55. data/lib/coradoc/input/html/converters/bypass.rb +77 -73
  56. data/lib/coradoc/input/html/converters/code.rb +18 -14
  57. data/lib/coradoc/input/html/converters/div.rb +15 -11
  58. data/lib/coradoc/input/html/converters/dl.rb +51 -44
  59. data/lib/coradoc/input/html/converters/drop.rb +21 -17
  60. data/lib/coradoc/input/html/converters/em.rb +16 -12
  61. data/lib/coradoc/input/html/converters/figure.rb +19 -15
  62. data/lib/coradoc/input/html/converters/h.rb +32 -30
  63. data/lib/coradoc/input/html/converters/head.rb +17 -13
  64. data/lib/coradoc/input/html/converters/hr.rb +11 -7
  65. data/lib/coradoc/input/html/converters/ignore.rb +15 -11
  66. data/lib/coradoc/input/html/converters/img.rb +98 -93
  67. data/lib/coradoc/input/html/converters/li.rb +13 -9
  68. data/lib/coradoc/input/html/converters/mark.rb +14 -10
  69. data/lib/coradoc/input/html/converters/markup.rb +22 -18
  70. data/lib/coradoc/input/html/converters/math.rb +26 -19
  71. data/lib/coradoc/input/html/converters/ol.rb +55 -50
  72. data/lib/coradoc/input/html/converters/p.rb +16 -12
  73. data/lib/coradoc/input/html/converters/pass_through.rb +12 -8
  74. data/lib/coradoc/input/html/converters/pre.rb +49 -45
  75. data/lib/coradoc/input/html/converters/q.rb +12 -8
  76. data/lib/coradoc/input/html/converters/strong.rb +15 -11
  77. data/lib/coradoc/input/html/converters/sub.rb +15 -11
  78. data/lib/coradoc/input/html/converters/sup.rb +15 -11
  79. data/lib/coradoc/input/html/converters/table.rb +21 -13
  80. data/lib/coradoc/input/html/converters/td.rb +64 -60
  81. data/lib/coradoc/input/html/converters/text.rb +24 -20
  82. data/lib/coradoc/input/html/converters/th.rb +13 -9
  83. data/lib/coradoc/input/html/converters/tr.rb +17 -13
  84. data/lib/coradoc/input/html/converters/video.rb +24 -20
  85. data/lib/coradoc/input/html/converters.rb +45 -43
  86. data/lib/coradoc/input/html/errors.rb +8 -6
  87. data/lib/coradoc/input/html/html_converter.rb +93 -90
  88. data/lib/coradoc/input/html/plugin.rb +104 -104
  89. data/lib/coradoc/input/html/plugins/plateau.rb +197 -190
  90. data/lib/coradoc/input/html/postprocessor.rb +188 -182
  91. data/lib/coradoc/input/html.rb +34 -32
  92. data/lib/coradoc/oscal.rb +18 -5
  93. data/lib/coradoc/output/adoc.rb +13 -11
  94. data/lib/coradoc/output/coradoc_tree_debug.rb +15 -13
  95. data/lib/coradoc/parser/asciidoc/admonition.rb +6 -6
  96. data/lib/coradoc/parser/asciidoc/attribute_list.rb +43 -27
  97. data/lib/coradoc/parser/asciidoc/base.rb +3 -6
  98. data/lib/coradoc/parser/asciidoc/bibliography.rb +5 -6
  99. data/lib/coradoc/parser/asciidoc/block.rb +30 -31
  100. data/lib/coradoc/parser/asciidoc/citation.rb +11 -29
  101. data/lib/coradoc/parser/asciidoc/content.rb +23 -33
  102. data/lib/coradoc/parser/asciidoc/document_attributes.rb +2 -3
  103. data/lib/coradoc/parser/asciidoc/header.rb +1 -2
  104. data/lib/coradoc/parser/asciidoc/inline.rb +165 -42
  105. data/lib/coradoc/parser/asciidoc/list.rb +27 -27
  106. data/lib/coradoc/parser/asciidoc/paragraph.rb +28 -19
  107. data/lib/coradoc/parser/asciidoc/section.rb +11 -17
  108. data/lib/coradoc/parser/asciidoc/table.rb +5 -5
  109. data/lib/coradoc/parser/asciidoc/term.rb +24 -8
  110. data/lib/coradoc/parser/asciidoc/text.rb +18 -21
  111. data/lib/coradoc/parser/base.rb +0 -3
  112. data/lib/coradoc/reverse_adoc.rb +3 -3
  113. data/lib/coradoc/transformer.rb +167 -137
  114. data/lib/coradoc/version.rb +1 -1
  115. data/lib/reverse_adoc.rb +1 -1
  116. data/utils/inspect_asciidoc.rb +29 -0
  117. data/utils/parser_analyzer.rb +14 -14
  118. data/utils/round_trip.rb +31 -15
  119. metadata +34 -137
  120. data/.hound.yml +0 -5
  121. data/lib/coradoc/element/inline/citation.rb +0 -24
  122. data/todo.md +0 -10
@@ -1,60 +1,65 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Ol < Base
4
- # FIXIT
5
- def to_coradoc(node, state = {})
6
- # convert(node, state)
7
- id = node["id"]
8
- ol_count = state.fetch(:ol_count, 0) + 1
9
- attrs = ol_attrs(node)
10
- items = treat_children_coradoc(node, state.merge(ol_count: ol_count))
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Ol < Base
6
+ # FIXIT
7
+ def to_coradoc(node, state = {})
8
+ # convert(node, state)
9
+ id = node["id"]
10
+ ol_count = state.fetch(:ol_count, 0) + 1
11
+ attrs = ol_attrs(node)
12
+ items = treat_children_coradoc(node,
13
+ state.merge(ol_count: ol_count))
11
14
 
12
- options = {}.tap do |hash|
13
- hash[:id] = id
14
- hash[:ol_count] = ol_count
15
- hash[:attrs] = attrs
16
- end
15
+ options = {}.tap do |hash|
16
+ hash[:id] = id
17
+ hash[:ol_count] = ol_count
18
+ hash[:attrs] = attrs
19
+ end
17
20
 
18
- case get_list_type(node, state)
19
- when :ordered
20
- Coradoc::Element::List::Ordered.new(items, options)
21
- when :unordered
22
- Coradoc::Element::List::Unordered.new(items, options)
23
- end
24
- end
21
+ case get_list_type(node, state)
22
+ when :ordered
23
+ Coradoc::Element::List::Ordered.new(items, options)
24
+ when :unordered
25
+ Coradoc::Element::List::Unordered.new(items, options)
26
+ end
27
+ end
25
28
 
26
- def get_list_type(node, _state)
27
- case node.name
28
- when "ol"
29
- :ordered
30
- when "ul"
31
- :unordered
32
- end
33
- end
29
+ def get_list_type(node, _state)
30
+ case node.name
31
+ when "ol"
32
+ :ordered
33
+ when "ul"
34
+ :unordered
35
+ end
36
+ end
37
+
38
+ def number_style(node)
39
+ case node["style"]
40
+ when "1" then "arabic"
41
+ when "A" then "upperalpha"
42
+ when "a" then "loweralpha"
43
+ when "I" then "upperroman"
44
+ when "i" then "lowerroman"
45
+ end
46
+ end
34
47
 
35
- def number_style(node)
36
- case node["style"]
37
- when "1" then "arabic"
38
- when "A" then "upperalpha"
39
- when "a" then "loweralpha"
40
- when "I" then "upperroman"
41
- when "i" then "lowerroman"
48
+ def ol_attrs(node)
49
+ attrs = Coradoc::Element::AttributeList.new
50
+ style = number_style(node)
51
+ attrs.add_positional(style) if style
52
+ attrs.add_positional("%reversed") if node["reversed"]
53
+ attrs.add_named("start", node["start"]) if node["start"]
54
+ attrs.add_named("type", node["type"]) if node["type"]
55
+ attrs
56
+ end
42
57
  end
43
- end
44
58
 
45
- def ol_attrs(node)
46
- attrs = Coradoc::Element::AttributeList.new
47
- style = number_style(node)
48
- attrs.add_positional(style) if style
49
- attrs.add_positional("%reversed") if node["reversed"]
50
- attrs.add_named("start", node["start"]) if node["start"]
51
- attrs.add_named("type", node["type"]) if node["type"]
52
- attrs
59
+ register :ol, Ol.new
60
+ register :ul, Ol.new
61
+ register :dir, Ol.new
53
62
  end
54
63
  end
55
-
56
- register :ol, Ol.new
57
- register :ul, Ol.new
58
- register :dir, Ol.new
59
64
  end
60
65
  end
@@ -1,19 +1,23 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class P < Base
4
- def to_coradoc(node, state = {})
5
- id = node["id"]
6
- content = treat_children_coradoc(node, state)
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class P < Base
6
+ def to_coradoc(node, state = {})
7
+ id = node["id"]
8
+ content = treat_children_coradoc(node, state)
7
9
 
8
- options = {}.tap do |hash|
9
- hash[:id] = id if id
10
- hash[:tdsinglepara] = true if state[:tdsinglepara]
10
+ options = {}.tap do |hash|
11
+ hash[:id] = id if id
12
+ hash[:tdsinglepara] = true if state[:tdsinglepara]
13
+ end
14
+
15
+ Coradoc::Element::Paragraph.new(content, options)
16
+ end
11
17
  end
12
18
 
13
- Coradoc::Element::Paragraph.new(content, options)
19
+ register :p, P.new
14
20
  end
15
21
  end
16
-
17
- register :p, P.new
18
22
  end
19
23
  end
@@ -1,12 +1,16 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class PassThrough < Base
4
- def to_coradoc(node, _state = {})
5
- node.to_s
6
- end
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class PassThrough < Base
6
+ def to_coradoc(node, _state = {})
7
+ node.to_s
8
+ end
7
9
 
8
- def convert(node, state = {})
9
- to_coradoc(node, state)
10
+ def convert(node, state = {})
11
+ to_coradoc(node, state)
12
+ end
13
+ end
10
14
  end
11
15
  end
12
16
  end
@@ -1,51 +1,55 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Pre < Base
4
- def to_coradoc(node, state = {})
5
- id = node["id"]
6
- lang = language(node)
7
- content = treat_children(node, state)
8
-
9
- unless lang
10
- return Coradoc::Element::Block::Literal.new(
11
- nil,
12
- lines: content,
13
- id: id,
14
- )
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Pre < Base
6
+ def to_coradoc(node, state = {})
7
+ id = node["id"]
8
+ lang = language(node)
9
+ content = treat_children(node, state)
10
+
11
+ unless lang
12
+ return Coradoc::Element::Block::Literal.new(
13
+ nil,
14
+ lines: content,
15
+ id: id,
16
+ )
17
+ end
18
+
19
+ Coradoc::Element::Block::SourceCode.new(
20
+ nil,
21
+ lines: content,
22
+ lang: lang,
23
+ id: id,
24
+ )
25
+ end
26
+
27
+ private
28
+
29
+ def treat(node, _state)
30
+ return "\n" if node.name == "br"
31
+
32
+ prefix = postfix = "\n\n" if node.name == "p"
33
+
34
+ "#{prefix}#{node.text}#{postfix}"
35
+ end
36
+
37
+ def language(node)
38
+ lang = language_from_highlight_class(node)
39
+ lang || language_from_confluence_class(node)
40
+ end
41
+
42
+ def language_from_highlight_class(node)
43
+ node.parent["class"].to_s[/highlight-([a-zA-Z0-9]+)/, 1]
44
+ end
45
+
46
+ def language_from_confluence_class(node)
47
+ node["class"].to_s[/brush:\s?(:?.*);/, 1]
48
+ end
15
49
  end
16
50
 
17
- Coradoc::Element::Block::SourceCode.new(
18
- nil,
19
- lines: content,
20
- lang: lang,
21
- id: id,
22
- )
23
- end
24
-
25
- private
26
-
27
- def treat(node, _state)
28
- return "\n" if node.name == "br"
29
-
30
- prefix = postfix = "\n\n" if node.name == "p"
31
-
32
- "#{prefix}#{node.text}#{postfix}"
33
- end
34
-
35
- def language(node)
36
- lang = language_from_highlight_class(node)
37
- lang || language_from_confluence_class(node)
38
- end
39
-
40
- def language_from_highlight_class(node)
41
- node.parent["class"].to_s[/highlight-([a-zA-Z0-9]+)/, 1]
42
- end
43
-
44
- def language_from_confluence_class(node)
45
- node["class"].to_s[/brush:\s?(:?.*);/, 1]
51
+ register :pre, Pre.new
46
52
  end
47
53
  end
48
-
49
- register :pre, Pre.new
50
54
  end
51
55
  end
@@ -1,12 +1,16 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Q < Base
4
- def to_coradoc(node, state = {})
5
- content = treat_children(node, state)
6
- Coradoc::Element::Inline::Quotation.new(content)
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Q < Base
6
+ def to_coradoc(node, state = {})
7
+ content = treat_children(node, state)
8
+ Coradoc::Element::Inline::Quotation.new(content)
9
+ end
10
+ end
11
+
12
+ register :q, Q.new
7
13
  end
8
14
  end
9
-
10
- register :q, Q.new
11
15
  end
12
16
  end
@@ -1,16 +1,20 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Strong < Markup
4
- def coradoc_class
5
- Coradoc::Element::Inline::Bold
6
- end
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Strong < Markup
6
+ def coradoc_class
7
+ Coradoc::Element::Inline::Bold
8
+ end
9
+
10
+ def markup_ancestor_tag_names
11
+ %w[strong b]
12
+ end
13
+ end
7
14
 
8
- def markup_ancestor_tag_names
9
- %w[strong b]
15
+ register :strong, Strong.new
16
+ register :b, Strong.new
10
17
  end
11
18
  end
12
-
13
- register :strong, Strong.new
14
- register :b, Strong.new
15
19
  end
16
20
  end
@@ -1,18 +1,22 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Sub < Base
4
- def to_coradoc(node, state = {})
5
- leading_whitespace, trailing_whitespace = extract_leading_trailing_whitespace(node)
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Sub < Base
6
+ def to_coradoc(node, state = {})
7
+ leading_whitespace, trailing_whitespace = extract_leading_trailing_whitespace(node)
6
8
 
7
- content = treat_children_coradoc(node, state)
9
+ content = treat_children_coradoc(node, state)
8
10
 
9
- return content if Coradoc::Generator.gen_adoc(content).strip.empty?
11
+ return content if Coradoc::Generator.gen_adoc(content).strip.empty?
10
12
 
11
- e = Coradoc::Element::Inline::Subscript.new(content)
12
- [leading_whitespace, e, trailing_whitespace]
13
+ e = Coradoc::Element::Inline::Subscript.new(content)
14
+ [leading_whitespace, e, trailing_whitespace]
15
+ end
16
+ end
17
+
18
+ register :sub, Sub.new
13
19
  end
14
20
  end
15
-
16
- register :sub, Sub.new
17
21
  end
18
22
  end
@@ -1,18 +1,22 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Sup < Base
4
- def to_coradoc(node, state = {})
5
- leading_whitespace, trailing_whitespace = extract_leading_trailing_whitespace(node)
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Sup < Base
6
+ def to_coradoc(node, state = {})
7
+ leading_whitespace, trailing_whitespace = extract_leading_trailing_whitespace(node)
6
8
 
7
- content = treat_children_coradoc(node, state)
9
+ content = treat_children_coradoc(node, state)
8
10
 
9
- return content if Coradoc::Generator.gen_adoc(content).strip.empty?
11
+ return content if Coradoc::Generator.gen_adoc(content).strip.empty?
10
12
 
11
- e = Coradoc::Element::Inline::Superscript.new(content)
12
- [leading_whitespace, e, trailing_whitespace]
13
+ e = Coradoc::Element::Inline::Superscript.new(content)
14
+ [leading_whitespace, e, trailing_whitespace]
15
+ end
16
+ end
17
+
18
+ register :sup, Sup.new
13
19
  end
14
20
  end
15
-
16
- register :sup, Sup.new
17
21
  end
18
22
  end
@@ -1,4 +1,5 @@
1
- module Coradoc::Input::HTML
1
+ module Coradoc::Input
2
+ module Html
2
3
  module Converters
3
4
  class Table < Base
4
5
  def to_coradoc(node, state = {})
@@ -61,7 +62,8 @@ module Coradoc::Input::HTML
61
62
 
62
63
  # Header first rows can't span multiple riws - drop header if they do.
63
64
  header = node.at_xpath(".//tr")
64
- unless header.xpath("./td | ./th").all? { |i| [nil, "1", ""].include? i["rowspan"] }
65
+ unless header.xpath("./td | ./th").all? { |i|
66
+ [nil, "1", ""].include? i["rowspan"] }
65
67
  attrs.add_named("options", ["noheader"])
66
68
  end
67
69
  end
@@ -102,10 +104,10 @@ module Coradoc::Input::HTML
102
104
  return ensure_row_column_integrity_and_get_column_sizes(node)
103
105
  end
104
106
 
105
- fits_in_cell_matrix = proc do |y,x,rowspan,colspan|
107
+ fits_in_cell_matrix = proc do |y, x, rowspan, colspan|
106
108
  rowspan.times.all? do |yy|
107
109
  colspan.times.all? do |xx|
108
- !cell_matrix.dig(y+yy, x+xx)
110
+ !cell_matrix.dig(y + yy, x + xx)
109
111
  end
110
112
  end
111
113
  end
@@ -124,7 +126,8 @@ module Coradoc::Input::HTML
124
126
  colspan = cell["colspan"]&.to_i || 1
125
127
  rowspan = cell["rowspan"]&.to_i || 1
126
128
 
127
- column_id += 1 until fits_in_cell_matrix.(i,column_id,rowspan,colspan)
129
+ column_id += 1 until fits_in_cell_matrix.(i, column_id, rowspan,
130
+ colspan)
128
131
 
129
132
  rowspan.times do |j|
130
133
  # Let's increase the table for particularly bad documents
@@ -134,7 +137,7 @@ module Coradoc::Input::HTML
134
137
  cell_references[i + j] ||= []
135
138
  cell_matrix[i + j] ||= []
136
139
  colspan.times do |k|
137
- cell_references[i + j] << [cell, k > 0]
140
+ cell_references[i + j] << [cell, k.positive?]
138
141
  cell_matrix[i + j][column_id] = cell
139
142
  column_id += 1
140
143
  end
@@ -225,7 +228,7 @@ module Coradoc::Input::HTML
225
228
  recompute.() if needs_recompute
226
229
 
227
230
  # But otherwise... we've got a really nasty table.
228
- warn <<~WARNING.gsub("\n", " ")
231
+ warn <<~WARNING.tr("\n", " ")
229
232
  **** Couldn't construct a valid image of a table on line
230
233
  #{node.line}. We need that to reliably compute column
231
234
  widths of that table. Please report a bug to metanorma/coradoc
@@ -236,7 +239,7 @@ module Coradoc::Input::HTML
236
239
  # Compute column sizes
237
240
  column_sizes = []
238
241
  cell_matrix.each do |row|
239
- row.each_with_index do |(cell,_), i|
242
+ row.each_with_index do |(cell, _), i|
240
243
  next unless !cell || [nil, "", "1"].include?(cell["colspan"])
241
244
 
242
245
  column_sizes[i] ||= []
@@ -244,7 +247,7 @@ module Coradoc::Input::HTML
244
247
  end
245
248
  end
246
249
 
247
- document_width = Coradoc::Input::HTML.config.doc_width.to_r
250
+ document_width = Coradoc::Input::Html.config.doc_width.to_r
248
251
 
249
252
  column_sizes += [nil] * (cpr.first - column_sizes.length)
250
253
 
@@ -271,8 +274,12 @@ module Coradoc::Input::HTML
271
274
  # The table seems bigger than the document... let's scale all
272
275
  # values.
273
276
  while sizes.map { |i|
274
- i.zero? ? document_width / 3 / sizes.length : i
275
- }.sum > document_width
277
+ if i.zero?
278
+ document_width / 3 / sizes.length
279
+ else
280
+ i
281
+ end
282
+ }.sum > document_width
276
283
 
277
284
  sizes = sizes.map { |i| i * 4 / 5 }
278
285
  end
@@ -290,11 +297,11 @@ module Coradoc::Input::HTML
290
297
  end
291
298
 
292
299
  # Scale to integers
293
- lcm = sizes.map(&:denominator).inject(1) { |i,j| i.lcm(j) }
300
+ lcm = sizes.map(&:denominator).inject(1) { |i, j| i.lcm(j) }
294
301
  sizes = sizes.map { |i| i * lcm }.map(&:to_i)
295
302
 
296
303
  # Scale down by gcd
297
- gcd = sizes.inject(sizes.first) { |i,j| i.gcd(j) }
304
+ gcd = sizes.inject(sizes.first) { |i, j| i.gcd(j) }
298
305
  sizes = sizes.map { |i| i / gcd }
299
306
 
300
307
  # Try to generate a shorter definition
@@ -308,4 +315,5 @@ module Coradoc::Input::HTML
308
315
 
309
316
  register :table, Table.new
310
317
  end
318
+ end
311
319
  end
@@ -1,77 +1,81 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Td < Base
4
- def to_coradoc(node, state = {})
5
- # convert(node, state)
6
- id = node["id"]
7
- colrowattr = colrow(node["colspan"], node["rowspan"])
8
- alignattr = alignstyle(node)
9
- style = cellstyle(node)
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Td < Base
6
+ def to_coradoc(node, state = {})
7
+ # convert(node, state)
8
+ id = node["id"]
9
+ colrowattr = colrow(node["colspan"], node["rowspan"])
10
+ alignattr = alignstyle(node)
11
+ style = cellstyle(node)
10
12
 
11
- singlepara = node.elements.size == 1 && node.elements.first.name == "p"
12
- state[:tdsinglepara] = singlepara if singlepara
13
+ singlepara = node.elements.size == 1 && node.elements.first.name == "p"
14
+ state[:tdsinglepara] = singlepara if singlepara
13
15
 
14
- adoccell = node.at(".//ul | .//ol | .//pre | .//blockquote | .//br | .//hr | .//img[@src]") ||
15
- node.at(".//p") && !singlepara
16
+ adoccell = node.at(".//ul | .//ol | .//pre | .//blockquote | .//br | .//hr | .//img[@src]") ||
17
+ node.at(".//p") && !singlepara
16
18
 
17
- style = "a" if adoccell
18
- content = treat_children_coradoc(node, state)
19
- options = {}.tap do |hash|
20
- hash[:id] = id
21
- hash[:colrowattr] = colrowattr
22
- hash[:alignattr] = alignattr
23
- hash[:style] = style
24
- hash[:content] = content
25
- end
26
-
27
- Coradoc::Element::Table::Cell.new(options)
28
- end
19
+ style = "a" if adoccell
20
+ content = treat_children_coradoc(node, state)
21
+ options = {}.tap do |hash|
22
+ hash[:id] = id
23
+ hash[:colrowattr] = colrowattr
24
+ hash[:alignattr] = alignattr
25
+ hash[:style] = style
26
+ hash[:content] = content
27
+ end
29
28
 
30
- def cellstyle(_node)
31
- ""
32
- end
29
+ Coradoc::Element::Table::Cell.new(options)
30
+ end
33
31
 
34
- def colrow(colspan, rowspan)
35
- if colspan && rowspan && colspan != "1" && rowspan != "1"
36
- "#{colspan}.#{rowspan}+"
37
- elsif colspan && colspan != "1"
38
- "#{colspan}+"
39
- elsif rowspan && rowspan != "1"
40
- ".#{rowspan}+"
41
- else
42
- ""
43
- end
44
- end
32
+ def cellstyle(_node)
33
+ ""
34
+ end
45
35
 
46
- def alignstyle(node)
47
- align = node["align"]
48
- valign = node["valign"]
49
- a = case align
50
- when "left" then "<"
51
- when "center" then "^"
52
- when "right" then ">"
36
+ def colrow(colspan, rowspan)
37
+ if colspan && rowspan && colspan != "1" && rowspan != "1"
38
+ "#{colspan}.#{rowspan}+"
39
+ elsif colspan && colspan != "1"
40
+ "#{colspan}+"
41
+ elsif rowspan && rowspan != "1"
42
+ ".#{rowspan}+"
53
43
  else
54
44
  ""
55
45
  end
56
- v = case valign
57
- when "top" then "<"
58
- when "middle" then "^"
59
- when "bottom" then ">"
46
+ end
47
+
48
+ def alignstyle(node)
49
+ align = node["align"]
50
+ valign = node["valign"]
51
+ a = case align
52
+ when "left" then "<"
53
+ when "center" then "^"
54
+ when "right" then ">"
55
+ else
56
+ ""
57
+ end
58
+ v = case valign
59
+ when "top" then "<"
60
+ when "middle" then "^"
61
+ when "bottom" then ">"
62
+ else
63
+ ""
64
+ end
65
+ if align && valign
66
+ "#{a}.#{v}"
67
+ elsif align
68
+ a
69
+ elsif valign
70
+ ".#{v}"
60
71
  else
61
72
  ""
62
73
  end
63
- if align && valign
64
- "#{a}.#{v}"
65
- elsif align
66
- a
67
- elsif valign
68
- ".#{v}"
69
- else
70
- ""
74
+ end
71
75
  end
76
+
77
+ register :td, Td.new
72
78
  end
73
79
  end
74
-
75
- register :td, Td.new
76
80
  end
77
81
  end