coradoc-markdown 1.0.6 → 1.0.7

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: bdce5853004d12a0dde16c5e512cdb8ce689babaa65b64ec2b64c6dd69b0b245
4
- data.tar.gz: 27c0c58e7ca3b4ed423fc072730442915be12d435f5eb09e58181e15824ba45f
3
+ metadata.gz: 87855aadbdb24171b83ced3a1f973439655bbd3b9bd676b378449df3de68bbd2
4
+ data.tar.gz: 7ade791de29328f8d9994490d2789d5281995cf18fe6662a32703d8f2b8e46dc
5
5
  SHA512:
6
- metadata.gz: 32fdb2bf2484781c0d704300eba6b7d60e15c3980f6468252c621f3884b8abee17a5da7283fd0197a1c76f84a3d033538d41f818f2f1ae356071a602a30a203b
7
- data.tar.gz: 72b5e70e3aec45b3670727fcff8439cb0ef520d2019f91c71c753b3dfb14e39648e3e3c66ed02429f3bb099465e61dc0568c4ef496745680b1b3d870c9b0a946
6
+ metadata.gz: a8e33edf86e3d9f52c62f046003d69b76f2d6268268c81c0dab3d094ea645e0f9deb6f5e44caa1c0a9a32c5a2d6ad4cbbba5d63f676cdabce17bf37207ec3d76
7
+ data.tar.gz: 4712b2d17b3f4955a3d2c43cbaaf4d3c04578539baead870f21f379845e7f3b4d811e1c5cfd72f08de3702f542067a27a66d265fc864305f9be23e783f2ba9b5
@@ -6,16 +6,19 @@ module Coradoc
6
6
  module Markdown
7
7
  # Sidebar block — a tangential aside, visually distinct from main flow.
8
8
  #
9
- # Markdown has no native sidebar. Serialized as an HTML fallback:
10
- # <div class="sidebar">...</div>
9
+ # Markdown has no native sidebar. Serialized as a VitePress `:::info`
10
+ # custom container. When the sidebar contains structured children
11
+ # (code blocks, lists, etc.), they are rendered into the container.
11
12
  class Sidebar < Base
12
13
  attribute :content, :string
13
14
  attribute :title, :string
15
+ attribute :children, Coradoc::Markdown::Base, collection: true, default: []
14
16
 
15
- def initialize(content:, title: nil, **rest)
17
+ def initialize(content:, title: nil, children: [], **rest)
16
18
  super
17
19
  @content = content
18
20
  @title = title
21
+ @children = Array(children)
19
22
  end
20
23
  end
21
24
  end
@@ -6,13 +6,18 @@ module Coradoc
6
6
  module Markdown
7
7
  class Serializer
8
8
  module Serializers
9
- # Literal block: indented code block (4 leading spaces per line).
10
- # Distinct from a code block (which carries a language hint).
9
+ # Literal block: preformatted text with no language hint. Uses an
10
+ # unlabeled fenced code block so the content survives VitePress's
11
+ # Vue template parser (4-space indented code blocks only work in
12
+ # specific contexts and leak `<` characters when not separated by
13
+ # blank lines).
11
14
  class Literal < ElementSerializer
12
15
  handles_type ::Coradoc::Markdown::Literal
13
16
 
14
17
  def call(element, _ctx)
15
- element.content.to_s.lines.map { |line| " #{line}" }.join
18
+ body = element.content.to_s
19
+ body = body.chomp + "\n" unless body.end_with?("\n")
20
+ "```\n#{body}```\n"
16
21
  end
17
22
  end
18
23
  end
@@ -6,12 +6,25 @@ module Coradoc
6
6
  module Markdown
7
7
  class Serializer
8
8
  module Serializers
9
+ # Sidebar block — a callout box. VitePress maps the `:::info`
10
+ # custom container to a styled callout, which matches AsciiDoc's
11
+ # sidebar semantics without leaking raw HTML into the Markdown.
9
12
  class Sidebar < ElementSerializer
10
13
  handles_type ::Coradoc::Markdown::Sidebar
11
14
 
12
- def call(element, _ctx)
13
- title_html = element.title ? %(<div class="title">#{element.title}</div>\n) : ''
14
- %(<div class="sidebar">\n#{title_html}#{element.content.to_s}\n</div>)
15
+ def call(element, ctx)
16
+ title = element.title.to_s
17
+ header = title.empty? ? '' : " #{title}"
18
+ body = render_body(element, ctx)
19
+ ":::info#{header}\n#{body}\n:::"
20
+ end
21
+
22
+ private
23
+
24
+ def render_body(element, ctx)
25
+ return element.content.to_s.chomp if element.children.nil? || element.children.empty?
26
+
27
+ element.children.map { |c| ctx.serialize(c) }.join("\n\n").chomp
15
28
  end
16
29
  end
17
30
  end
@@ -228,7 +228,11 @@ module Coradoc
228
228
  end
229
229
 
230
230
  def transform_literal_block(block)
231
- Coradoc::Markdown::Literal.new(content: block.content.to_s)
231
+ content = CoreModel::CalloutText.strip_markers(block.content.to_s, block.callouts)
232
+ literal = Coradoc::Markdown::Literal.new(content: content)
233
+ return literal if block.callouts.nil? || block.callouts.empty?
234
+
235
+ [literal, transform_callout_list(block.callouts)]
232
236
  end
233
237
 
234
238
  def transform_example_block(block)
@@ -241,9 +245,11 @@ module Coradoc
241
245
  end
242
246
 
243
247
  def transform_sidebar_block(block)
248
+ children = Array(block.children).map { |c| transform(c) }.flat_map { |c| flatten_result(c) }
244
249
  Coradoc::Markdown::Sidebar.new(
245
250
  content: block.flat_text,
246
- title: block.title.to_s
251
+ title: block.title.to_s,
252
+ children: children
247
253
  )
248
254
  end
249
255
 
@@ -350,13 +356,13 @@ module Coradoc
350
356
 
351
357
  # Check if first row is marked as header, or if any of its cells are header cells
352
358
  if first_row&.header || first_row_cells.any?(&:header)
353
- headers = first_row_cells.map(&:flat_text)
359
+ headers = first_row_cells.map { |cell| strip_cell_callouts(cell.flat_text) }
354
360
  table_rows = table_rows[1..] || []
355
361
  end
356
362
 
357
363
  # Convert remaining rows to pipe-separated strings
358
364
  rows = table_rows.map do |row|
359
- Array(row.cells).map(&:flat_text).join(' | ')
365
+ Array(row.cells).map { |cell| strip_cell_callouts(cell.flat_text) }.join(' | ')
360
366
  end
361
367
  end
362
368
 
@@ -366,6 +372,12 @@ module Coradoc
366
372
  )
367
373
  end
368
374
 
375
+ CALLOUT_MARKER_IN_CELL = /\s*<\d+>(?=\s|\z)/.freeze
376
+
377
+ def strip_cell_callouts(text)
378
+ text.to_s.gsub(CALLOUT_MARKER_IN_CELL, '')
379
+ end
380
+
369
381
  def transform_image(image)
370
382
  Coradoc::Markdown::Image.new(
371
383
  src: image.src,
@@ -37,6 +37,8 @@ module Coradoc
37
37
  text: element.content.to_s,
38
38
  target: element.target.to_s
39
39
  )
40
+ when 'raw_inline'
41
+ element.content.to_s
40
42
  else
41
43
  element.content.to_s
42
44
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Coradoc
4
4
  module Markdown
5
- VERSION = '1.0.6'
5
+ VERSION = '1.0.7'
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.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.