coradoc-markdown 1.0.3 → 1.0.4

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: e84594b2f47a9d07086b781a843c5b1f7b2ddb34303bbe32114ea1c9e7ac1aec
4
- data.tar.gz: 7fd311efb6eef499247c37bacb8357d3b6349eabc1347c6a875d21c6b315fa18
3
+ metadata.gz: 007d0f6cb59531d5677c8775118fa2e676f811b067b725170963a64d727235da
4
+ data.tar.gz: ca79c3da61050874894e5815cf03c5cce54711781ae51c5c4971cb5b56d36040
5
5
  SHA512:
6
- metadata.gz: ee32797ed75c3659d6e21fd9041d4f9a193497c50417f1f2ca986bd23459bf83b5a3cab47540f417d34014d806b1f20671e132ca4b0c0195b7b23870cb4aff37
7
- data.tar.gz: 2cfc83d2fa5c1e732283d6efa0d37f05b5f9ea4c8970217f64cbb6771084c4aa2f6fa0aaaba4049aceb9ed9fb611d6395d210a5c8ce8c199a3bbf1768e4d4665
6
+ metadata.gz: e551c841bc950973c7a96274e77f31b450916cfcd4bc989dd6f425688d493898318f6ac545dc537b1cf584fa7f6d3d8d8fa9c7a00b47750d7407abf2419494b9
7
+ data.tar.gz: c75199d663605c880367231f1f3779480ac7582610d55983a0bedced93b513041bedf8d190066c8d6bacd3220ec6646b9a7b0e57ceb00bbde7ed138dd462cae0
@@ -24,11 +24,17 @@ module Coradoc
24
24
  attribute :content, :string
25
25
  attribute :title, :string
26
26
 
27
- def initialize(admonition_type:, content:, title: nil, **rest)
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
@@ -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, _ctx)
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.content.to_s}\n:::"
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, _ctx)
15
+ def render(admonition, ctx)
16
16
  type = admonition.admonition_type.to_s.capitalize
17
- body = admonition.content.to_s
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, _ctx)
15
+ def render(admonition, ctx)
16
16
  type = admonition.admonition_type.to_s.upcase
17
- body = admonition.content.to_s
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, _ctx)
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.content.to_s}\n</div>)
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
 
@@ -255,10 +261,12 @@ module Coradoc
255
261
  end
256
262
 
257
263
  def transform_admonition_block(block, default_type: 'note')
264
+ children = transform_inline_array(block.renderable_content)
258
265
  Coradoc::Markdown::Admonition.new(
259
266
  admonition_type: block.respond_to?(:annotation_type) ? (block.annotation_type || default_type) : default_type,
260
267
  content: block.flat_text,
261
- title: block.respond_to?(:annotation_label) ? block.annotation_label : nil
268
+ title: block.respond_to?(:annotation_label) ? block.annotation_label : nil,
269
+ children: children
262
270
  )
263
271
  end
264
272
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Coradoc
4
4
  module Markdown
5
- VERSION = '1.0.3'
5
+ VERSION = '1.0.4'
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.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.