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 +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/pass.rb +12 -3
- data/lib/coradoc/markdown/serializer/serializers/sidebar.rb +16 -3
- data/lib/coradoc/markdown/transform/from_core_model.rb +20 -4
- data/lib/coradoc/markdown/transform/inline_transformer.rb +4 -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: d207c747b020fc24b596609a937ae0a4b756295f3e834d925c0ff4af6b403e8f
|
|
4
|
+
data.tar.gz: b1a62c3d3f4df78ef3a0d177cfdf5432f1fe28a1cf24c6716f1da74c00d4122a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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,13 +6,22 @@ module Coradoc
|
|
|
6
6
|
module Markdown
|
|
7
7
|
class Serializer
|
|
8
8
|
module Serializers
|
|
9
|
-
# Pass block
|
|
10
|
-
#
|
|
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
|
-
|
|
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,
|
|
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
|
|
@@ -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
|
-
|
|
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(
|
|
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(
|
|
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
|