coradoc-mirror 0.1.5 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec671d9e6bbd3654635451d5a9ae2284f7e778f313b56e4e8d87e237e853b15e
4
- data.tar.gz: 51f63185d93bda861e6f545fdd4bceb0e07a9516db1d8d51011fda4e08236b35
3
+ metadata.gz: 29f073186a23485753658ba4782ec7022461c2869351d6bb273eda9f30fda92e
4
+ data.tar.gz: aee881fe73fa219d89415deb8b6eb0e9a509cbd4b5b71b3f4ddfe6456ef114f8
5
5
  SHA512:
6
- metadata.gz: 40d4b935ed85cdfb2a0d4845807df32367541498c4921879d5875194f8c1572402ad7bd809055cdb285b9ea2b7457c1847c8039c861c88db9c5094ea42d6edfa
7
- data.tar.gz: 91b105b79f7eef2230869c1cc386d0ec105b08346a36e66f4e18e95b6931a66382ae786910c9d6bc72c04e287dd9f856a38cc569dadfe3a9f2304f710186e0f7
6
+ metadata.gz: beabd828aeb5e91a4a3c9e6049045123a2c4884ceef8a9887d4ec27874242a22e36661d2f807a67cbb7bc4a19b4616b8b578463d4ecfb763d98fcf56d5c5a591
7
+ data.tar.gz: 23e77c6e5dc7605ba5e4ff8a4cab88efc7433c30554cb5afcb71cff4345d4dc6906ca2efa03d58034e07f6a594e543c7291e9dd88e02f2f458fb5c6c197cdee9
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module Mirror
5
+ module Handlers
6
+ module Abstract
7
+ def self.call(element, context:)
8
+ content = context.extract_content(element)
9
+ return nil if content.empty?
10
+
11
+ Node::Abstract.new(
12
+ attrs: Node::Abstract::Attrs.new(id: element.id, title: element.title),
13
+ content: content
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -8,13 +8,16 @@ module Coradoc
8
8
  # Two emission shapes:
9
9
  # - Ruby legacy (default): bare `image` node, title/caption in attrs.
10
10
  # - JS @metanorma/mirror (`partition_structural: true`): when the
11
- # source image has a title, wrap it in a `figure` node with the
12
- # image plus a `caption` child, matching the JS schema.
11
+ # source image is a **block** image with a title, wrap it in a
12
+ # `figure` node with the image plus a `caption` child, matching
13
+ # the JS schema. Inline images never wrap, even if they carry a
14
+ # role or title, because they live inside paragraph flow.
13
15
  module Image
14
16
  def self.call(element, context:)
15
17
  image_node = build_image_node(element)
16
18
 
17
19
  return image_node unless context.partition_structural
20
+ return image_node if element.inline
18
21
  return image_node unless caption_text?(element)
19
22
 
20
23
  Node::Figure.new(
@@ -27,16 +30,19 @@ module Coradoc
27
30
  private
28
31
 
29
32
  def build_image_node(element)
30
- Node::Image.new(
31
- attrs: Node::Image::Attrs.new(
32
- src: element.src,
33
- alt: element.alt,
34
- title: element.title,
35
- caption: element.caption,
36
- width: element.width,
37
- height: element.height,
38
- inline: element.inline || nil
39
- )
33
+ Node::Image.new(attrs: image_attrs(element))
34
+ end
35
+
36
+ def image_attrs(element)
37
+ Node::Image::Attrs.new(
38
+ src: element.src,
39
+ alt: element.alt,
40
+ title: element.title,
41
+ caption: element.caption,
42
+ width: element.width,
43
+ height: element.height,
44
+ role: element.role,
45
+ inline: element.inline
40
46
  )
41
47
  end
42
48
 
@@ -102,7 +102,9 @@ module Coradoc
102
102
  build_span_mark(element, context)
103
103
  when CoreModel::FootnoteElement
104
104
  build_footnote_node(element, context)
105
- when CoreModel::HardLineBreakElement, CoreModel::LineBreakElement
105
+ when CoreModel::HardLineBreakElement
106
+ Node::HardBreak.new
107
+ when CoreModel::LineBreakElement
106
108
  Node::SoftBreak.new
107
109
  when CoreModel::TextElement
108
110
  build_text_only(element, context)
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module Mirror
5
+ module Handlers
6
+ module Partintro
7
+ def self.call(element, context:)
8
+ content = context.extract_content(element)
9
+ return nil if content.empty?
10
+
11
+ Node::Partintro.new(
12
+ attrs: Node::Partintro::Attrs.new(id: element.id, title: element.title),
13
+ content: content
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -17,6 +17,8 @@ module Coradoc
17
17
  autoload :Blockquote, "#{__dir__}/handlers/blockquote"
18
18
  autoload :Example, "#{__dir__}/handlers/example"
19
19
  autoload :Sidebar, "#{__dir__}/handlers/sidebar"
20
+ autoload :Abstract, "#{__dir__}/handlers/abstract"
21
+ autoload :Partintro, "#{__dir__}/handlers/partintro"
20
22
  autoload :OpenBlock, "#{__dir__}/handlers/open_block"
21
23
  autoload :Verse, "#{__dir__}/handlers/verse"
22
24
  autoload :Comment, "#{__dir__}/handlers/comment"
@@ -303,6 +303,60 @@ module Coradoc
303
303
  end
304
304
  end
305
305
 
306
+ # Abstract block — `[abstract]\n====\n...\n====` in AsciiDoc. Carries
307
+ # the same shape as Sidebar/Example but a distinct wire type so the
308
+ # block-level construct does not collide with the section-level
309
+ # `abstract` (one of Section's PM_ALIASES). The block preserves its
310
+ # block identity through round-trip; renderers that want a section
311
+ # view should look at SectionElement-style sources instead.
312
+ class Abstract < Node
313
+ PM_TYPE = 'abstract_block'
314
+
315
+ class Attrs < Lutaml::Model::Serializable
316
+ attribute :title, :string
317
+ attribute :id, :string
318
+
319
+ key_value do
320
+ map 'title', to: :title
321
+ map 'id', to: :id
322
+ end
323
+ end
324
+
325
+ attribute :attrs, Attrs
326
+
327
+ key_value do
328
+ map 'type', to: :type, render_default: true
329
+ map 'attrs', to: :attrs
330
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
331
+ end
332
+ end
333
+
334
+ # Partintro block — `[partintro]\n====\n...\n====` in AsciiDoc, used
335
+ # to introduce a "part" in multi-part documents. Distinct wire type
336
+ # for the same reason as Abstract (no collision with potential
337
+ # section-level uses of "partintro").
338
+ class Partintro < Node
339
+ PM_TYPE = 'partintro_block'
340
+
341
+ class Attrs < Lutaml::Model::Serializable
342
+ attribute :title, :string
343
+ attribute :id, :string
344
+
345
+ key_value do
346
+ map 'title', to: :title
347
+ map 'id', to: :id
348
+ end
349
+ end
350
+
351
+ attribute :attrs, Attrs
352
+
353
+ key_value do
354
+ map 'type', to: :type, render_default: true
355
+ map 'attrs', to: :attrs
356
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
357
+ end
358
+ end
359
+
306
360
  class OpenBlock < Node
307
361
  PM_TYPE = 'open_block'
308
362
 
@@ -344,6 +398,15 @@ module Coradoc
344
398
  PM_TYPE = 'soft_break'
345
399
  end
346
400
 
401
+ # Hard line break — author-requested explicit break (`foo +\nbar` in
402
+ # AsciiDoc, `<br>` semantics in HTML). Distinct from SoftBreak so
403
+ # downstream renderers can map it to `<br>` rather than collapsing
404
+ # the break into a soft newline-or-space convention. ProseMirror's
405
+ # schema uses `hard_break` for the same purpose.
406
+ class HardBreak < Node
407
+ PM_TYPE = 'hard_break'
408
+ end
409
+
347
410
  # ── Admonition (NOTE, TIP, WARNING, CAUTION, IMPORTANT) ──
348
411
  #
349
412
  # The Ruby attribute name is `admonition_type` (kept distinct from
@@ -496,6 +559,7 @@ module Coradoc
496
559
  attribute :caption, :string
497
560
  attribute :width, :string
498
561
  attribute :height, :string
562
+ attribute :role, :string
499
563
  attribute :inline, :boolean
500
564
 
501
565
  key_value do
@@ -505,6 +569,7 @@ module Coradoc
505
569
  map 'caption', to: :caption
506
570
  map 'width', to: :width
507
571
  map 'height', to: :height
572
+ map 'role', to: :role
508
573
  map 'inline', to: :inline
509
574
  end
510
575
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ module Coradoc
6
+ module Mirror
7
+ module ReverseBuilder
8
+ class Abstract < Base
9
+ registers 'abstract_block'
10
+
11
+ def build(node)
12
+ CoreModel::AbstractBlock.new(
13
+ title: node.attrs&.title,
14
+ id: node.attrs&.id,
15
+ children: build_content(node)
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ module Coradoc
6
+ module Mirror
7
+ module ReverseBuilder
8
+ class HardBreak < Base
9
+ registers 'hard_break'
10
+
11
+ def build(_node)
12
+ CoreModel::HardLineBreakElement.new(content: '')
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ module Coradoc
6
+ module Mirror
7
+ module ReverseBuilder
8
+ class Partintro < Base
9
+ registers 'partintro_block'
10
+
11
+ def build(node)
12
+ CoreModel::PartintroBlock.new(
13
+ title: node.attrs&.title,
14
+ id: node.attrs&.id,
15
+ children: build_content(node)
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -62,6 +62,8 @@ module Coradoc
62
62
  require_relative 'reverse_builder/blockquote'
63
63
  require_relative 'reverse_builder/example'
64
64
  require_relative 'reverse_builder/sidebar'
65
+ require_relative 'reverse_builder/abstract'
66
+ require_relative 'reverse_builder/partintro'
65
67
  require_relative 'reverse_builder/open_block'
66
68
  require_relative 'reverse_builder/verse'
67
69
  require_relative 'reverse_builder/horizontal_rule'
@@ -91,6 +93,7 @@ module Coradoc
91
93
  require_relative 'reverse_builder/text'
92
94
  require_relative 'reverse_builder/raw_inline'
93
95
  require_relative 'reverse_builder/soft_break'
96
+ require_relative 'reverse_builder/hard_break'
94
97
  require_relative 'reverse_builder/generic_block'
95
98
  end
96
99
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Coradoc
4
4
  module Mirror
5
- VERSION = '0.1.5'
5
+ VERSION = '0.1.7'
6
6
  end
7
7
  end
@@ -75,6 +75,8 @@ module Coradoc
75
75
  registry.register(CoreModel::QuoteBlock, Handlers::Blockquote)
76
76
  registry.register(CoreModel::ExampleBlock, Handlers::Example)
77
77
  registry.register(CoreModel::SidebarBlock, Handlers::Sidebar)
78
+ registry.register(CoreModel::AbstractBlock, Handlers::Abstract)
79
+ registry.register(CoreModel::PartintroBlock, Handlers::Partintro)
78
80
  registry.register(CoreModel::OpenBlock, Handlers::OpenBlock)
79
81
  registry.register(CoreModel::VerseBlock, Handlers::Verse)
80
82
  registry.register(CoreModel::CommentBlock, Handlers::Comment)
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.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -81,6 +81,7 @@ files:
81
81
  - lib/coradoc/mirror/frontmatter_tree_to_hash.rb
82
82
  - lib/coradoc/mirror/handler_registry.rb
83
83
  - lib/coradoc/mirror/handlers.rb
84
+ - lib/coradoc/mirror/handlers/abstract.rb
84
85
  - lib/coradoc/mirror/handlers/admonition.rb
85
86
  - lib/coradoc/mirror/handlers/bibliography.rb
86
87
  - lib/coradoc/mirror/handlers/blockquote.rb
@@ -98,6 +99,7 @@ files:
98
99
  - lib/coradoc/mirror/handlers/list.rb
99
100
  - lib/coradoc/mirror/handlers/open_block.rb
100
101
  - lib/coradoc/mirror/handlers/paragraph.rb
102
+ - lib/coradoc/mirror/handlers/partintro.rb
101
103
  - lib/coradoc/mirror/handlers/reviewer.rb
102
104
  - lib/coradoc/mirror/handlers/sidebar.rb
103
105
  - lib/coradoc/mirror/handlers/structural.rb
@@ -112,6 +114,7 @@ files:
112
114
  - lib/coradoc/mirror/node.rb
113
115
  - lib/coradoc/mirror/partitioner.rb
114
116
  - lib/coradoc/mirror/reverse_builder.rb
117
+ - lib/coradoc/mirror/reverse_builder/abstract.rb
115
118
  - lib/coradoc/mirror/reverse_builder/admonition.rb
116
119
  - lib/coradoc/mirror/reverse_builder/base.rb
117
120
  - lib/coradoc/mirror/reverse_builder/biblio_entry.rb
@@ -129,6 +132,7 @@ files:
129
132
  - lib/coradoc/mirror/reverse_builder/footnotes.rb
130
133
  - lib/coradoc/mirror/reverse_builder/frontmatter.rb
131
134
  - lib/coradoc/mirror/reverse_builder/generic_block.rb
135
+ - lib/coradoc/mirror/reverse_builder/hard_break.rb
132
136
  - lib/coradoc/mirror/reverse_builder/header.rb
133
137
  - lib/coradoc/mirror/reverse_builder/horizontal_rule.rb
134
138
  - lib/coradoc/mirror/reverse_builder/image.rb
@@ -139,6 +143,7 @@ files:
139
143
  - lib/coradoc/mirror/reverse_builder/open_block.rb
140
144
  - lib/coradoc/mirror/reverse_builder/ordered_list.rb
141
145
  - lib/coradoc/mirror/reverse_builder/paragraph.rb
146
+ - lib/coradoc/mirror/reverse_builder/partintro.rb
142
147
  - lib/coradoc/mirror/reverse_builder/pass_block.rb
143
148
  - lib/coradoc/mirror/reverse_builder/preamble.rb
144
149
  - lib/coradoc/mirror/reverse_builder/raw_inline.rb