coradoc 2.0.2 → 2.0.4

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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +65 -8
  3. data/coradoc-adoc/lib/coradoc/asciidoc/model/attached.rb +3 -0
  4. data/coradoc-adoc/lib/coradoc/asciidoc/model/base.rb +10 -0
  5. data/coradoc-adoc/lib/coradoc/asciidoc/model/comment_block.rb +4 -0
  6. data/coradoc-adoc/lib/coradoc/asciidoc/model/image/block_image.rb +4 -0
  7. data/coradoc-adoc/lib/coradoc/asciidoc/model/image/inline_image.rb +4 -0
  8. data/coradoc-adoc/lib/coradoc/asciidoc/model/inline/base.rb +3 -0
  9. data/coradoc-adoc/lib/coradoc/asciidoc/model/inline/hard_line_break.rb +3 -0
  10. data/coradoc-adoc/lib/coradoc/asciidoc/model/list/core.rb +4 -0
  11. data/coradoc-adoc/lib/coradoc/asciidoc/model/list/item.rb +0 -17
  12. data/coradoc-adoc/lib/coradoc/asciidoc/model/section.rb +4 -0
  13. data/coradoc-adoc/lib/coradoc/asciidoc/model/table.rb +4 -0
  14. data/coradoc-adoc/lib/coradoc/asciidoc/model/text_element.rb +4 -0
  15. data/coradoc-adoc/lib/coradoc/asciidoc/serializer/serializers/base.rb +0 -11
  16. data/coradoc-adoc/lib/coradoc/asciidoc/serializer/serializers/list/item.rb +4 -10
  17. data/coradoc-adoc/lib/coradoc/asciidoc/serializer/spacing_strategy.rb +4 -18
  18. data/coradoc-adoc/spec/coradoc/asciidoc/model/base_spec.rb +16 -2
  19. data/coradoc-adoc/spec/coradoc/asciidoc/model/element_classification_spec.rb +146 -0
  20. data/coradoc-docx/lib/coradoc/docx/transform/context.rb +1 -1
  21. data/coradoc-docx/lib/coradoc/docx/transform/from_core_model.rb +13 -6
  22. data/coradoc-docx/lib/coradoc/docx/transform/numbering_resolver.rb +9 -7
  23. data/coradoc-docx/lib/coradoc/docx/transform/ordered_content.rb +2 -2
  24. data/coradoc-docx/lib/coradoc/docx/transform/rules/image_rule.rb +4 -1
  25. data/coradoc-docx/lib/coradoc/docx/transform/rules/math_rule.rb +2 -1
  26. data/coradoc-docx/lib/coradoc/docx/transform/rules/run_rule.rb +17 -30
  27. data/coradoc-docx/lib/coradoc/docx/transform/rules/simple_field_rule.rb +3 -5
  28. data/coradoc-docx/lib/coradoc/docx/transform/rules/table_rule.rb +3 -4
  29. data/coradoc-docx/lib/coradoc/docx/transform/style_resolver.rb +19 -24
  30. data/coradoc-docx/lib/coradoc/docx/transform/to_core_model.rb +18 -11
  31. data/coradoc-html/lib/coradoc/html/base.rb +3 -7
  32. data/coradoc-html/lib/coradoc/html/converter_base.rb +5 -15
  33. data/coradoc-html/lib/coradoc/html/converters/base.rb +18 -27
  34. data/coradoc-html/lib/coradoc/html/converters/comment_line.rb +2 -2
  35. data/coradoc-html/lib/coradoc/html/converters/link.rb +1 -1
  36. data/coradoc-html/lib/coradoc/html/converters/list_item.rb +3 -3
  37. data/coradoc-html/lib/coradoc/html/converters/ordered.rb +1 -1
  38. data/coradoc-html/lib/coradoc/html/converters/span.rb +2 -2
  39. data/coradoc-html/lib/coradoc/html/converters/table.rb +3 -3
  40. data/coradoc-html/lib/coradoc/html/converters/table_cell.rb +14 -28
  41. data/coradoc-html/lib/coradoc/html/converters/table_row.rb +2 -2
  42. data/coradoc-html/lib/coradoc/html/converters/text_element.rb +1 -5
  43. data/coradoc-html/lib/coradoc/html/input/converters/a.rb +2 -2
  44. data/coradoc-html/lib/coradoc/html/input/converters/dl.rb +1 -1
  45. data/coradoc-html/lib/coradoc/html/input/converters/figure.rb +2 -2
  46. data/coradoc-html/lib/coradoc/html/input/converters/markup.rb +3 -3
  47. data/coradoc-html/lib/coradoc/html/input/converters/p.rb +1 -1
  48. data/coradoc-html/lib/coradoc/html/input/converters/td.rb +1 -1
  49. data/coradoc-html/lib/coradoc/html/input/converters.rb +1 -2
  50. data/coradoc-html/lib/coradoc/html/input/html_converter.rb +3 -3
  51. data/coradoc-html/lib/coradoc/html/input/plugin.rb +2 -2
  52. data/coradoc-html/lib/coradoc/html/renderer.rb +4 -6
  53. data/coradoc-html/lib/coradoc/html/theme/base.rb +2 -3
  54. data/coradoc-html/lib/coradoc/html/theme/classic_renderer.rb +9 -12
  55. data/coradoc-html/lib/coradoc/html/theme/modern/serializers/document_serializer.rb +3 -3
  56. data/coradoc-markdown/lib/coradoc/markdown/model/base.rb +6 -5
  57. data/coradoc-markdown/lib/coradoc/markdown/serializer.rb +2 -2
  58. data/coradoc-markdown/lib/coradoc/markdown/toc_generator.rb +4 -5
  59. data/coradoc-markdown/lib/coradoc/markdown/transformer.rb +5 -3
  60. data/lib/coradoc/version.rb +1 -1
  61. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2a167bf671c487f25b37d0df4019bee6bd324636fdf9a681b799764f4a14b2d
4
- data.tar.gz: 89345da1186b5ad1fc3ed0315b536a09e445015b1744094fd3ff187382023818
3
+ metadata.gz: 69f496efd91c2d85e4e057be629f8ee00492c40497661c0af940be65f148e092
4
+ data.tar.gz: a2668ca45e7d23bf613d966c36b4c5da70311be0dcdbc0fba4d988844f49b65f
5
5
  SHA512:
6
- metadata.gz: 5a7ead748469ceecbe303de9fd0e65b0081c4765cb8cda371f11cdd76173dcb60372f89ff2c5fc1d30b74fab0bff349fd0149b62ddd65df5b944a350dea14cc9
7
- data.tar.gz: 41c5de35c416b7bfcc74ba8043bc26771e4bc8a332f59211de6f0c7f6bae7019fa096458ab705bd7e54b0c248c352df70c04467679f156c315e02c00ef4fdf5d
6
+ metadata.gz: '04584b5faee36ac872400d4d17458221931de4f733aae75839dc40f282d4f863948c9105eb80fefb84f6945639c76c55ccf62fd93d8fd442268f36698950625d'
7
+ data.tar.gz: 00c91cfd40f731c1fffab6ae507d326140e5c7830a8d10bf6a5bb75857ba0b69a552fc4a27d8bd3abb95d4a16159a516df62232bc538fd79fe55a7023e95af0b
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2026-05-06 19:17:34 UTC using RuboCop version 1.75.8.
3
+ # on 2026-05-08 04:52:25 UTC using RuboCop version 1.75.8.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -15,6 +15,28 @@ Gemspec/RequiredRubyVersion:
15
15
  - 'coradoc-html/coradoc-html.gemspec'
16
16
  - 'coradoc.gemspec'
17
17
 
18
+ # Offense count: 1
19
+ # This cop supports safe autocorrection (--autocorrect).
20
+ # Configuration parameters: EnforcedStyle, IndentationWidth.
21
+ # SupportedStyles: with_first_argument, with_fixed_indentation
22
+ Layout/ArgumentAlignment:
23
+ Exclude:
24
+ - 'coradoc-adoc/lib/coradoc/asciidoc/serializer/serializers/document.rb'
25
+
26
+ # Offense count: 1
27
+ # This cop supports safe autocorrection (--autocorrect).
28
+ Layout/ClosingParenthesisIndentation:
29
+ Exclude:
30
+ - 'lib/coradoc/document_manipulator.rb'
31
+
32
+ # Offense count: 1
33
+ # This cop supports safe autocorrection (--autocorrect).
34
+ # Configuration parameters: EnforcedStyle, IndentationWidth.
35
+ # SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses
36
+ Layout/FirstArgumentIndentation:
37
+ Exclude:
38
+ - 'lib/coradoc/document_manipulator.rb'
39
+
18
40
  # Offense count: 6
19
41
  # This cop supports safe autocorrection (--autocorrect).
20
42
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
@@ -22,6 +44,21 @@ Gemspec/RequiredRubyVersion:
22
44
  Layout/LineLength:
23
45
  Max: 235
24
46
 
47
+ # Offense count: 1
48
+ # This cop supports safe autocorrection (--autocorrect).
49
+ # Configuration parameters: EnforcedStyle.
50
+ # SupportedStyles: symmetrical, new_line, same_line
51
+ Layout/MultilineMethodCallBraceLayout:
52
+ Exclude:
53
+ - 'lib/coradoc/document_manipulator.rb'
54
+
55
+ # Offense count: 1
56
+ # This cop supports safe autocorrection (--autocorrect).
57
+ # Configuration parameters: AllowInHeredoc.
58
+ Layout/TrailingWhitespace:
59
+ Exclude:
60
+ - 'coradoc-adoc/lib/coradoc/asciidoc/serializer/serializers/document.rb'
61
+
25
62
  # Offense count: 1
26
63
  Lint/BinaryOperatorWithIdenticalOperands:
27
64
  Exclude:
@@ -96,7 +133,7 @@ Lint/Void:
96
133
  Exclude:
97
134
  - 'coradoc-html/lib/coradoc/html.rb'
98
135
 
99
- # Offense count: 237
136
+ # Offense count: 236
100
137
  # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
101
138
  Metrics/AbcSize:
102
139
  Max: 178
@@ -117,12 +154,12 @@ Metrics/BlockNesting:
117
154
  Metrics/ClassLength:
118
155
  Max: 556
119
156
 
120
- # Offense count: 186
157
+ # Offense count: 179
121
158
  # Configuration parameters: AllowedMethods, AllowedPatterns.
122
159
  Metrics/CyclomaticComplexity:
123
160
  Max: 32
124
161
 
125
- # Offense count: 383
162
+ # Offense count: 384
126
163
  # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
127
164
  Metrics/MethodLength:
128
165
  Max: 246
@@ -138,7 +175,7 @@ Metrics/ParameterLists:
138
175
  Max: 7
139
176
  MaxOptionalParameters: 4
140
177
 
141
- # Offense count: 125
178
+ # Offense count: 122
142
179
  # Configuration parameters: AllowedMethods, AllowedPatterns.
143
180
  Metrics/PerceivedComplexity:
144
181
  Max: 27
@@ -201,6 +238,12 @@ Naming/VariableName:
201
238
  Exclude:
202
239
  - 'coradoc-markdown/lib/coradoc/markdown.rb'
203
240
 
241
+ # Offense count: 12
242
+ # This cop supports unsafe autocorrection (--autocorrect-all).
243
+ RSpec/BeEq:
244
+ Exclude:
245
+ - 'coradoc-adoc/spec/coradoc/asciidoc/model/element_classification_spec.rb'
246
+
204
247
  # Offense count: 1
205
248
  RSpec/BeforeAfterAll:
206
249
  Exclude:
@@ -209,11 +252,19 @@ RSpec/BeforeAfterAll:
209
252
  - '**/spec/support/**/*.rb'
210
253
  - 'spec/benchmark/performance_spec.rb'
211
254
 
212
- # Offense count: 19
255
+ # Offense count: 20
213
256
  # Configuration parameters: IgnoredMetadata.
214
257
  RSpec/DescribeClass:
215
258
  Enabled: false
216
259
 
260
+ # Offense count: 1
261
+ # This cop supports unsafe autocorrection (--autocorrect-all).
262
+ # Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants.
263
+ # SupportedStyles: described_class, explicit
264
+ RSpec/DescribedClass:
265
+ Exclude:
266
+ - 'coradoc-adoc/spec/coradoc/asciidoc/model/base_spec.rb'
267
+
217
268
  # Offense count: 485
218
269
  # Configuration parameters: CountAsOne.
219
270
  RSpec/ExampleLength:
@@ -265,7 +316,7 @@ RSpec/MessageSpies:
265
316
  RSpec/MultipleDescribes:
266
317
  Enabled: false
267
318
 
268
- # Offense count: 613
319
+ # Offense count: 619
269
320
  RSpec/MultipleExpectations:
270
321
  Max: 12
271
322
 
@@ -344,7 +395,7 @@ Style/ClassVars:
344
395
  - 'coradoc-adoc/lib/coradoc/asciidoc/serializer/element_registry.rb'
345
396
  - 'coradoc-html/lib/coradoc/html/input/converters.rb'
346
397
 
347
- # Offense count: 291
398
+ # Offense count: 292
348
399
  # Configuration parameters: AllowedConstants.
349
400
  Style/Documentation:
350
401
  Enabled: false
@@ -380,6 +431,12 @@ Style/HashLikeCase:
380
431
  - 'coradoc-html/lib/coradoc/html/input/converters/table.rb'
381
432
  - 'coradoc-html/lib/coradoc/html/input/converters/td.rb'
382
433
 
434
+ # Offense count: 1
435
+ # This cop supports safe autocorrection (--autocorrect).
436
+ Style/MultilineIfModifier:
437
+ Exclude:
438
+ - 'coradoc-adoc/lib/coradoc/asciidoc/serializer/serializers/document.rb'
439
+
383
440
  # Offense count: 1
384
441
  # This cop supports unsafe autocorrection (--autocorrect-all).
385
442
  # Configuration parameters: EnforcedStyle.
@@ -17,6 +17,9 @@ module Coradoc
17
17
  # @see Coradoc::AsciiDoc::Model::Block::Core
18
18
  #
19
19
  class Attached < Base
20
+ def block_level?
21
+ true
22
+ end
20
23
  end
21
24
  end
22
25
  end
@@ -35,6 +35,16 @@ module Coradoc
35
35
 
36
36
  attribute :id, :string
37
37
 
38
+ # Element classification for spacing and serialization decisions.
39
+ # Subclasses override these to declare their level.
40
+ def block_level?
41
+ false
42
+ end
43
+
44
+ def inline?
45
+ false
46
+ end
47
+
38
48
  # Generate a warning message whenever this method is called.
39
49
  def simplify_block_content(content)
40
50
  warn '[DEPRECATION] #simplify_block_content is called inside a Lutaml Model. This is still a WIP.'
@@ -21,6 +21,10 @@ module Coradoc
21
21
  # @see Coradoc::AsciiDoc::Model::CommentLine Single-line comments
22
22
  #
23
23
  class CommentBlock < Base
24
+ def block_level?
25
+ true
26
+ end
27
+
24
28
  attribute :text, :string
25
29
  attribute :line_break, :string, default: -> { "\n" }
26
30
  end
@@ -5,6 +5,10 @@ module Coradoc
5
5
  module Model
6
6
  module Image
7
7
  class BlockImage < Coradoc::AsciiDoc::Model::Image::Core
8
+ def block_level?
9
+ true
10
+ end
11
+
8
12
  # Autoload nested AttributeList class
9
13
  autoload :AttributeList, 'coradoc/asciidoc/model/image/block_image/attribute_list'
10
14
 
@@ -5,6 +5,10 @@ module Coradoc
5
5
  module Model
6
6
  module Image
7
7
  class InlineImage < Coradoc::AsciiDoc::Model::Image::Core
8
+ def inline?
9
+ true
10
+ end
11
+
8
12
  attribute :colons, :string, default: -> { ':' }
9
13
  end
10
14
  end
@@ -5,6 +5,9 @@ module Coradoc
5
5
  module Model
6
6
  module Inline
7
7
  class Base < Coradoc::AsciiDoc::Model::Base
8
+ def inline?
9
+ true
10
+ end
8
11
  end
9
12
  end
10
13
  end
@@ -14,6 +14,9 @@ module Coradoc
14
14
  # break.to_adoc # => " +"
15
15
  #
16
16
  class HardLineBreak < Base
17
+ def inline?
18
+ :hardbreak
19
+ end
17
20
  end
18
21
  end
19
22
  end
@@ -29,6 +29,10 @@ module Coradoc
29
29
  class Core < Nestable
30
30
  include Coradoc::AsciiDoc::Model::Anchorable
31
31
 
32
+ def block_level?
33
+ true
34
+ end
35
+
32
36
  attribute :id, :string
33
37
  attribute :prefix, :string
34
38
  # attribute :anchor, Inline::Anchor, default: -> {
@@ -65,23 +65,6 @@ module Coradoc
65
65
  initialize_empty: true
66
66
 
67
67
  attribute :nested, Coradoc::AsciiDoc::Model::List::Nestable
68
-
69
- HARDBREAK_MARKERS = %i[hardbreak init].freeze
70
- STRIP_UNICODE_BEGIN_MARKERS = (HARDBREAK_MARKERS.dup + [false]).freeze
71
- STRIP_UNICODE_END_MARKERS = [:hardbreak, :end, false].freeze
72
-
73
- def inline?(elem)
74
- case elem
75
- when Inline::HardLineBreak
76
- :hardbreak
77
- when ->(i) { i.class.name.to_s.include? '::Inline::' }
78
- true
79
- when String, TextElement, Image::InlineImage
80
- true
81
- else
82
- false
83
- end
84
- end
85
68
  end
86
69
  end
87
70
  end
@@ -39,6 +39,10 @@ module Coradoc
39
39
  class Section < Base
40
40
  include Coradoc::AsciiDoc::Model::Anchorable
41
41
 
42
+ def block_level?
43
+ true
44
+ end
45
+
42
46
  attribute :id, :string
43
47
  attribute :content, :string
44
48
  attribute :title, Coradoc::AsciiDoc::Model::Title
@@ -26,6 +26,10 @@ module Coradoc
26
26
  class Table < Base
27
27
  include Coradoc::AsciiDoc::Model::Anchorable
28
28
 
29
+ def block_level?
30
+ true
31
+ end
32
+
29
33
  attribute :id, :string
30
34
  attribute :title, :string
31
35
  attribute :rows, Coradoc::AsciiDoc::Model::TableRow, collection: true
@@ -4,6 +4,10 @@ module Coradoc
4
4
  module AsciiDoc
5
5
  module Model
6
6
  class TextElement < Base
7
+ def inline?
8
+ true
9
+ end
10
+
7
11
  attribute :id, :string
8
12
  attribute :content,
9
13
  Lutaml::Model::Serializable,
@@ -120,17 +120,6 @@ module Coradoc
120
120
  end
121
121
  end
122
122
 
123
- # Helper to check if element is block-level
124
- # @param element [Object] Element to check
125
- # @return [Boolean] True if block-level
126
- def block_level_element?(element)
127
- element.is_a?(Coradoc::AsciiDoc::Model::Block::Core) ||
128
- element.is_a?(Coradoc::AsciiDoc::Model::Section) ||
129
- element.is_a?(Coradoc::AsciiDoc::Model::Paragraph) ||
130
- element.is_a?(Coradoc::AsciiDoc::Model::List) ||
131
- element.is_a?(Coradoc::AsciiDoc::Model::Table)
132
- end
133
-
134
123
  # Helper to add spacing between elements
135
124
  # @param elements [Array] Elements to space
136
125
  # @param options [Hash] Spacing options
@@ -94,16 +94,10 @@ module Coradoc
94
94
  private
95
95
 
96
96
  def inline?(elem)
97
- case elem
98
- when Coradoc::AsciiDoc::Model::Inline::HardLineBreak
99
- :hardbreak
100
- when ->(i) { i.class.name.to_s.include?('::Inline::') }
101
- true
102
- when String, Coradoc::AsciiDoc::Model::TextElement, Coradoc::AsciiDoc::Model::Image::InlineImage
103
- true
104
- else
105
- false
106
- end
97
+ return true if elem.is_a?(String)
98
+ return false unless elem.is_a?(Coradoc::AsciiDoc::Model::Base)
99
+
100
+ elem.inline?
107
101
  end
108
102
 
109
103
  def gen_anchor(inline: false)
@@ -47,19 +47,11 @@ module Coradoc
47
47
  end
48
48
  end
49
49
 
50
- # Check if element is block-level
51
- # @param element [Object] Element to check
52
- # @return [Boolean] True if block-level
53
50
  def block_level?(element)
54
51
  return false if element.nil?
52
+ return true if element.is_a?(String)
55
53
 
56
- element.is_a?(Coradoc::AsciiDoc::Model::Block::Core) ||
57
- element.is_a?(Coradoc::AsciiDoc::Model::Section) ||
58
- element.is_a?(Coradoc::AsciiDoc::Model::Paragraph) ||
59
- element.is_a?(Coradoc::AsciiDoc::Model::List) ||
60
- element.is_a?(Coradoc::AsciiDoc::Model::Table) ||
61
- element.is_a?(Coradoc::AsciiDoc::Model::CommentBlock) ||
62
- element.is_a?(Coradoc::AsciiDoc::Model::Admonition)
54
+ element.block_level?
63
55
  end
64
56
 
65
57
  # Check if element is inline-level
@@ -67,15 +59,9 @@ module Coradoc
67
59
  # @return [Boolean] True if inline-level
68
60
  def inline_level?(element)
69
61
  return false if element.nil?
62
+ return true if element.is_a?(String)
70
63
 
71
- element.is_a?(String) ||
72
- element.is_a?(Coradoc::AsciiDoc::Model::TextElement) ||
73
- element.is_a?(Coradoc::AsciiDoc::Model::Inline::Bold) ||
74
- element.is_a?(Coradoc::AsciiDoc::Model::Inline::Italic) ||
75
- element.is_a?(Coradoc::AsciiDoc::Model::Inline::Monospace) ||
76
- element.is_a?(Coradoc::AsciiDoc::Model::Inline::Highlight) ||
77
- element.is_a?(Coradoc::AsciiDoc::Model::Inline::Superscript) ||
78
- element.is_a?(Coradoc::AsciiDoc::Model::Inline::Subscript)
64
+ element.inline?
79
65
  end
80
66
  end
81
67
  end
@@ -33,10 +33,24 @@ RSpec.describe Coradoc::AsciiDoc::Model::Base do
33
33
  end
34
34
 
35
35
  describe '#to_adoc' do
36
- it 'is defined on Base' do
36
+ it 'serializes via ElementRegistry' do
37
37
  instance = test_class.new(name: 'test')
38
38
 
39
- expect(instance).to respond_to(:to_adoc)
39
+ expect(instance).to be_a(described_class)
40
+ end
41
+ end
42
+
43
+ describe 'element classification' do
44
+ it 'defaults block_level? to false' do
45
+ instance = test_class.new
46
+
47
+ expect(instance.block_level?).to be(false)
48
+ end
49
+
50
+ it 'defaults inline? to false' do
51
+ instance = test_class.new
52
+
53
+ expect(instance.inline?).to be(false)
40
54
  end
41
55
  end
42
56
 
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'Element classification' do
6
+ describe 'block_level?' do
7
+ it 'Section is block-level' do
8
+ expect(Coradoc::AsciiDoc::Model::Section.new.block_level?).to be(true)
9
+ end
10
+
11
+ it 'Paragraph is block-level' do
12
+ expect(Coradoc::AsciiDoc::Model::Paragraph.new.block_level?).to be(true)
13
+ end
14
+
15
+ it 'Admonition is block-level' do
16
+ expect(Coradoc::AsciiDoc::Model::Admonition.new.block_level?).to be(true)
17
+ end
18
+
19
+ it 'CommentBlock is block-level' do
20
+ expect(Coradoc::AsciiDoc::Model::CommentBlock.new.block_level?).to be(true)
21
+ end
22
+
23
+ it 'Table is block-level' do
24
+ expect(Coradoc::AsciiDoc::Model::Table.new.block_level?).to be(true)
25
+ end
26
+
27
+ it 'Block::Core is block-level' do
28
+ expect(Coradoc::AsciiDoc::Model::Block::Core.new.block_level?).to be(true)
29
+ end
30
+
31
+ it 'Block::Listing is block-level (inherits from Core)' do
32
+ expect(Coradoc::AsciiDoc::Model::Block::Listing.new.block_level?).to be(true)
33
+ end
34
+
35
+ it 'Block::Quote is block-level (inherits from Core)' do
36
+ expect(Coradoc::AsciiDoc::Model::Block::Quote.new.block_level?).to be(true)
37
+ end
38
+
39
+ it 'List::Ordered is block-level' do
40
+ expect(Coradoc::AsciiDoc::Model::List::Ordered.new.block_level?).to be(true)
41
+ end
42
+
43
+ it 'List::Unordered is block-level' do
44
+ expect(Coradoc::AsciiDoc::Model::List::Unordered.new.block_level?).to be(true)
45
+ end
46
+
47
+ it 'BlockImage is block-level' do
48
+ expect(Coradoc::AsciiDoc::Model::Image::BlockImage.new.block_level?).to be(true)
49
+ end
50
+ end
51
+
52
+ describe 'inline?' do
53
+ it 'Inline::Bold is inline' do
54
+ expect(Coradoc::AsciiDoc::Model::Inline::Bold.new.inline?).to be(true)
55
+ end
56
+
57
+ it 'Inline::Italic is inline' do
58
+ expect(Coradoc::AsciiDoc::Model::Inline::Italic.new.inline?).to be(true)
59
+ end
60
+
61
+ it 'Inline::Monospace is inline' do
62
+ expect(Coradoc::AsciiDoc::Model::Inline::Monospace.new.inline?).to be(true)
63
+ end
64
+
65
+ it 'Inline::Highlight is inline' do
66
+ expect(Coradoc::AsciiDoc::Model::Inline::Highlight.new.inline?).to be(true)
67
+ end
68
+
69
+ it 'Inline::Superscript is inline' do
70
+ expect(Coradoc::AsciiDoc::Model::Inline::Superscript.new.inline?).to be(true)
71
+ end
72
+
73
+ it 'Inline::Subscript is inline' do
74
+ expect(Coradoc::AsciiDoc::Model::Inline::Subscript.new.inline?).to be(true)
75
+ end
76
+
77
+ it 'Inline::Link is inline' do
78
+ expect(Coradoc::AsciiDoc::Model::Inline::Link.new.inline?).to be(true)
79
+ end
80
+
81
+ it 'Inline::Anchor is inline' do
82
+ expect(Coradoc::AsciiDoc::Model::Inline::Anchor.new.inline?).to be(true)
83
+ end
84
+
85
+ it 'TextElement is inline' do
86
+ expect(Coradoc::AsciiDoc::Model::TextElement.new.inline?).to be(true)
87
+ end
88
+
89
+ it 'InlineImage is inline' do
90
+ expect(Coradoc::AsciiDoc::Model::Image::InlineImage.new.inline?).to be(true)
91
+ end
92
+
93
+ it 'HardLineBreak returns :hardbreak' do
94
+ expect(Coradoc::AsciiDoc::Model::Inline::HardLineBreak.new.inline?).to eq(:hardbreak)
95
+ end
96
+ end
97
+
98
+ describe 'non-block, non-inline elements' do
99
+ it 'Title is neither block nor inline' do
100
+ title = Coradoc::AsciiDoc::Model::Title.new
101
+ expect(title.block_level?).to be(false)
102
+ expect(title.inline?).to be(false)
103
+ end
104
+
105
+ it 'List::Item is neither block nor inline' do
106
+ item = Coradoc::AsciiDoc::Model::List::Item.new
107
+ expect(item.block_level?).to be(false)
108
+ expect(item.inline?).to be(false)
109
+ end
110
+
111
+ it 'AttributeList is neither block nor inline' do
112
+ attrs = Coradoc::AsciiDoc::Model::AttributeList.new
113
+ expect(attrs.block_level?).to be(false)
114
+ expect(attrs.inline?).to be(false)
115
+ end
116
+ end
117
+
118
+ describe 'SpacingStrategy integration' do
119
+ let(:strategy) { Coradoc::AsciiDoc::Serializer::SpacingStrategy }
120
+
121
+ it 'uses polymorphic block_level? for spacing' do
122
+ para = Coradoc::AsciiDoc::Model::Paragraph.new
123
+ section = Coradoc::AsciiDoc::Model::Section.new
124
+
125
+ expect(strategy.block_level?(para)).to be(true)
126
+ expect(strategy.block_level?(section)).to be(true)
127
+ end
128
+
129
+ it 'uses polymorphic inline? for spacing' do
130
+ bold = Coradoc::AsciiDoc::Model::Inline::Bold.new
131
+ text = Coradoc::AsciiDoc::Model::TextElement.new
132
+
133
+ expect(strategy.inline_level?(bold)).to be(true)
134
+ expect(strategy.inline_level?(text)).to be(true)
135
+ end
136
+
137
+ it 'returns false for nil' do
138
+ expect(strategy.block_level?(nil)).to be(false)
139
+ expect(strategy.inline_level?(nil)).to be(false)
140
+ end
141
+
142
+ it 'treats strings as inline' do
143
+ expect(strategy.inline_level?('text')).to be(true)
144
+ end
145
+ end
146
+ end
@@ -62,7 +62,7 @@ module Coradoc
62
62
  private
63
63
 
64
64
  def extract_paragraph_text(paragraph)
65
- return '' unless paragraph.respond_to?(:text)
65
+ return '' unless paragraph.is_a?(Uniword::Wordprocessingml::Paragraph) || paragraph.is_a?(Uniword::Wordprocessingml::Run)
66
66
 
67
67
  paragraph.text.to_s
68
68
  end
@@ -242,11 +242,19 @@ module Coradoc
242
242
  end
243
243
 
244
244
  def add_list_to_builder(list_block, builder)
245
- method = list_block.marker_type == 'numbered' ? :numbered_list : :bullet_list
245
+ list_method = list_block.marker_type == 'numbered' ? :numbered_list : :bullet_list
246
246
 
247
- builder.send(method) do |list|
248
- list_block.items.each do |item|
249
- list.item(item.flat_text)
247
+ if list_method == :numbered_list
248
+ builder.numbered_list do |list|
249
+ list_block.items.each do |item|
250
+ list.item(item.flat_text)
251
+ end
252
+ end
253
+ else
254
+ builder.bullet_list do |list|
255
+ list_block.items.each do |item|
256
+ list.item(item.flat_text)
257
+ end
250
258
  end
251
259
  end
252
260
  end
@@ -334,8 +342,7 @@ module Coradoc
334
342
  va.value = 'superscript'
335
343
  props.vertical_align = va
336
344
  when 'monospace'
337
- # Monospace via font
338
- props.font = 'Courier New' if props.respond_to?(:font=)
345
+ props.fonts = Uniword::Wordprocessingml::RFonts.new(ascii: 'Courier New')
339
346
  when 'link'
340
347
  # Links need to be at the paragraph level (w:hyperlink)
341
348
  # Return the run; caller should wrap in Hyperlink
@@ -61,8 +61,8 @@ module Coradoc
61
61
  def build_num_map(config)
62
62
  return {} unless config
63
63
 
64
- instances = config.respond_to?(:instances) ? config.instances : []
65
- return {} if instances.empty?
64
+ instances = config.instances
65
+ return {} if instances.nil? || instances.empty?
66
66
 
67
67
  map = {}
68
68
  instances.each do |inst|
@@ -73,8 +73,8 @@ module Coradoc
73
73
  definition = find_definition(config, abstract_num_id)
74
74
  next unless definition
75
75
 
76
- levels = definition.respond_to?(:levels) ? definition.levels : []
77
- level = levels.first
76
+ levels = definition.levels
77
+ level = levels&.first
78
78
  next unless level
79
79
 
80
80
  fmt = extract_num_fmt(level)
@@ -93,11 +93,13 @@ module Coradoc
93
93
  aid = instance.abstract_num_id
94
94
  return nil unless aid
95
95
 
96
- aid.respond_to?(:value) ? aid.value : aid
96
+ aid.is_a?(Uniword::Wordprocessingml::AbstractNumId) ? aid.val : aid
97
97
  end
98
98
 
99
99
  def find_definition(config, abstract_num_id)
100
- defs = config.respond_to?(:definitions) ? config.definitions : []
100
+ defs = config.definitions
101
+ return [] unless defs
102
+
101
103
  defs.find { |d| d.abstract_num_id == abstract_num_id }
102
104
  end
103
105
 
@@ -105,7 +107,7 @@ module Coradoc
105
107
  nf = level.numFmt
106
108
  return 'bullet' unless nf
107
109
 
108
- nf.respond_to?(:val) ? nf.val.to_s : nf.to_s
110
+ nf.is_a?(Uniword::Wordprocessingml::NumFmt) ? nf.val.to_s : nf.to_s
109
111
  end
110
112
 
111
113
  def marker_type_for(fmt)