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 +4 -4
- data/lib/coradoc/markdown/model/sidebar.rb +6 -3
- data/lib/coradoc/markdown/serializer/serializers/literal.rb +8 -3
- data/lib/coradoc/markdown/serializer/serializers/sidebar.rb +16 -3
- data/lib/coradoc/markdown/transform/from_core_model.rb +16 -4
- data/lib/coradoc/markdown/transform/inline_transformer.rb +2 -0
- 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: 87855aadbdb24171b83ced3a1f973439655bbd3b9bd676b378449df3de68bbd2
|
|
4
|
+
data.tar.gz: 7ade791de29328f8d9994490d2789d5281995cf18fe6662a32703d8f2b8e46dc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
10
|
-
#
|
|
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:
|
|
10
|
-
#
|
|
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
|
|
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,
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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,
|