coradoc-markdown 1.0.3 → 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 +4 -4
- data/lib/coradoc/markdown/model/admonition.rb +7 -1
- data/lib/coradoc/markdown/model/example_block.rb +3 -1
- data/lib/coradoc/markdown/serializer/serializers/example_block.rb +14 -6
- data/lib/coradoc/markdown/serializer/strategies/admonition/base.rb +11 -0
- data/lib/coradoc/markdown/serializer/strategies/admonition/container.rb +2 -2
- data/lib/coradoc/markdown/serializer/strategies/admonition/gfm_alert.rb +2 -2
- data/lib/coradoc/markdown/serializer/strategies/admonition/github.rb +3 -5
- data/lib/coradoc/markdown/serializer/strategies/admonition/html.rb +2 -2
- data/lib/coradoc/markdown/transform/from_core_model.rb +12 -2
- data/lib/coradoc/markdown/version.rb +1 -1
- metadata +1 -1
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
|
|
@@ -24,11 +24,17 @@ module Coradoc
|
|
|
24
24
|
attribute :content, :string
|
|
25
25
|
attribute :title, :string
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
# Mixed inline content (strings and inline model objects) carried
|
|
28
|
+
# from the CoreModel children so serializers can preserve cross
|
|
29
|
+
# references, code spans, etc. When empty, fall back to `content`.
|
|
30
|
+
attr_reader :children
|
|
31
|
+
|
|
32
|
+
def initialize(admonition_type:, content:, title: nil, children: [], **rest)
|
|
28
33
|
super
|
|
29
34
|
@admonition_type = admonition_type.to_s.downcase
|
|
30
35
|
@content = content
|
|
31
36
|
@title = title
|
|
37
|
+
@children = Array(children)
|
|
32
38
|
end
|
|
33
39
|
end
|
|
34
40
|
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
|
|
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
|
|
@@ -21,6 +21,17 @@ module Coradoc
|
|
|
21
21
|
def mode_name
|
|
22
22
|
name.split('::').last.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase.to_sym
|
|
23
23
|
end
|
|
24
|
+
|
|
25
|
+
# Render the admonition body, preferring typed children
|
|
26
|
+
# (so cross-refs, code spans, etc. survive) and falling
|
|
27
|
+
# back to the plain-text content attribute when there are
|
|
28
|
+
# no children or the ctx can't serialize them.
|
|
29
|
+
def render_body(admonition, ctx)
|
|
30
|
+
children = admonition.children
|
|
31
|
+
return admonition.content.to_s if children.nil? || children.empty?
|
|
32
|
+
|
|
33
|
+
ctx.serialize_inline_join(children)
|
|
34
|
+
end
|
|
24
35
|
end
|
|
25
36
|
end
|
|
26
37
|
end
|
|
@@ -20,10 +20,10 @@ module Coradoc
|
|
|
20
20
|
# :::
|
|
21
21
|
class Container < Base
|
|
22
22
|
class << self
|
|
23
|
-
def render(admonition,
|
|
23
|
+
def render(admonition, ctx)
|
|
24
24
|
type = admonition.admonition_type.to_s
|
|
25
25
|
title_suffix = admonition.title ? "[#{admonition.title}]" : ''
|
|
26
|
-
":::#{type}#{title_suffix}\n#{admonition
|
|
26
|
+
":::#{type}#{title_suffix}\n#{render_body(admonition, ctx)}\n:::"
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -12,9 +12,9 @@ module Coradoc
|
|
|
12
12
|
# Source: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts
|
|
13
13
|
class GfmAlert < Base
|
|
14
14
|
class << self
|
|
15
|
-
def render(admonition,
|
|
15
|
+
def render(admonition, ctx)
|
|
16
16
|
type = admonition.admonition_type.to_s.capitalize
|
|
17
|
-
body = admonition
|
|
17
|
+
body = render_body(admonition, ctx)
|
|
18
18
|
body = body.lines.map { |line| "> #{line}".rstrip }.join("\n")
|
|
19
19
|
title_suffix = admonition.title ? " \"#{admonition.title}\"" : ''
|
|
20
20
|
"> [!#{type}]#{title_suffix}\n#{body}"
|
|
@@ -12,12 +12,10 @@ module Coradoc
|
|
|
12
12
|
# recognize the bold-prefix pattern.
|
|
13
13
|
class Github < Base
|
|
14
14
|
class << self
|
|
15
|
-
def render(admonition,
|
|
15
|
+
def render(admonition, ctx)
|
|
16
16
|
type = admonition.admonition_type.to_s.upcase
|
|
17
|
-
body = admonition
|
|
18
|
-
if admonition.title
|
|
19
|
-
body = "**#{admonition.title}**\n\n#{body}" unless admonition.title.to_s.strip.empty?
|
|
20
|
-
end
|
|
17
|
+
body = render_body(admonition, ctx)
|
|
18
|
+
body = "**#{admonition.title}**\n\n#{body}" if admonition.title && !admonition.title.to_s.strip.empty?
|
|
21
19
|
"> **#{type}:** #{body}"
|
|
22
20
|
end
|
|
23
21
|
end
|
|
@@ -11,10 +11,10 @@ module Coradoc
|
|
|
11
11
|
# `<div class="title">` for the title.
|
|
12
12
|
class Html < Base
|
|
13
13
|
class << self
|
|
14
|
-
def render(admonition,
|
|
14
|
+
def render(admonition, ctx)
|
|
15
15
|
type = admonition.admonition_type.to_s
|
|
16
16
|
title_html = admonition.title ? %(<div class="title">#{admonition.title}</div>\n) : ''
|
|
17
|
-
%(<div class="#{type}">\n#{title_html}#{admonition
|
|
17
|
+
%(<div class="#{type}">\n#{title_html}#{render_body(admonition, ctx)}\n</div>)
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -165,6 +165,12 @@ module Coradoc
|
|
|
165
165
|
end
|
|
166
166
|
end
|
|
167
167
|
|
|
168
|
+
def transform_inline_array(renderable)
|
|
169
|
+
return [] unless renderable.is_a?(Array)
|
|
170
|
+
|
|
171
|
+
renderable.map { |c| transform_inline_content(c) }
|
|
172
|
+
end
|
|
173
|
+
|
|
168
174
|
def transform_delimited_block(block)
|
|
169
175
|
semantic = resolve_markdown_semantic(block)
|
|
170
176
|
|
|
@@ -226,9 +232,11 @@ module Coradoc
|
|
|
226
232
|
end
|
|
227
233
|
|
|
228
234
|
def transform_example_block(block)
|
|
235
|
+
children = Array(block.children).map { |c| transform(c) }.flat_map { |c| flatten_result(c) }
|
|
229
236
|
Coradoc::Markdown::ExampleBlock.new(
|
|
230
237
|
content: block.flat_text,
|
|
231
|
-
caption: block.title.to_s
|
|
238
|
+
caption: block.title.to_s,
|
|
239
|
+
children: children
|
|
232
240
|
)
|
|
233
241
|
end
|
|
234
242
|
|
|
@@ -255,10 +263,12 @@ module Coradoc
|
|
|
255
263
|
end
|
|
256
264
|
|
|
257
265
|
def transform_admonition_block(block, default_type: 'note')
|
|
266
|
+
children = transform_inline_array(block.renderable_content)
|
|
258
267
|
Coradoc::Markdown::Admonition.new(
|
|
259
268
|
admonition_type: block.respond_to?(:annotation_type) ? (block.annotation_type || default_type) : default_type,
|
|
260
269
|
content: block.flat_text,
|
|
261
|
-
title: block.respond_to?(:annotation_label) ? block.annotation_label : nil
|
|
270
|
+
title: block.respond_to?(:annotation_label) ? block.annotation_label : nil,
|
|
271
|
+
children: children
|
|
262
272
|
)
|
|
263
273
|
end
|
|
264
274
|
|