coradoc-markdown 1.0.4 → 1.0.5

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: 953ed53e8524e48cac6182bce3e847cc99deba64ba70e49add437b170186bc4c
4
+ data.tar.gz: 4b47acb69d7ab740fe2bb1f40e14ed0471cc4766ae7bb861efe066a94551eb33
5
5
  SHA512:
6
- metadata.gz: e551c841bc950973c7a96274e77f31b450916cfcd4bc989dd6f425688d493898318f6ac545dc537b1cf584fa7f6d3d8d8fa9c7a00b47750d7407abf2419494b9
7
- data.tar.gz: c75199d663605c880367231f1f3779480ac7582610d55983a0bedced93b513041bedf8d190066c8d6bacd3220ec6646b9a7b0e57ceb00bbde7ed138dd462cae0
6
+ metadata.gz: 5e46c8a03f843c7061438135d27440476f4415c29a3c9d3f253cc523ae90a13ea044fa801c839f6ab7723ecc414c88a7773ac40effd10de38177dc376fafbd62
7
+ data.tar.gz: 7a3480158a1aef2af7236d751577fb5297f0844f148a54218b23b2583c74fee472b42c5a8c10b356b4b2c4e13999c3521fb6be4f808d27e037893509e458ec91
@@ -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
@@ -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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Coradoc
4
4
  module Markdown
5
- VERSION = '1.0.4'
5
+ VERSION = '1.0.5'
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.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.