coradoc-markdown 1.0.6 → 1.0.8

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: d207c747b020fc24b596609a937ae0a4b756295f3e834d925c0ff4af6b403e8f
4
+ data.tar.gz: b1a62c3d3f4df78ef3a0d177cfdf5432f1fe28a1cf24c6716f1da74c00d4122a
5
5
  SHA512:
6
- metadata.gz: 32fdb2bf2484781c0d704300eba6b7d60e15c3980f6468252c621f3884b8abee17a5da7283fd0197a1c76f84a3d033538d41f818f2f1ae356071a602a30a203b
7
- data.tar.gz: 72b5e70e3aec45b3670727fcff8439cb0ef520d2019f91c71c753b3dfb14e39648e3e3c66ed02429f3bb099465e61dc0568c4ef496745680b1b3d870c9b0a946
6
+ metadata.gz: 6842c914db9bfa787cc93e9f4b197e010bd303fc7da0687b49e5d8b025dae06c6376a12f8b6f98fd76617b1224db22766883a18a5fd423d7829e690f45337b3f
7
+ data.tar.gz: 16c27e25254e057943c8505b6ef493dd48aa5280d8d9581ccf8aa106e06fa1524522a86ba56ed31be5e90c9e5adf3b497eed30cad47665d2871f99e8769e30e3
@@ -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,13 +6,22 @@ module Coradoc
6
6
  module Markdown
7
7
  class Serializer
8
8
  module Serializers
9
- # Pass block: emit content inside kramdown's nomarkdown extension
10
- # so it bypasses Markdown rendering.
9
+ # Pass block. AsciiDoc pass content is raw and bypasses all
10
+ # substitutions. Markdown has no equivalent — kramdown's
11
+ # `{::nomarkdown}` extension is not supported by VitePress /
12
+ # markdown-it, so emitting it leaks raw HTML that breaks Vue's
13
+ # template compiler.
14
+ #
15
+ # Emit as an HTML comment so the content is preserved (for
16
+ # debugging or downstream tooling) but never rendered as HTML.
11
17
  class Pass < ElementSerializer
12
18
  handles_type ::Coradoc::Markdown::Pass
13
19
 
14
20
  def call(element, _ctx)
15
- "{::nomarkdown}#{element.content.to_s}{:/}"
21
+ content = element.content.to_s
22
+ stripped = content.gsub(/\A\n+|\n+\z/, '')
23
+ comment_body = stripped.empty? ? '' : " #{stripped} "
24
+ "<!--#{comment_body}-->"
16
25
  end
17
26
  end
18
27
  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
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'cgi'
4
+
3
5
  module Coradoc
4
6
  module Markdown
5
7
  module Transform
@@ -228,7 +230,11 @@ module Coradoc
228
230
  end
229
231
 
230
232
  def transform_literal_block(block)
231
- Coradoc::Markdown::Literal.new(content: block.content.to_s)
233
+ content = CoreModel::CalloutText.strip_markers(block.content.to_s, block.callouts)
234
+ literal = Coradoc::Markdown::Literal.new(content: content)
235
+ return literal if block.callouts.nil? || block.callouts.empty?
236
+
237
+ [literal, transform_callout_list(block.callouts)]
232
238
  end
233
239
 
234
240
  def transform_example_block(block)
@@ -241,9 +247,11 @@ module Coradoc
241
247
  end
242
248
 
243
249
  def transform_sidebar_block(block)
250
+ children = Array(block.children).map { |c| transform(c) }.flat_map { |c| flatten_result(c) }
244
251
  Coradoc::Markdown::Sidebar.new(
245
252
  content: block.flat_text,
246
- title: block.title.to_s
253
+ title: block.title.to_s,
254
+ children: children
247
255
  )
248
256
  end
249
257
 
@@ -350,13 +358,13 @@ module Coradoc
350
358
 
351
359
  # Check if first row is marked as header, or if any of its cells are header cells
352
360
  if first_row&.header || first_row_cells.any?(&:header)
353
- headers = first_row_cells.map(&:flat_text)
361
+ headers = first_row_cells.map { |cell| strip_cell_callouts(cell.flat_text) }
354
362
  table_rows = table_rows[1..] || []
355
363
  end
356
364
 
357
365
  # Convert remaining rows to pipe-separated strings
358
366
  rows = table_rows.map do |row|
359
- Array(row.cells).map(&:flat_text).join(' | ')
367
+ Array(row.cells).map { |cell| strip_cell_callouts(cell.flat_text) }.join(' | ')
360
368
  end
361
369
  end
362
370
 
@@ -366,6 +374,12 @@ module Coradoc
366
374
  )
367
375
  end
368
376
 
377
+ CALLOUT_MARKER_IN_CELL = /\s*<\d+>(?=\s|\z)/.freeze
378
+
379
+ def strip_cell_callouts(text)
380
+ text.to_s.gsub(CALLOUT_MARKER_IN_CELL, '')
381
+ end
382
+
369
383
  def transform_image(image)
370
384
  Coradoc::Markdown::Image.new(
371
385
  src: image.src,
@@ -405,6 +419,8 @@ module Coradoc
405
419
  text: element.content.to_s,
406
420
  target: element.target.to_s
407
421
  )
422
+ when 'raw_inline'
423
+ CGI.escapeHTML(element.content.to_s)
408
424
  else
409
425
  element.content.to_s
410
426
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'cgi'
4
+
3
5
  module Coradoc
4
6
  module Markdown
5
7
  module Transform
@@ -37,6 +39,8 @@ module Coradoc
37
39
  text: element.content.to_s,
38
40
  target: element.target.to_s
39
41
  )
42
+ when 'raw_inline'
43
+ CGI.escapeHTML(element.content.to_s)
40
44
  else
41
45
  element.content.to_s
42
46
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Coradoc
4
4
  module Markdown
5
- VERSION = '1.0.6'
5
+ VERSION = '1.0.8'
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.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.