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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 953ed53e8524e48cac6182bce3e847cc99deba64ba70e49add437b170186bc4c
|
|
4
|
+
data.tar.gz: 4b47acb69d7ab740fe2bb1f40e14ed0471cc4766ae7bb861efe066a94551eb33
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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
|
-
|
|
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#{
|
|
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
|
|