coradoc-markdown 1.0.5 → 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/definition_item.rb +4 -2
- data/lib/coradoc/markdown/model/definition_term.rb +7 -1
- 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/serializer/strategies/definition_list/flat.rb +19 -3
- data/lib/coradoc/markdown/transform/from_core_model.rb +34 -8
- 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
|
|
@@ -14,8 +14,10 @@ module Coradoc
|
|
|
14
14
|
# The definition content (text or nested blocks)
|
|
15
15
|
attribute :content, :string
|
|
16
16
|
|
|
17
|
-
# Inline content
|
|
18
|
-
|
|
17
|
+
# Inline content as typed Markdown elements (Code, Strong, Text, etc.).
|
|
18
|
+
# When present, the Flat serializer renders these via
|
|
19
|
+
# `ctx.serialize_inline_join` so inline formatting is preserved.
|
|
20
|
+
attribute :inline_content, Coradoc::Markdown::Base, collection: true, default: []
|
|
19
21
|
|
|
20
22
|
# Nested block content (paragraphs, code blocks, lists, etc.)
|
|
21
23
|
attribute :blocks, :string, collection: true
|
|
@@ -15,16 +15,22 @@ module Coradoc
|
|
|
15
15
|
attribute :text, :string
|
|
16
16
|
attribute :definitions, Coradoc::Markdown::DefinitionItem, collection: true, default: []
|
|
17
17
|
|
|
18
|
+
# Typed inline children for the term (Code, Strong, Text, etc.).
|
|
19
|
+
# When present, the Flat serializer renders these via
|
|
20
|
+
# `ctx.serialize_inline_join` so inline formatting is preserved.
|
|
21
|
+
attribute :text_children, Coradoc::Markdown::Base, collection: true, default: []
|
|
22
|
+
|
|
18
23
|
# Optional nested definition list under this term.
|
|
19
24
|
# When present, the flat-PHP-Markdown-Extra syntax is no longer
|
|
20
25
|
# sufficient and the serializer falls back to HTML <dl>/<dt>/<dd>.
|
|
21
26
|
attribute :nested, Coradoc::Markdown::DefinitionList
|
|
22
27
|
|
|
23
|
-
def initialize(text: '', definitions: [], nested: nil, **rest)
|
|
28
|
+
def initialize(text: '', definitions: [], nested: nil, text_children: [], **rest)
|
|
24
29
|
super
|
|
25
30
|
@text = text
|
|
26
31
|
@definitions = definitions
|
|
27
32
|
@nested = nested
|
|
33
|
+
@text_children = Array(text_children)
|
|
28
34
|
end
|
|
29
35
|
end
|
|
30
36
|
end
|
|
@@ -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
|
|
@@ -24,11 +24,11 @@ module Coradoc
|
|
|
24
24
|
list.items.none? { |term| term.nested }
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
def render(list,
|
|
27
|
+
def render(list, ctx)
|
|
28
28
|
list.items.map do |term|
|
|
29
|
-
lines = [term
|
|
29
|
+
lines = [render_term(term, ctx)]
|
|
30
30
|
term.definitions.each do |defn|
|
|
31
|
-
content_str = defn
|
|
31
|
+
content_str = render_definition(defn, ctx)
|
|
32
32
|
content_str.lines.each_with_index do |line, i|
|
|
33
33
|
stripped = line.rstrip
|
|
34
34
|
next if i.positive? && stripped.empty?
|
|
@@ -39,6 +39,22 @@ module Coradoc
|
|
|
39
39
|
lines.join("\n")
|
|
40
40
|
end.join("\n\n")
|
|
41
41
|
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def render_term(term, ctx)
|
|
46
|
+
children = term.text_children
|
|
47
|
+
return term.text.to_s if children.nil? || children.empty?
|
|
48
|
+
|
|
49
|
+
ctx.serialize_inline_join(children)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def render_definition(defn, ctx)
|
|
53
|
+
children = defn.inline_content
|
|
54
|
+
return defn.content.to_s if children.nil? || children.empty?
|
|
55
|
+
|
|
56
|
+
ctx.serialize_inline_join(children)
|
|
57
|
+
end
|
|
42
58
|
end
|
|
43
59
|
end
|
|
44
60
|
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,
|
|
@@ -412,13 +424,13 @@ module Coradoc
|
|
|
412
424
|
|
|
413
425
|
def transform_definition_list(dl)
|
|
414
426
|
items = Array(dl.items).map do |item|
|
|
415
|
-
|
|
416
|
-
Coradoc::Markdown::DefinitionItem.new(content: defn.to_s)
|
|
417
|
-
end
|
|
427
|
+
definition = build_definition_item(item)
|
|
418
428
|
nested = item.nested ? transform_definition_list(item.nested) : nil
|
|
429
|
+
term_children = Array(item.term_children).map { |c| transform_inline_content(c) }
|
|
419
430
|
Coradoc::Markdown::DefinitionTerm.new(
|
|
420
431
|
text: item.term.to_s,
|
|
421
|
-
|
|
432
|
+
text_children: term_children,
|
|
433
|
+
definitions: [definition],
|
|
422
434
|
nested: nested
|
|
423
435
|
)
|
|
424
436
|
end
|
|
@@ -426,6 +438,20 @@ module Coradoc
|
|
|
426
438
|
Coradoc::Markdown::DefinitionList.new(items: items)
|
|
427
439
|
end
|
|
428
440
|
|
|
441
|
+
def build_definition_item(item)
|
|
442
|
+
children = Array(item.definition_children)
|
|
443
|
+
if children.empty?
|
|
444
|
+
content = item.definitions&.first&.to_s
|
|
445
|
+
return Coradoc::Markdown::DefinitionItem.new(content: content)
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
inline = children.map { |c| transform_inline_content(c) }
|
|
449
|
+
Coradoc::Markdown::DefinitionItem.new(
|
|
450
|
+
content: item.definitions&.first&.to_s,
|
|
451
|
+
inline_content: inline
|
|
452
|
+
)
|
|
453
|
+
end
|
|
454
|
+
|
|
429
455
|
def transform_footnote(fn)
|
|
430
456
|
Coradoc::Markdown::Footnote.new(
|
|
431
457
|
id: fn.id.to_s,
|