coradoc-markdown 1.0.5 → 1.0.6
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/serializer/strategies/definition_list/flat.rb +19 -3
- data/lib/coradoc/markdown/transform/from_core_model.rb +18 -4
- 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: bdce5853004d12a0dde16c5e512cdb8ce689babaa65b64ec2b64c6dd69b0b245
|
|
4
|
+
data.tar.gz: 27c0c58e7ca3b4ed423fc072730442915be12d435f5eb09e58181e15824ba45f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 32fdb2bf2484781c0d704300eba6b7d60e15c3980f6468252c621f3884b8abee17a5da7283fd0197a1c76f84a3d033538d41f818f2f1ae356071a602a30a203b
|
|
7
|
+
data.tar.gz: 72b5e70e3aec45b3670727fcff8439cb0ef520d2019f91c71c753b3dfb14e39648e3e3c66ed02429f3bb099465e61dc0568c4ef496745680b1b3d870c9b0a946
|
|
@@ -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
|
|
@@ -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
|
|
@@ -412,13 +412,13 @@ module Coradoc
|
|
|
412
412
|
|
|
413
413
|
def transform_definition_list(dl)
|
|
414
414
|
items = Array(dl.items).map do |item|
|
|
415
|
-
|
|
416
|
-
Coradoc::Markdown::DefinitionItem.new(content: defn.to_s)
|
|
417
|
-
end
|
|
415
|
+
definition = build_definition_item(item)
|
|
418
416
|
nested = item.nested ? transform_definition_list(item.nested) : nil
|
|
417
|
+
term_children = Array(item.term_children).map { |c| transform_inline_content(c) }
|
|
419
418
|
Coradoc::Markdown::DefinitionTerm.new(
|
|
420
419
|
text: item.term.to_s,
|
|
421
|
-
|
|
420
|
+
text_children: term_children,
|
|
421
|
+
definitions: [definition],
|
|
422
422
|
nested: nested
|
|
423
423
|
)
|
|
424
424
|
end
|
|
@@ -426,6 +426,20 @@ module Coradoc
|
|
|
426
426
|
Coradoc::Markdown::DefinitionList.new(items: items)
|
|
427
427
|
end
|
|
428
428
|
|
|
429
|
+
def build_definition_item(item)
|
|
430
|
+
children = Array(item.definition_children)
|
|
431
|
+
if children.empty?
|
|
432
|
+
content = item.definitions&.first&.to_s
|
|
433
|
+
return Coradoc::Markdown::DefinitionItem.new(content: content)
|
|
434
|
+
end
|
|
435
|
+
|
|
436
|
+
inline = children.map { |c| transform_inline_content(c) }
|
|
437
|
+
Coradoc::Markdown::DefinitionItem.new(
|
|
438
|
+
content: item.definitions&.first&.to_s,
|
|
439
|
+
inline_content: inline
|
|
440
|
+
)
|
|
441
|
+
end
|
|
442
|
+
|
|
429
443
|
def transform_footnote(fn)
|
|
430
444
|
Coradoc::Markdown::Footnote.new(
|
|
431
445
|
id: fn.id.to_s,
|