coradoc-markdown 1.0.4 → 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: 007d0f6cb59531d5677c8775118fa2e676f811b067b725170963a64d727235da
4
- data.tar.gz: ca79c3da61050874894e5815cf03c5cce54711781ae51c5c4971cb5b56d36040
3
+ metadata.gz: bdce5853004d12a0dde16c5e512cdb8ce689babaa65b64ec2b64c6dd69b0b245
4
+ data.tar.gz: 27c0c58e7ca3b4ed423fc072730442915be12d435f5eb09e58181e15824ba45f
5
5
  SHA512:
6
- metadata.gz: e551c841bc950973c7a96274e77f31b450916cfcd4bc989dd6f425688d493898318f6ac545dc537b1cf584fa7f6d3d8d8fa9c7a00b47750d7407abf2419494b9
7
- data.tar.gz: c75199d663605c880367231f1f3779480ac7582610d55983a0bedced93b513041bedf8d190066c8d6bacd3220ec6646b9a7b0e57ceb00bbde7ed138dd462cae0
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
@@ -15,11 +15,13 @@ module Coradoc
15
15
  class ExampleBlock < Base
16
16
  attribute :content, :string
17
17
  attribute :caption, :string
18
+ attribute :children, Coradoc::Markdown::Base, collection: true, default: []
18
19
 
19
- def initialize(content:, caption: nil, **rest)
20
+ def initialize(content:, caption: nil, children: [], **rest)
20
21
  super
21
22
  @content = content
22
23
  @caption = caption
24
+ @children = Array(children)
23
25
  end
24
26
  end
25
27
  end
@@ -15,23 +15,31 @@ module Coradoc
15
15
  handles_type ::Coradoc::Markdown::ExampleBlock
16
16
 
17
17
  def call(element, ctx)
18
+ body = render_body(element, ctx)
18
19
  if ctx.config.admonition_style == :container
19
- render_container(element)
20
+ render_container(element, body)
20
21
  else
21
- render_html(element)
22
+ render_html(element, body)
22
23
  end
23
24
  end
24
25
 
25
26
  private
26
27
 
27
- def render_html(element)
28
+ def render_body(element, ctx)
29
+ return element.content.to_s if element.children.nil? || element.children.empty?
30
+
31
+ element.children.map { |c| ctx.serialize(c) }.join("\n\n")
32
+ end
33
+
34
+ def render_html(element, body)
28
35
  caption_html = element.caption ? %(<h4>Example: #{element.caption}</h4>\n) : ''
29
- %(<div class="example">\n#{caption_html}<p>#{element.content.to_s}</p>\n</div>)
36
+ inner = element.children&.any? ? body : "<p>#{body}</p>"
37
+ %(<div class="example">\n#{caption_html}#{inner}\n</div>)
30
38
  end
31
39
 
32
- def render_container(element)
40
+ def render_container(element, body)
33
41
  title = element.caption ? " Example: #{element.caption}" : ''
34
- ":::details#{title}\n#{element.content.to_s}\n:::"
42
+ ":::details#{title}\n#{body}\n:::"
35
43
  end
36
44
  end
37
45
  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
@@ -232,9 +232,11 @@ module Coradoc
232
232
  end
233
233
 
234
234
  def transform_example_block(block)
235
+ children = Array(block.children).map { |c| transform(c) }.flat_map { |c| flatten_result(c) }
235
236
  Coradoc::Markdown::ExampleBlock.new(
236
237
  content: block.flat_text,
237
- caption: block.title.to_s
238
+ caption: block.title.to_s,
239
+ children: children
238
240
  )
239
241
  end
240
242
 
@@ -410,13 +412,13 @@ module Coradoc
410
412
 
411
413
  def transform_definition_list(dl)
412
414
  items = Array(dl.items).map do |item|
413
- definitions = Array(item.definitions).map do |defn|
414
- Coradoc::Markdown::DefinitionItem.new(content: defn.to_s)
415
- end
415
+ definition = build_definition_item(item)
416
416
  nested = item.nested ? transform_definition_list(item.nested) : nil
417
+ term_children = Array(item.term_children).map { |c| transform_inline_content(c) }
417
418
  Coradoc::Markdown::DefinitionTerm.new(
418
419
  text: item.term.to_s,
419
- definitions: definitions,
420
+ text_children: term_children,
421
+ definitions: [definition],
420
422
  nested: nested
421
423
  )
422
424
  end
@@ -424,6 +426,20 @@ module Coradoc
424
426
  Coradoc::Markdown::DefinitionList.new(items: items)
425
427
  end
426
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
+
427
443
  def transform_footnote(fn)
428
444
  Coradoc::Markdown::Footnote.new(
429
445
  id: fn.id.to_s,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Coradoc
4
4
  module Markdown
5
- VERSION = '1.0.4'
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.4
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.