coradoc-adoc 2.0.11 → 2.0.13

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: 791dca3b794e199e6d856458c3399946545f54a26a98cc4e8aee07de8b7aa21f
4
- data.tar.gz: 6fd4f6457098075c4ad3f98238ab56c4eb5359271f2024e3b75b0caee3791372
3
+ metadata.gz: e39d805fa1f2a5a0f7417223301a0935c858a8ccb157c57d420c8a3f8a90962b
4
+ data.tar.gz: 369b807f0cdeacf1bd0fb420500301add3d3c334e8e3b202054b4c14834faf37
5
5
  SHA512:
6
- metadata.gz: d8c7eb7672609651c3152ce468727f638cd5e9b5bd73b25b1334697710b8083391db13e9d6d030f97a288a7fe28e33567a2dd934b6a455c0e5279fe4fe183455
7
- data.tar.gz: 003e62344acf12212216306ad211330464866862dc5876d2caf7a4812c3c120a041b1da11d7ae83668b15e4a0c96a80e08984b9b7a3686de451fa548c444b0e0
6
+ metadata.gz: 2fa932a43798666e4a1dc2c709433ba55fe8ef570e7d8cc2c9d178a94a058295ec70353abf09fb5069cba6c6afe9dac110f742809ca696446c79759c2734160a
7
+ data.tar.gz: '091cdb09fb0cc658a60080718b536eacc6ddfd06056cf846e568af815c04f4dee05e1b8394cb0f246c324b9d903e73877f3219eaa4876ab69b0fb53204025868'
@@ -28,7 +28,13 @@ module Coradoc
28
28
  # admonition.content = "Be careful!"
29
29
  #
30
30
  class Admonition < Attached
31
- attribute :content, :string
31
+ attribute :content,
32
+ Lutaml::Model::Serializable,
33
+ collection: true,
34
+ polymorphic: [
35
+ Lutaml::Model::Type::String,
36
+ Coradoc::AsciiDoc::Model::TextElement
37
+ ]
32
38
  attribute :type, :string
33
39
  attribute :line_break, :string, default: -> { '' }
34
40
  end
@@ -36,9 +36,12 @@ module Coradoc
36
36
  # Coerce a raw parser AST value into the canonical ref_text string.
37
37
  # Accepts the shapes produced by Parser::Bibliography for `:ref_text`:
38
38
  # nil, Parslet::Slice, plain String, single Model::Base, or an Array
39
- # of any of these. Keeping this coercion on the model that owns
40
- # ref_text (rather than in a transformer rule) keeps the transformer
41
- # declarative and lets callers build entries from any source shape.
39
+ # of any of these. Model objects (TextElement, Inline::Italic, etc.)
40
+ # are flattened via TextExtractVisitor so their text content is
41
+ # preserved instead of leaking `#<Class:0x...>` inspect strings.
42
+ # Keeping this coercion on the model that owns ref_text (rather than
43
+ # in a transformer rule) keeps the transformer declarative and lets
44
+ # callers build entries from any source shape.
42
45
  # @param raw [Object, nil]
43
46
  # @return [String]
44
47
  def self.coerce_ref_text(raw)
@@ -47,6 +50,8 @@ module Coradoc
47
50
  case raw
48
51
  when Array then raw.map { |e| coerce_ref_text(e) }.join
49
52
  when String then raw
53
+ when Coradoc::AsciiDoc::Model::Base
54
+ Coradoc::AsciiDoc::Transform::TextExtractVisitor.new.extract(raw).to_s
50
55
  else raw.to_s
51
56
  end
52
57
  end
@@ -15,7 +15,7 @@ module Coradoc
15
15
 
16
16
  def admonition_line
17
17
  admonition_type.as(:admonition_type) >> str(': ') >>
18
- (text.as(:text) >>
18
+ (text_any.as(:text) >>
19
19
  line_ending.as(:line_break)
20
20
  ).repeat(1)
21
21
  .as(:content)
@@ -35,6 +35,75 @@ module Coradoc
35
35
  )
36
36
  end
37
37
 
38
+ # Open blocks (`--`) are generic containers. AsciiDoc allows
39
+ # casting them to a different block type via positional
40
+ # attributes: verbatim types (`[source]`, `[listing]`,
41
+ # `[literal]`) and admonition labels (`[NOTE]`, `[TIP]`,
42
+ # `[WARNING]`, `[CAUTION]`, `[IMPORTANT]`). When such a cast
43
+ # is present, the block behaves like the corresponding
44
+ # delimited block. Anything else stays an OpenBlock.
45
+ def transform_open_block(block)
46
+ semantic = open_block_semantic(block)
47
+ case semantic
48
+ when :source_code
49
+ transform_source_block(block)
50
+ when :listing
51
+ transform_listing_from_open(block)
52
+ when :literal
53
+ transform_literal_from_open(block)
54
+ when :admonition
55
+ transform_admonition_from_open(block)
56
+ else
57
+ transform_typed_block(block, Coradoc::CoreModel::OpenBlock)
58
+ end
59
+ end
60
+
61
+ ADMONITION_TYPES = %w[note tip warning caution important].freeze
62
+
63
+ def open_block_semantic(block)
64
+ attrs = block.attributes
65
+ return nil unless attrs.is_a?(Coradoc::AsciiDoc::Model::AttributeList)
66
+
67
+ first = attrs.positional&.first
68
+ return nil unless first.is_a?(Coradoc::AsciiDoc::Model::AttributeListAttribute)
69
+
70
+ case first.value.to_s.downcase
71
+ when 'source' then :source_code
72
+ when 'listing' then :listing
73
+ when 'literal' then :literal
74
+ when *ADMONITION_TYPES then :admonition
75
+ end
76
+ end
77
+
78
+ def transform_admonition_from_open(block)
79
+ type = block.attributes.positional.first.value.to_s.downcase
80
+ content_lines = Array(block.lines).map { |line| ToCoreModel.extract_text_content(line) }.join("\n")
81
+ Coradoc::CoreModel::AnnotationBlock.new(
82
+ annotation_type: type,
83
+ content: content_lines,
84
+ title: ToCoreModel.extract_title_text(block.title)
85
+ )
86
+ end
87
+
88
+ def transform_listing_from_open(block)
89
+ content_lines = Array(block.lines).map { |line| ToCoreModel.extract_text_content(line) }.join("\n")
90
+ Coradoc::CoreModel::ListingBlock.new(
91
+ id: block.id,
92
+ title: ToCoreModel.extract_title_text(block.title),
93
+ content: content_lines,
94
+ language: ToCoreModel.extract_block_language(block)
95
+ )
96
+ end
97
+
98
+ def transform_literal_from_open(block)
99
+ content_lines = Array(block.lines).map { |line| ToCoreModel.extract_text_content(line) }.join("\n")
100
+ Coradoc::CoreModel::LiteralBlock.new(
101
+ id: block.id,
102
+ title: ToCoreModel.extract_title_text(block.title),
103
+ content: content_lines
104
+ )
105
+ end
106
+
38
107
  def transform_block(block, semantic_type_or_delimiter)
39
108
  content_lines = ToCoreModel.extract_block_lines(block)
40
109
  semantic_type = if semantic_type_or_delimiter.is_a?(Symbol)
@@ -52,7 +52,6 @@ module Coradoc
52
52
  Coradoc::AsciiDoc::Model::Block::Example => Coradoc::CoreModel::ExampleBlock,
53
53
  Coradoc::AsciiDoc::Model::Block::Side => Coradoc::CoreModel::SidebarBlock,
54
54
  Coradoc::AsciiDoc::Model::Block::Literal => Coradoc::CoreModel::LiteralBlock,
55
- Coradoc::AsciiDoc::Model::Block::Open => Coradoc::CoreModel::OpenBlock,
56
55
  Coradoc::AsciiDoc::Model::Block::Pass => Coradoc::CoreModel::PassBlock
57
56
  }.each do |block_class, core_model_class|
58
57
  Registry.register_with_priority(
@@ -62,6 +61,12 @@ module Coradoc
62
61
  )
63
62
  end
64
63
 
64
+ Registry.register_with_priority(
65
+ Coradoc::AsciiDoc::Model::Block::Open,
66
+ ->(model) { Blk.transform_open_block(model) },
67
+ priority: 10
68
+ )
69
+
65
70
  Registry.register(
66
71
  Coradoc::AsciiDoc::Model::Block::Core,
67
72
  ->(model) { Blk.transform_block(model, model.delimiter.to_s) }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Coradoc
4
4
  module AsciiDoc
5
- VERSION = '2.0.11'
5
+ VERSION = '2.0.13'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coradoc-adoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.11
4
+ version: 2.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.