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: 7e474854dfc3ccc3cb6edce0dce14958aa962cfd87d40ce77a530348d6f7488b
4
- data.tar.gz: 50b26a4e35effc7a2065e06a739eb3ca4bfc62ccf1b0242987c8d29f42a9722b
3
+ metadata.gz: 000b9fd36ba19db9a57b3ad656292b1629eb82a12e7004add2e97b7823060e19
4
+ data.tar.gz: f5364e581508705701aac01de53a2d03371213a4224356d4343f197aa37edab0
5
5
  SHA512:
6
- metadata.gz: 6dee99c97897a0a65cf8667b5b78ee6ac549511b5e16208454b467955baf8f48030fcfe724120f4f42ec183521c61660811cd89be834c46be8deee0994052c68
7
- data.tar.gz: 94c0a6bcb1e973cea8fee23324a7f4d4eaa70673c1400313da931c7a2eab0132facc7d7356cbb9f639c3895a67cf1f968f6df08c12d43fc23db1db202c2c8045
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
@@ -33,6 +33,7 @@ module Coradoc
33
33
  autoload :Toc, "#{__dir__}/handlers/toc"
34
34
  autoload :Frontmatter, "#{__dir__}/handlers/frontmatter"
35
35
  autoload :GenericBlock, "#{__dir__}/handlers/generic_block"
36
+ autoload :Include, "#{__dir__}/handlers/include"
36
37
  end
37
38
  end
38
39
  end
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Coradoc
4
4
  module Mirror
5
- VERSION = '0.1.3'
5
+ VERSION = '0.1.4'
6
6
  end
7
7
  end
@@ -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.3
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