coradoc-mirror 0.1.3 → 0.1.4
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 000b9fd36ba19db9a57b3ad656292b1629eb82a12e7004add2e97b7823060e19
|
|
4
|
+
data.tar.gz: f5364e581508705701aac01de53a2d03371213a4224356d4343f197aa37edab0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8bcd0570c09daf184700080579a5cb17c54a2cccc16d8afb95b3f0598d644d5f5b14790c81024fafdb8306720170ae1e9ddeda893f111446e854b03effcb6826
|
|
7
|
+
data.tar.gz: f40e562805ca5466db7847773f7386c8709471c8aa4acbfbc4971db7e8255ede4b32e54b42cec361fa517cd31b1fbed1f283e6c01c3efadcf29ea1b33e75112f
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Coradoc
|
|
4
|
+
module Mirror
|
|
5
|
+
module Handlers
|
|
6
|
+
# Include directive handler.
|
|
7
|
+
#
|
|
8
|
+
# Emits a ProseMirror-compatible +include+ node carrying the
|
|
9
|
+
# target path and parsed options as typed attrs. Graph-mode
|
|
10
|
+
# preservation: the node survives serialization and round-trips
|
|
11
|
+
# back to a +CoreModel::Include+ via the reverse builder.
|
|
12
|
+
module Include
|
|
13
|
+
def self.call(element, context:)
|
|
14
|
+
Node::Include.new(attrs: build_attrs(element))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class << self
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def build_attrs(element)
|
|
21
|
+
options = element.options
|
|
22
|
+
Node::Include::Attrs.new(
|
|
23
|
+
target: element.target,
|
|
24
|
+
tags: tags_value(options),
|
|
25
|
+
lines: options&.lines_spec,
|
|
26
|
+
leveloffset: leveloffset_value(options),
|
|
27
|
+
indent: options&.indent,
|
|
28
|
+
file_encoding: options&.file_encoding,
|
|
29
|
+
raw_options: element.raw_options
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def tags_value(options)
|
|
34
|
+
return [] unless options
|
|
35
|
+
|
|
36
|
+
options.tags
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def leveloffset_value(options)
|
|
40
|
+
return nil unless options&.leveloffset
|
|
41
|
+
|
|
42
|
+
options.leveloffset.to_s
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
data/lib/coradoc/mirror/node.rb
CHANGED
|
@@ -512,6 +512,40 @@ module Coradoc
|
|
|
512
512
|
end
|
|
513
513
|
end
|
|
514
514
|
|
|
515
|
+
# Include directive node — a text-graph edge pointing at another file.
|
|
516
|
+
# Graph mode emits this; flat mode (ResolveIncludes) replaces it with
|
|
517
|
+
# the included subtree before serialization.
|
|
518
|
+
class Include < Node
|
|
519
|
+
PM_TYPE = 'include'
|
|
520
|
+
|
|
521
|
+
class Attrs < Lutaml::Model::Serializable
|
|
522
|
+
attribute :target, :string
|
|
523
|
+
attribute :tags, :string, collection: true
|
|
524
|
+
attribute :lines, :string
|
|
525
|
+
attribute :leveloffset, :string
|
|
526
|
+
attribute :indent, :integer
|
|
527
|
+
attribute :file_encoding, :string
|
|
528
|
+
attribute :raw_options, :string
|
|
529
|
+
|
|
530
|
+
key_value do
|
|
531
|
+
map 'target', to: :target
|
|
532
|
+
map 'tags', to: :tags
|
|
533
|
+
map 'lines', to: :lines
|
|
534
|
+
map 'leveloffset', to: :leveloffset
|
|
535
|
+
map 'indent', to: :indent
|
|
536
|
+
map 'encoding', to: :file_encoding
|
|
537
|
+
map 'raw_options', to: :raw_options
|
|
538
|
+
end
|
|
539
|
+
end
|
|
540
|
+
|
|
541
|
+
attribute :attrs, Attrs
|
|
542
|
+
|
|
543
|
+
key_value do
|
|
544
|
+
map 'type', to: :type, render_default: true
|
|
545
|
+
map 'attrs', to: :attrs
|
|
546
|
+
end
|
|
547
|
+
end
|
|
548
|
+
|
|
515
549
|
# ── Tables ──
|
|
516
550
|
|
|
517
551
|
class Table < Node
|
|
@@ -386,6 +386,43 @@ module Coradoc
|
|
|
386
386
|
end
|
|
387
387
|
end
|
|
388
388
|
|
|
389
|
+
# Include directive: round-trips back to a CoreModel::Include link
|
|
390
|
+
# node. The text graph is preserved through mirror_json → core.
|
|
391
|
+
class Include < Base
|
|
392
|
+
registers 'include'
|
|
393
|
+
|
|
394
|
+
def build(node)
|
|
395
|
+
attrs = node.attrs
|
|
396
|
+
CoreModel::Include.new(
|
|
397
|
+
target: attrs&.target,
|
|
398
|
+
options: build_options(attrs),
|
|
399
|
+
raw_options: attrs&.raw_options || ''
|
|
400
|
+
)
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
private
|
|
404
|
+
|
|
405
|
+
def build_options(attrs)
|
|
406
|
+
return CoreModel::IncludeOptions.new unless attrs
|
|
407
|
+
|
|
408
|
+
CoreModel::IncludeOptions.new(
|
|
409
|
+
tags: Array(attrs.tags),
|
|
410
|
+
tags_wildcard: attrs.tags == ['*'],
|
|
411
|
+
tags_inverted: attrs.tags == ['**'],
|
|
412
|
+
lines_spec: attrs.lines,
|
|
413
|
+
leveloffset: parse_leveloffset(attrs.leveloffset),
|
|
414
|
+
indent: attrs.indent,
|
|
415
|
+
file_encoding: attrs.file_encoding
|
|
416
|
+
)
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
def parse_leveloffset(raw)
|
|
420
|
+
return nil if raw.nil? || raw.to_s.empty?
|
|
421
|
+
|
|
422
|
+
Coradoc::CoreModel::IncludeLevelOffset.parse(raw.to_s)
|
|
423
|
+
end
|
|
424
|
+
end
|
|
425
|
+
|
|
389
426
|
# ── Tables ──
|
|
390
427
|
|
|
391
428
|
class Table < Base
|
data/lib/coradoc/mirror.rb
CHANGED
|
@@ -111,6 +111,9 @@ module Coradoc
|
|
|
111
111
|
# ── Frontmatter ──
|
|
112
112
|
registry.register(CoreModel::FrontmatterBlock, Handlers::Frontmatter)
|
|
113
113
|
|
|
114
|
+
# ── Include directive (text-graph edge) ──
|
|
115
|
+
registry.register(CoreModel::Include, Handlers::Include)
|
|
116
|
+
|
|
114
117
|
# ── Generic Block (catch-all for unrecognized block types) ──
|
|
115
118
|
registry.register(CoreModel::Block, Handlers::GenericBlock)
|
|
116
119
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: coradoc-mirror
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -93,6 +93,7 @@ files:
|
|
|
93
93
|
- lib/coradoc/mirror/handlers/generic_block.rb
|
|
94
94
|
- lib/coradoc/mirror/handlers/horizontal_rule.rb
|
|
95
95
|
- lib/coradoc/mirror/handlers/image.rb
|
|
96
|
+
- lib/coradoc/mirror/handlers/include.rb
|
|
96
97
|
- lib/coradoc/mirror/handlers/inline.rb
|
|
97
98
|
- lib/coradoc/mirror/handlers/list.rb
|
|
98
99
|
- lib/coradoc/mirror/handlers/open_block.rb
|