coradoc-markdown 1.0.9 → 1.0.10
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/admonition.rb +6 -7
- data/lib/coradoc/markdown/model/blockquote.rb +0 -5
- data/lib/coradoc/markdown/model/code_block.rb +0 -6
- data/lib/coradoc/markdown/model/comment.rb +1 -1
- data/lib/coradoc/markdown/model/definition_term.rb +0 -8
- data/lib/coradoc/markdown/model/example_block.rb +0 -7
- data/lib/coradoc/markdown/model/heading.rb +0 -6
- data/lib/coradoc/markdown/model/list_item.rb +1 -16
- data/lib/coradoc/markdown/model/literal.rb +0 -5
- data/lib/coradoc/markdown/model/open_block.rb +0 -5
- data/lib/coradoc/markdown/model/paragraph.rb +1 -14
- data/lib/coradoc/markdown/model/pass.rb +0 -5
- data/lib/coradoc/markdown/model/sidebar.rb +0 -7
- data/lib/coradoc/markdown/model/verse.rb +0 -7
- data/lib/coradoc/markdown/serializer/serializers/list.rb +1 -3
- data/lib/coradoc/markdown/serializer/strategies/definition_list/nested_html.rb +1 -1
- data/lib/coradoc/markdown/transform/from_core_model.rb +63 -12
- data/lib/coradoc/markdown/transform/list_transformer.rb +11 -5
- data/lib/coradoc/markdown/transform/structural_transformer.rb +1 -1
- data/lib/coradoc/markdown/transform/to_core_model.rb +3 -1
- 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: 45a195eaddedba173983f2ba2ab08ce81044fe089124b8287b4a643262dbc6f8
|
|
4
|
+
data.tar.gz: b163677948cdc8459692c411c2840f2bfa0cfe401e47453d61e88d156bbfc910
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3b6c63bf4e97c80a63c4f6289576f80577434d6aa8176aafd3067c026abbad4c9ab72fbe509e936933f60ef6cf02c7e3b6087efab353f541618ffe75d6c93ad1
|
|
7
|
+
data.tar.gz: 0a7a78dc0d92fd3c03344df7a6063429b443dcacfc760686a7d3080b6df7daff9b873251a1576d73307bbacfa8e642e08e02561625f6cfcd2d493f524843dd4b
|
|
@@ -27,14 +27,13 @@ module Coradoc
|
|
|
27
27
|
# Mixed inline content (strings and inline model objects) carried
|
|
28
28
|
# from the CoreModel children so serializers can preserve cross
|
|
29
29
|
# references, code spans, etc. When empty, fall back to `content`.
|
|
30
|
-
|
|
30
|
+
attribute :children, Coradoc::Markdown::Base, collection: true, default: []
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
@children = Array(children)
|
|
32
|
+
# Normalize type on assignment. Callers can pass "NOTE", "Note",
|
|
33
|
+
# or "note" — storage is always lowercase so downstream comparison
|
|
34
|
+
# and CSS class generation don't need to repeat the normalization.
|
|
35
|
+
def admonition_type=(value)
|
|
36
|
+
super(value.to_s.downcase)
|
|
38
37
|
end
|
|
39
38
|
end
|
|
40
39
|
end
|
|
@@ -24,14 +24,6 @@ module Coradoc
|
|
|
24
24
|
# When present, the flat-PHP-Markdown-Extra syntax is no longer
|
|
25
25
|
# sufficient and the serializer falls back to HTML <dl>/<dt>/<dd>.
|
|
26
26
|
attribute :nested, Coradoc::Markdown::DefinitionList
|
|
27
|
-
|
|
28
|
-
def initialize(text: '', definitions: [], nested: nil, text_children: [], **rest)
|
|
29
|
-
super
|
|
30
|
-
@text = text
|
|
31
|
-
@definitions = definitions
|
|
32
|
-
@nested = nested
|
|
33
|
-
@text_children = Array(text_children)
|
|
34
|
-
end
|
|
35
27
|
end
|
|
36
28
|
end
|
|
37
29
|
end
|
|
@@ -16,13 +16,6 @@ module Coradoc
|
|
|
16
16
|
attribute :content, :string
|
|
17
17
|
attribute :caption, :string
|
|
18
18
|
attribute :children, Coradoc::Markdown::Base, collection: true, default: []
|
|
19
|
-
|
|
20
|
-
def initialize(content:, caption: nil, children: [], **rest)
|
|
21
|
-
super
|
|
22
|
-
@content = content
|
|
23
|
-
@caption = caption
|
|
24
|
-
@children = Array(children)
|
|
25
|
-
end
|
|
26
19
|
end
|
|
27
20
|
end
|
|
28
21
|
end
|
|
@@ -11,12 +11,6 @@ module Coradoc
|
|
|
11
11
|
attribute :level, :integer, default: 1
|
|
12
12
|
attribute :text, :string
|
|
13
13
|
|
|
14
|
-
def initialize(level: 1, text: '')
|
|
15
|
-
super()
|
|
16
|
-
@level = level
|
|
17
|
-
@text = text
|
|
18
|
-
end
|
|
19
|
-
|
|
20
14
|
# Generate an auto ID from the heading text
|
|
21
15
|
#
|
|
22
16
|
# @return [String] A slugified version of the text suitable for use as an ID
|
|
@@ -8,22 +8,7 @@ module Coradoc
|
|
|
8
8
|
attribute :text, :string
|
|
9
9
|
attribute :checked, :boolean # For task lists (- [ ] or - [x])
|
|
10
10
|
attribute :sublist, Coradoc::Markdown::List # Nested list
|
|
11
|
-
|
|
12
|
-
# Mixed content (strings and inline model objects)
|
|
13
|
-
# @return [Array] mixed content array
|
|
14
|
-
attr_reader :children
|
|
15
|
-
|
|
16
|
-
def initialize(args = {})
|
|
17
|
-
super()
|
|
18
|
-
@text = args[:text] || ''
|
|
19
|
-
@checked = args[:checked]
|
|
20
|
-
@sublist = args[:sublist]
|
|
21
|
-
@children = args.fetch(:children, [])
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def children=(value)
|
|
25
|
-
@children = value || []
|
|
26
|
-
end
|
|
11
|
+
attribute :children, Coradoc::Markdown::Base, collection: true, default: []
|
|
27
12
|
end
|
|
28
13
|
end
|
|
29
14
|
end
|
|
@@ -12,11 +12,6 @@ module Coradoc
|
|
|
12
12
|
# - With id/classes → emit `<div id="...">...</div>` wrapper
|
|
13
13
|
class OpenBlock < Base
|
|
14
14
|
attribute :children, Coradoc::Markdown::Base, collection: true, default: []
|
|
15
|
-
|
|
16
|
-
def initialize(children: [], **rest)
|
|
17
|
-
super
|
|
18
|
-
@children = Array(children)
|
|
19
|
-
end
|
|
20
15
|
end
|
|
21
16
|
end
|
|
22
17
|
end
|
|
@@ -9,20 +9,7 @@ module Coradoc
|
|
|
9
9
|
#
|
|
10
10
|
class Paragraph < Base
|
|
11
11
|
attribute :text, :string
|
|
12
|
-
|
|
13
|
-
# Mixed content (strings and inline model objects)
|
|
14
|
-
# @return [Array] mixed content array
|
|
15
|
-
attr_reader :children
|
|
16
|
-
|
|
17
|
-
def initialize(text: '', children: [])
|
|
18
|
-
super()
|
|
19
|
-
@text = text
|
|
20
|
-
@children = children
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def children=(value)
|
|
24
|
-
@children = value || []
|
|
25
|
-
end
|
|
12
|
+
attribute :children, Base, collection: true, default: []
|
|
26
13
|
end
|
|
27
14
|
end
|
|
28
15
|
end
|
|
@@ -13,13 +13,6 @@ module Coradoc
|
|
|
13
13
|
attribute :content, :string
|
|
14
14
|
attribute :title, :string
|
|
15
15
|
attribute :children, Coradoc::Markdown::Base, collection: true, default: []
|
|
16
|
-
|
|
17
|
-
def initialize(content:, title: nil, children: [], **rest)
|
|
18
|
-
super
|
|
19
|
-
@content = content
|
|
20
|
-
@title = title
|
|
21
|
-
@children = Array(children)
|
|
22
|
-
end
|
|
23
16
|
end
|
|
24
17
|
end
|
|
25
18
|
end
|
|
@@ -15,13 +15,6 @@ module Coradoc
|
|
|
15
15
|
attribute :content, :string
|
|
16
16
|
attribute :attribution, :string
|
|
17
17
|
attribute :citetitle, :string
|
|
18
|
-
|
|
19
|
-
def initialize(content:, attribution: nil, citetitle: nil, **rest)
|
|
20
|
-
super
|
|
21
|
-
@content = content
|
|
22
|
-
@attribution = attribution
|
|
23
|
-
@citetitle = citetitle
|
|
24
|
-
end
|
|
25
18
|
end
|
|
26
19
|
end
|
|
27
20
|
end
|
|
@@ -13,9 +13,7 @@ module Coradoc
|
|
|
13
13
|
marker = element.ordered ? '1.' : '-'
|
|
14
14
|
element.items.flat_map do |item|
|
|
15
15
|
lines = [render_item(item, marker, _ctx)]
|
|
16
|
-
if item.sublist
|
|
17
|
-
lines += call(item.sublist, _ctx).split("\n").map { |l| " #{l}" }
|
|
18
|
-
end
|
|
16
|
+
lines += call(item.sublist, _ctx).split("\n").map { |l| " #{l}" } if item.sublist
|
|
19
17
|
lines
|
|
20
18
|
end.join("\n")
|
|
21
19
|
end
|
|
@@ -35,7 +35,7 @@ module Coradoc
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def render_term(term)
|
|
38
|
-
dt = "<dt>#{term.text
|
|
38
|
+
dt = "<dt>#{term.text}</dt>"
|
|
39
39
|
dds = term.definitions.map { |d| render_dd(d) }.join
|
|
40
40
|
nested = term.nested ? "\n #{render_dl(term.nested)}" : ''
|
|
41
41
|
"#{dt}\n#{dds}#{nested unless nested.empty?}"
|
|
@@ -219,7 +219,7 @@ module Coradoc
|
|
|
219
219
|
def transform_verse_block(block)
|
|
220
220
|
Coradoc::Markdown::Verse.new(
|
|
221
221
|
content: block.flat_text,
|
|
222
|
-
attribution: block.
|
|
222
|
+
attribution: block.is_a?(Coradoc::CoreModel::VerseBlock) ? block.attribution : nil
|
|
223
223
|
)
|
|
224
224
|
end
|
|
225
225
|
|
|
@@ -272,10 +272,17 @@ module Coradoc
|
|
|
272
272
|
|
|
273
273
|
def transform_admonition_block(block, default_type: 'note')
|
|
274
274
|
children = transform_inline_array(block.renderable_content)
|
|
275
|
+
if block.is_a?(Coradoc::CoreModel::AnnotationBlock)
|
|
276
|
+
adm_type = block.annotation_type || default_type
|
|
277
|
+
adm_label = block.annotation_label
|
|
278
|
+
else
|
|
279
|
+
adm_type = default_type
|
|
280
|
+
adm_label = nil
|
|
281
|
+
end
|
|
275
282
|
Coradoc::Markdown::Admonition.new(
|
|
276
|
-
admonition_type:
|
|
283
|
+
admonition_type: adm_type,
|
|
277
284
|
content: block.flat_text,
|
|
278
|
-
title:
|
|
285
|
+
title: adm_label,
|
|
279
286
|
children: children
|
|
280
287
|
)
|
|
281
288
|
end
|
|
@@ -374,7 +381,7 @@ module Coradoc
|
|
|
374
381
|
)
|
|
375
382
|
end
|
|
376
383
|
|
|
377
|
-
CALLOUT_MARKER_IN_CELL = /\s*<\d+>(?=\s|\z)
|
|
384
|
+
CALLOUT_MARKER_IN_CELL = /\s*<\d+>(?=\s|\z)/
|
|
378
385
|
|
|
379
386
|
def strip_cell_callouts(text)
|
|
380
387
|
text.to_s.gsub(CALLOUT_MARKER_IN_CELL, '')
|
|
@@ -428,21 +435,52 @@ module Coradoc
|
|
|
428
435
|
end
|
|
429
436
|
|
|
430
437
|
def transform_definition_list(dl)
|
|
431
|
-
|
|
432
|
-
|
|
438
|
+
# flat_map because each CoreModel DefinitionItem may emit
|
|
439
|
+
# multiple Markdown DefinitionTerms (multi-term `<dt>`).
|
|
440
|
+
items = Array(dl.items).flat_map do |item|
|
|
441
|
+
definitions = [build_definition_item(item)]
|
|
442
|
+
# `+`-continuation blocks attached to the dd become
|
|
443
|
+
# additional definitions in Markdown (each renders as
|
|
444
|
+
# `: line` in the Flat serializer). One DefinitionItem
|
|
445
|
+
# per attached block, preserving their distinct content
|
|
446
|
+
# without jamming them into the primary definition's text.
|
|
447
|
+
definitions.concat(Array(item.attached_children).map { |b| build_attached_definition_item(b) })
|
|
433
448
|
nested = item.nested ? transform_definition_list(item.nested) : nil
|
|
434
449
|
term_children = Array(item.term_children).map { |c| transform_inline_content(c) }
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
)
|
|
450
|
+
# Multi-term `<dt>`: emit one Markdown DefinitionTerm per
|
|
451
|
+
# term string. Inline children map 1:1 to the FIRST term
|
|
452
|
+
# (matches the mirror handler's behaviour; multi-term
|
|
453
|
+
# with inline markup on later terms is rare and the
|
|
454
|
+
# parser doesn't capture per-term children today).
|
|
455
|
+
terms = terms_for(item)
|
|
456
|
+
if terms.empty?
|
|
457
|
+
# Defensive: term and terms both empty — emit nothing.
|
|
458
|
+
next
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
terms.each_with_index.map do |term_text, idx|
|
|
462
|
+
Coradoc::Markdown::DefinitionTerm.new(
|
|
463
|
+
text: term_text.to_s,
|
|
464
|
+
text_children: idx.zero? ? term_children : [],
|
|
465
|
+
definitions: definitions,
|
|
466
|
+
nested: nested
|
|
467
|
+
)
|
|
468
|
+
end
|
|
441
469
|
end
|
|
442
470
|
|
|
443
471
|
Coradoc::Markdown::DefinitionList.new(items: items)
|
|
444
472
|
end
|
|
445
473
|
|
|
474
|
+
# Source of truth for "the terms on this <dt>": the `terms`
|
|
475
|
+
# collection when populated, else `[term]` for legacy callers.
|
|
476
|
+
def terms_for(item)
|
|
477
|
+
collection = item.terms if item.is_a?(Coradoc::CoreModel::DefinitionItem)
|
|
478
|
+
return Array(collection) unless collection.nil? || collection.empty?
|
|
479
|
+
|
|
480
|
+
primary = item.term
|
|
481
|
+
primary.to_s.empty? ? [] : [primary.to_s]
|
|
482
|
+
end
|
|
483
|
+
|
|
446
484
|
def build_definition_item(item)
|
|
447
485
|
children = Array(item.definition_children)
|
|
448
486
|
if children.empty?
|
|
@@ -457,6 +495,19 @@ module Coradoc
|
|
|
457
495
|
)
|
|
458
496
|
end
|
|
459
497
|
|
|
498
|
+
# Build a DefinitionItem from a single attached block (e.g.
|
|
499
|
+
# paragraph from a `+`-continuation). Flat-text extraction
|
|
500
|
+
# via ChildrenContent is the single source of truth — every
|
|
501
|
+
# attached block in CoreModel includes ChildrenContent.
|
|
502
|
+
def build_attached_definition_item(block)
|
|
503
|
+
content = if block.is_a?(Coradoc::CoreModel::ChildrenContent)
|
|
504
|
+
block.flat_text
|
|
505
|
+
else
|
|
506
|
+
block.to_s
|
|
507
|
+
end
|
|
508
|
+
Coradoc::Markdown::DefinitionItem.new(content: content)
|
|
509
|
+
end
|
|
510
|
+
|
|
460
511
|
def transform_footnote(fn)
|
|
461
512
|
Coradoc::Markdown::Footnote.new(
|
|
462
513
|
id: fn.id.to_s,
|
|
@@ -30,14 +30,20 @@ module Coradoc
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def transform_definition_list(dl)
|
|
33
|
-
|
|
33
|
+
# flat_map because multi-term `<dt>`'s emit multiple
|
|
34
|
+
# DefinitionTerms per CoreModel DefinitionItem.
|
|
35
|
+
items = Array(dl.items).flat_map do |item|
|
|
34
36
|
definitions = Array(item.definitions).map do |defn|
|
|
35
37
|
Coradoc::Markdown::DefinitionItem.new(content: defn.to_s)
|
|
36
38
|
end
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
terms = item.terms
|
|
40
|
+
term_strings = terms.nil? || terms.empty? ? [item.term.to_s] : terms.map(&:to_s)
|
|
41
|
+
term_strings.map do |term_text|
|
|
42
|
+
Coradoc::Markdown::DefinitionTerm.new(
|
|
43
|
+
text: term_text,
|
|
44
|
+
definitions: definitions
|
|
45
|
+
)
|
|
46
|
+
end
|
|
41
47
|
end
|
|
42
48
|
|
|
43
49
|
Coradoc::Markdown::DefinitionList.new(items: items)
|
|
@@ -80,7 +80,7 @@ module Coradoc
|
|
|
80
80
|
def transform_bibliography_entry(entry)
|
|
81
81
|
FromCoreModel.transform_bibliography_entry(entry)
|
|
82
82
|
end
|
|
83
|
-
end
|
|
83
|
+
end
|
|
84
84
|
|
|
85
85
|
# Register with FromCoreModel
|
|
86
86
|
FromCoreModel.register(CoreModel::StructuralElement, method(:transform_structural_element))
|
|
@@ -165,7 +165,9 @@ module Coradoc
|
|
|
165
165
|
cells = if row.is_a?(Array)
|
|
166
166
|
row.map { |c| Coradoc::CoreModel::TableCell.new(content: c.to_s, header: false) }
|
|
167
167
|
else
|
|
168
|
-
row.to_s.split(' | ').map
|
|
168
|
+
row.to_s.split(' | ').map do |c|
|
|
169
|
+
Coradoc::CoreModel::TableCell.new(content: c.to_s, header: false)
|
|
170
|
+
end
|
|
169
171
|
end
|
|
170
172
|
rows << Coradoc::CoreModel::TableRow.new(cells: cells)
|
|
171
173
|
end
|