coradoc-markdown 1.0.9 → 1.0.10

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8787bd4fa185e797413467515c62bcd103651592e9ef33a6c6d9afe07f087c5c
4
- data.tar.gz: e63120ad791f193d3a09711da9345788482ae6076bc8a173d97b863b6273b69f
3
+ metadata.gz: 45a195eaddedba173983f2ba2ab08ce81044fe089124b8287b4a643262dbc6f8
4
+ data.tar.gz: b163677948cdc8459692c411c2840f2bfa0cfe401e47453d61e88d156bbfc910
5
5
  SHA512:
6
- metadata.gz: 707ffce48956d79723b12c6112ff9237f5149037f830f37b32ad2905e6ea1ad8b0456d888ce7d4cf74315d54e9e4fab37287e44cb7d38d363318bae9f13d8a25
7
- data.tar.gz: 5ef6ac646dac9047440649ad153e0bbd8300caa29633c8b41e1bcf58c09e5eee034a2aec0e63be3e4c4d5c423dca02a488d6f9912711f576f9a9d8288b3b4541
6
+ metadata.gz: 3b6c63bf4e97c80a63c4f6289576f80577434d6aa8176aafd3067c026abbad4c9ab72fbe509e936933f60ef6cf02c7e3b6087efab353f541618ffe75d6c93ad1
7
+ data.tar.gz: 0a7a78dc0d92fd3c03344df7a6063429b443dcacfc760686a7d3080b6df7daff9b873251a1576d73307bbacfa8e642e08e02561625f6cfcd2d493f524843dd4b
@@ -27,14 +27,13 @@ module Coradoc
27
27
  # Mixed inline content (strings and inline model objects) carried
28
28
  # from the CoreModel children so serializers can preserve cross
29
29
  # references, code spans, etc. When empty, fall back to `content`.
30
- attr_reader :children
30
+ attribute :children, Coradoc::Markdown::Base, collection: true, default: []
31
31
 
32
- def initialize(admonition_type:, content:, title: nil, children: [], **rest)
33
- super
34
- @admonition_type = admonition_type.to_s.downcase
35
- @content = content
36
- @title = title
37
- @children = Array(children)
32
+ # Normalize type on assignment. Callers can pass "NOTE", "Note",
33
+ # or "note" — storage is always lowercase so downstream comparison
34
+ # and CSS class generation don't need to repeat the normalization.
35
+ def admonition_type=(value)
36
+ super(value.to_s.downcase)
38
37
  end
39
38
  end
40
39
  end
@@ -11,11 +11,6 @@ module Coradoc
11
11
  #
12
12
  class Blockquote < Base
13
13
  attribute :content, :string
14
-
15
- def initialize(content: '')
16
- super()
17
- @content = content
18
- end
19
14
  end
20
15
  end
21
16
  end
@@ -13,12 +13,6 @@ module Coradoc
13
13
  class CodeBlock < Base
14
14
  attribute :language, :string
15
15
  attribute :code, :string
16
-
17
- def initialize(language: nil, code: '')
18
- super()
19
- @language = language
20
- @code = code
21
- end
22
16
  end
23
17
  end
24
18
  end
@@ -11,4 +11,4 @@ module Coradoc
11
11
  attribute :text, :string
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -24,14 +24,6 @@ module Coradoc
24
24
  # When present, the flat-PHP-Markdown-Extra syntax is no longer
25
25
  # sufficient and the serializer falls back to HTML <dl>/<dt>/<dd>.
26
26
  attribute :nested, Coradoc::Markdown::DefinitionList
27
-
28
- def initialize(text: '', definitions: [], nested: nil, text_children: [], **rest)
29
- super
30
- @text = text
31
- @definitions = definitions
32
- @nested = nested
33
- @text_children = Array(text_children)
34
- end
35
27
  end
36
28
  end
37
29
  end
@@ -16,13 +16,6 @@ module Coradoc
16
16
  attribute :content, :string
17
17
  attribute :caption, :string
18
18
  attribute :children, Coradoc::Markdown::Base, collection: true, default: []
19
-
20
- def initialize(content:, caption: nil, children: [], **rest)
21
- super
22
- @content = content
23
- @caption = caption
24
- @children = Array(children)
25
- end
26
19
  end
27
20
  end
28
21
  end
@@ -11,12 +11,6 @@ module Coradoc
11
11
  attribute :level, :integer, default: 1
12
12
  attribute :text, :string
13
13
 
14
- def initialize(level: 1, text: '')
15
- super()
16
- @level = level
17
- @text = text
18
- end
19
-
20
14
  # Generate an auto ID from the heading text
21
15
  #
22
16
  # @return [String] A slugified version of the text suitable for use as an ID
@@ -8,22 +8,7 @@ module Coradoc
8
8
  attribute :text, :string
9
9
  attribute :checked, :boolean # For task lists (- [ ] or - [x])
10
10
  attribute :sublist, Coradoc::Markdown::List # Nested list
11
-
12
- # Mixed content (strings and inline model objects)
13
- # @return [Array] mixed content array
14
- attr_reader :children
15
-
16
- def initialize(args = {})
17
- super()
18
- @text = args[:text] || ''
19
- @checked = args[:checked]
20
- @sublist = args[:sublist]
21
- @children = args.fetch(:children, [])
22
- end
23
-
24
- def children=(value)
25
- @children = value || []
26
- end
11
+ attribute :children, Coradoc::Markdown::Base, collection: true, default: []
27
12
  end
28
13
  end
29
14
  end
@@ -11,11 +11,6 @@ module Coradoc
11
11
  # Markdown: indented code block (4 leading spaces per line).
12
12
  class Literal < Base
13
13
  attribute :content, :string
14
-
15
- def initialize(content:, **rest)
16
- super
17
- @content = content
18
- end
19
14
  end
20
15
  end
21
16
  end
@@ -12,11 +12,6 @@ module Coradoc
12
12
  # - With id/classes → emit `<div id="...">...</div>` wrapper
13
13
  class OpenBlock < Base
14
14
  attribute :children, Coradoc::Markdown::Base, collection: true, default: []
15
-
16
- def initialize(children: [], **rest)
17
- super
18
- @children = Array(children)
19
- end
20
15
  end
21
16
  end
22
17
  end
@@ -9,20 +9,7 @@ module Coradoc
9
9
  #
10
10
  class Paragraph < Base
11
11
  attribute :text, :string
12
-
13
- # Mixed content (strings and inline model objects)
14
- # @return [Array] mixed content array
15
- attr_reader :children
16
-
17
- def initialize(text: '', children: [])
18
- super()
19
- @text = text
20
- @children = children
21
- end
22
-
23
- def children=(value)
24
- @children = value || []
25
- end
12
+ attribute :children, Base, collection: true, default: []
26
13
  end
27
14
  end
28
15
  end
@@ -11,11 +11,6 @@ module Coradoc
11
11
  # inside a `nomarkdown` kramdown extension or raw HTML passthrough.
12
12
  class Pass < Base
13
13
  attribute :content, :string
14
-
15
- def initialize(content:, **rest)
16
- super
17
- @content = content
18
- end
19
14
  end
20
15
  end
21
16
  end
@@ -13,13 +13,6 @@ module Coradoc
13
13
  attribute :content, :string
14
14
  attribute :title, :string
15
15
  attribute :children, Coradoc::Markdown::Base, collection: true, default: []
16
-
17
- def initialize(content:, title: nil, children: [], **rest)
18
- super
19
- @content = content
20
- @title = title
21
- @children = Array(children)
22
- end
23
16
  end
24
17
  end
25
18
  end
@@ -15,13 +15,6 @@ module Coradoc
15
15
  attribute :content, :string
16
16
  attribute :attribution, :string
17
17
  attribute :citetitle, :string
18
-
19
- def initialize(content:, attribution: nil, citetitle: nil, **rest)
20
- super
21
- @content = content
22
- @attribution = attribution
23
- @citetitle = citetitle
24
- end
25
18
  end
26
19
  end
27
20
  end
@@ -13,9 +13,7 @@ module Coradoc
13
13
  marker = element.ordered ? '1.' : '-'
14
14
  element.items.flat_map do |item|
15
15
  lines = [render_item(item, marker, _ctx)]
16
- if item.sublist
17
- lines += call(item.sublist, _ctx).split("\n").map { |l| " #{l}" }
18
- end
16
+ lines += call(item.sublist, _ctx).split("\n").map { |l| " #{l}" } if item.sublist
19
17
  lines
20
18
  end.join("\n")
21
19
  end
@@ -35,7 +35,7 @@ module Coradoc
35
35
  end
36
36
 
37
37
  def render_term(term)
38
- dt = "<dt>#{term.text.to_s}</dt>"
38
+ dt = "<dt>#{term.text}</dt>"
39
39
  dds = term.definitions.map { |d| render_dd(d) }.join
40
40
  nested = term.nested ? "\n #{render_dl(term.nested)}" : ''
41
41
  "#{dt}\n#{dds}#{nested unless nested.empty?}"
@@ -219,7 +219,7 @@ module Coradoc
219
219
  def transform_verse_block(block)
220
220
  Coradoc::Markdown::Verse.new(
221
221
  content: block.flat_text,
222
- attribution: block.respond_to?(:attribution) ? block.attribution : nil
222
+ attribution: block.is_a?(Coradoc::CoreModel::VerseBlock) ? block.attribution : nil
223
223
  )
224
224
  end
225
225
 
@@ -272,10 +272,17 @@ module Coradoc
272
272
 
273
273
  def transform_admonition_block(block, default_type: 'note')
274
274
  children = transform_inline_array(block.renderable_content)
275
+ if block.is_a?(Coradoc::CoreModel::AnnotationBlock)
276
+ adm_type = block.annotation_type || default_type
277
+ adm_label = block.annotation_label
278
+ else
279
+ adm_type = default_type
280
+ adm_label = nil
281
+ end
275
282
  Coradoc::Markdown::Admonition.new(
276
- admonition_type: block.respond_to?(:annotation_type) ? (block.annotation_type || default_type) : default_type,
283
+ admonition_type: adm_type,
277
284
  content: block.flat_text,
278
- title: block.respond_to?(:annotation_label) ? block.annotation_label : nil,
285
+ title: adm_label,
279
286
  children: children
280
287
  )
281
288
  end
@@ -374,7 +381,7 @@ module Coradoc
374
381
  )
375
382
  end
376
383
 
377
- CALLOUT_MARKER_IN_CELL = /\s*<\d+>(?=\s|\z)/.freeze
384
+ CALLOUT_MARKER_IN_CELL = /\s*<\d+>(?=\s|\z)/
378
385
 
379
386
  def strip_cell_callouts(text)
380
387
  text.to_s.gsub(CALLOUT_MARKER_IN_CELL, '')
@@ -428,21 +435,52 @@ module Coradoc
428
435
  end
429
436
 
430
437
  def transform_definition_list(dl)
431
- items = Array(dl.items).map do |item|
432
- definition = build_definition_item(item)
438
+ # flat_map because each CoreModel DefinitionItem may emit
439
+ # multiple Markdown DefinitionTerms (multi-term `<dt>`).
440
+ items = Array(dl.items).flat_map do |item|
441
+ definitions = [build_definition_item(item)]
442
+ # `+`-continuation blocks attached to the dd become
443
+ # additional definitions in Markdown (each renders as
444
+ # `: line` in the Flat serializer). One DefinitionItem
445
+ # per attached block, preserving their distinct content
446
+ # without jamming them into the primary definition's text.
447
+ definitions.concat(Array(item.attached_children).map { |b| build_attached_definition_item(b) })
433
448
  nested = item.nested ? transform_definition_list(item.nested) : nil
434
449
  term_children = Array(item.term_children).map { |c| transform_inline_content(c) }
435
- Coradoc::Markdown::DefinitionTerm.new(
436
- text: item.term.to_s,
437
- text_children: term_children,
438
- definitions: [definition],
439
- nested: nested
440
- )
450
+ # Multi-term `<dt>`: emit one Markdown DefinitionTerm per
451
+ # term string. Inline children map 1:1 to the FIRST term
452
+ # (matches the mirror handler's behaviour; multi-term
453
+ # with inline markup on later terms is rare and the
454
+ # parser doesn't capture per-term children today).
455
+ terms = terms_for(item)
456
+ if terms.empty?
457
+ # Defensive: term and terms both empty — emit nothing.
458
+ next
459
+ end
460
+
461
+ terms.each_with_index.map do |term_text, idx|
462
+ Coradoc::Markdown::DefinitionTerm.new(
463
+ text: term_text.to_s,
464
+ text_children: idx.zero? ? term_children : [],
465
+ definitions: definitions,
466
+ nested: nested
467
+ )
468
+ end
441
469
  end
442
470
 
443
471
  Coradoc::Markdown::DefinitionList.new(items: items)
444
472
  end
445
473
 
474
+ # Source of truth for "the terms on this <dt>": the `terms`
475
+ # collection when populated, else `[term]` for legacy callers.
476
+ def terms_for(item)
477
+ collection = item.terms if item.is_a?(Coradoc::CoreModel::DefinitionItem)
478
+ return Array(collection) unless collection.nil? || collection.empty?
479
+
480
+ primary = item.term
481
+ primary.to_s.empty? ? [] : [primary.to_s]
482
+ end
483
+
446
484
  def build_definition_item(item)
447
485
  children = Array(item.definition_children)
448
486
  if children.empty?
@@ -457,6 +495,19 @@ module Coradoc
457
495
  )
458
496
  end
459
497
 
498
+ # Build a DefinitionItem from a single attached block (e.g.
499
+ # paragraph from a `+`-continuation). Flat-text extraction
500
+ # via ChildrenContent is the single source of truth — every
501
+ # attached block in CoreModel includes ChildrenContent.
502
+ def build_attached_definition_item(block)
503
+ content = if block.is_a?(Coradoc::CoreModel::ChildrenContent)
504
+ block.flat_text
505
+ else
506
+ block.to_s
507
+ end
508
+ Coradoc::Markdown::DefinitionItem.new(content: content)
509
+ end
510
+
460
511
  def transform_footnote(fn)
461
512
  Coradoc::Markdown::Footnote.new(
462
513
  id: fn.id.to_s,
@@ -30,14 +30,20 @@ module Coradoc
30
30
  end
31
31
 
32
32
  def transform_definition_list(dl)
33
- items = Array(dl.items).map do |item|
33
+ # flat_map because multi-term `<dt>`'s emit multiple
34
+ # DefinitionTerms per CoreModel DefinitionItem.
35
+ items = Array(dl.items).flat_map do |item|
34
36
  definitions = Array(item.definitions).map do |defn|
35
37
  Coradoc::Markdown::DefinitionItem.new(content: defn.to_s)
36
38
  end
37
- Coradoc::Markdown::DefinitionTerm.new(
38
- text: item.term.to_s,
39
- definitions: definitions
40
- )
39
+ terms = item.terms
40
+ term_strings = terms.nil? || terms.empty? ? [item.term.to_s] : terms.map(&:to_s)
41
+ term_strings.map do |term_text|
42
+ Coradoc::Markdown::DefinitionTerm.new(
43
+ text: term_text,
44
+ definitions: definitions
45
+ )
46
+ end
41
47
  end
42
48
 
43
49
  Coradoc::Markdown::DefinitionList.new(items: items)
@@ -80,7 +80,7 @@ module Coradoc
80
80
  def transform_bibliography_entry(entry)
81
81
  FromCoreModel.transform_bibliography_entry(entry)
82
82
  end
83
- end
83
+ end
84
84
 
85
85
  # Register with FromCoreModel
86
86
  FromCoreModel.register(CoreModel::StructuralElement, method(:transform_structural_element))
@@ -165,7 +165,9 @@ module Coradoc
165
165
  cells = if row.is_a?(Array)
166
166
  row.map { |c| Coradoc::CoreModel::TableCell.new(content: c.to_s, header: false) }
167
167
  else
168
- row.to_s.split(' | ').map { |c| Coradoc::CoreModel::TableCell.new(content: c.to_s, header: false) }
168
+ row.to_s.split(' | ').map do |c|
169
+ Coradoc::CoreModel::TableCell.new(content: c.to_s, header: false)
170
+ end
169
171
  end
170
172
  rows << Coradoc::CoreModel::TableRow.new(cells: cells)
171
173
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Coradoc
4
4
  module Markdown
5
- VERSION = '1.0.9'
5
+ VERSION = '1.0.10'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coradoc-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.