coradoc-markdown 1.0.5 → 1.0.6

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: 953ed53e8524e48cac6182bce3e847cc99deba64ba70e49add437b170186bc4c
4
- data.tar.gz: 4b47acb69d7ab740fe2bb1f40e14ed0471cc4766ae7bb861efe066a94551eb33
3
+ metadata.gz: bdce5853004d12a0dde16c5e512cdb8ce689babaa65b64ec2b64c6dd69b0b245
4
+ data.tar.gz: 27c0c58e7ca3b4ed423fc072730442915be12d435f5eb09e58181e15824ba45f
5
5
  SHA512:
6
- metadata.gz: 5e46c8a03f843c7061438135d27440476f4415c29a3c9d3f253cc523ae90a13ea044fa801c839f6ab7723ecc414c88a7773ac40effd10de38177dc376fafbd62
7
- data.tar.gz: 7a3480158a1aef2af7236d751577fb5297f0844f148a54218b23b2583c74fee472b42c5a8c10b356b4b2c4e13999c3521fb6be4f808d27e037893509e458ec91
6
+ metadata.gz: 32fdb2bf2484781c0d704300eba6b7d60e15c3980f6468252c621f3884b8abee17a5da7283fd0197a1c76f84a3d033538d41f818f2f1ae356071a602a30a203b
7
+ data.tar.gz: 72b5e70e3aec45b3670727fcff8439cb0ef520d2019f91c71c753b3dfb14e39648e3e3c66ed02429f3bb099465e61dc0568c4ef496745680b1b3d870c9b0a946
@@ -14,8 +14,10 @@ module Coradoc
14
14
  # The definition content (text or nested blocks)
15
15
  attribute :content, :string
16
16
 
17
- # Inline content can be an array of text/inline elements
18
- attribute :inline_content, :string, collection: true
17
+ # Inline content as typed Markdown elements (Code, Strong, Text, etc.).
18
+ # When present, the Flat serializer renders these via
19
+ # `ctx.serialize_inline_join` so inline formatting is preserved.
20
+ attribute :inline_content, Coradoc::Markdown::Base, collection: true, default: []
19
21
 
20
22
  # Nested block content (paragraphs, code blocks, lists, etc.)
21
23
  attribute :blocks, :string, collection: true
@@ -15,16 +15,22 @@ module Coradoc
15
15
  attribute :text, :string
16
16
  attribute :definitions, Coradoc::Markdown::DefinitionItem, collection: true, default: []
17
17
 
18
+ # Typed inline children for the term (Code, Strong, Text, etc.).
19
+ # When present, the Flat serializer renders these via
20
+ # `ctx.serialize_inline_join` so inline formatting is preserved.
21
+ attribute :text_children, Coradoc::Markdown::Base, collection: true, default: []
22
+
18
23
  # Optional nested definition list under this term.
19
24
  # When present, the flat-PHP-Markdown-Extra syntax is no longer
20
25
  # sufficient and the serializer falls back to HTML <dl>/<dt>/<dd>.
21
26
  attribute :nested, Coradoc::Markdown::DefinitionList
22
27
 
23
- def initialize(text: '', definitions: [], nested: nil, **rest)
28
+ def initialize(text: '', definitions: [], nested: nil, text_children: [], **rest)
24
29
  super
25
30
  @text = text
26
31
  @definitions = definitions
27
32
  @nested = nested
33
+ @text_children = Array(text_children)
28
34
  end
29
35
  end
30
36
  end
@@ -24,11 +24,11 @@ module Coradoc
24
24
  list.items.none? { |term| term.nested }
25
25
  end
26
26
 
27
- def render(list, _ctx)
27
+ def render(list, ctx)
28
28
  list.items.map do |term|
29
- lines = [term.text.to_s]
29
+ lines = [render_term(term, ctx)]
30
30
  term.definitions.each do |defn|
31
- content_str = defn.content.to_s
31
+ content_str = render_definition(defn, ctx)
32
32
  content_str.lines.each_with_index do |line, i|
33
33
  stripped = line.rstrip
34
34
  next if i.positive? && stripped.empty?
@@ -39,6 +39,22 @@ module Coradoc
39
39
  lines.join("\n")
40
40
  end.join("\n\n")
41
41
  end
42
+
43
+ private
44
+
45
+ def render_term(term, ctx)
46
+ children = term.text_children
47
+ return term.text.to_s if children.nil? || children.empty?
48
+
49
+ ctx.serialize_inline_join(children)
50
+ end
51
+
52
+ def render_definition(defn, ctx)
53
+ children = defn.inline_content
54
+ return defn.content.to_s if children.nil? || children.empty?
55
+
56
+ ctx.serialize_inline_join(children)
57
+ end
42
58
  end
43
59
  end
44
60
  end
@@ -412,13 +412,13 @@ module Coradoc
412
412
 
413
413
  def transform_definition_list(dl)
414
414
  items = Array(dl.items).map do |item|
415
- definitions = Array(item.definitions).map do |defn|
416
- Coradoc::Markdown::DefinitionItem.new(content: defn.to_s)
417
- end
415
+ definition = build_definition_item(item)
418
416
  nested = item.nested ? transform_definition_list(item.nested) : nil
417
+ term_children = Array(item.term_children).map { |c| transform_inline_content(c) }
419
418
  Coradoc::Markdown::DefinitionTerm.new(
420
419
  text: item.term.to_s,
421
- definitions: definitions,
420
+ text_children: term_children,
421
+ definitions: [definition],
422
422
  nested: nested
423
423
  )
424
424
  end
@@ -426,6 +426,20 @@ module Coradoc
426
426
  Coradoc::Markdown::DefinitionList.new(items: items)
427
427
  end
428
428
 
429
+ def build_definition_item(item)
430
+ children = Array(item.definition_children)
431
+ if children.empty?
432
+ content = item.definitions&.first&.to_s
433
+ return Coradoc::Markdown::DefinitionItem.new(content: content)
434
+ end
435
+
436
+ inline = children.map { |c| transform_inline_content(c) }
437
+ Coradoc::Markdown::DefinitionItem.new(
438
+ content: item.definitions&.first&.to_s,
439
+ inline_content: inline
440
+ )
441
+ end
442
+
429
443
  def transform_footnote(fn)
430
444
  Coradoc::Markdown::Footnote.new(
431
445
  id: fn.id.to_s,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Coradoc
4
4
  module Markdown
5
- VERSION = '1.0.5'
5
+ VERSION = '1.0.6'
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.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.