coradoc-adoc 2.0.12 → 2.0.14
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/asciidoc/parser/citation.rb +6 -18
- data/lib/coradoc/asciidoc/transform/element_transformers/block_transformer.rb +69 -0
- data/lib/coradoc/asciidoc/transform/to_core_model_registrations.rb +6 -1
- data/lib/coradoc/asciidoc/transformer/inline_rules.rb +5 -19
- data/lib/coradoc/asciidoc/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: 36de3b63e2c80a4abafb35c88ca1ba80eb52603af631191e16f26d6482a5398c
|
|
4
|
+
data.tar.gz: 53026d0cf6835c5824636ffd6455f2baceecc3ffdd510cc26c8b79910c180c4f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8c51394ca9c3bde2a4d7c329e01648ae54d51d6e95e767a85cbaedc8aac35894fccaa50a9d46bf629477d8ac897700b70fff92d060dcbc9acad7182f92913672
|
|
7
|
+
data.tar.gz: 1bc422db9eeb898056d1a79150a1efdf81bddce0f0895cfc1760d9e6cc1953ccfc0d29aa2718da79c5e637ae1afca3565c8a08832950e4bfc0c3b102d3a4ea5a
|
|
@@ -4,25 +4,13 @@ module Coradoc
|
|
|
4
4
|
module AsciiDoc
|
|
5
5
|
module Parser
|
|
6
6
|
module Citation
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def xref_str
|
|
12
|
-
match('[^,>]').repeat(1).as(:text)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def xref_arg
|
|
16
|
-
(str('section') | str('paragraph') | str('clause') | str('annex') | str('table')).as(:key) >>
|
|
17
|
-
match('[ =]').as(:delimiter) >>
|
|
18
|
-
match('[^,>=]').repeat(1).as(:value)
|
|
19
|
-
end
|
|
20
|
-
|
|
7
|
+
# In `<<target,text>>`, the target is everything up to the first comma
|
|
8
|
+
# or closing `>`. The text is everything else up to `>` — it can
|
|
9
|
+
# contain commas, quotes, and any other punctuation.
|
|
21
10
|
def cross_reference
|
|
22
|
-
(str('<<') >>
|
|
23
|
-
|
|
24
|
-
(str(',') >>
|
|
25
|
-
).maybe >>
|
|
11
|
+
(str('<<') >>
|
|
12
|
+
match('[^,>]').repeat(1).as(:href) >>
|
|
13
|
+
(str(',') >> match('[^>]').repeat(0).as(:text)).maybe >>
|
|
26
14
|
str('>>')
|
|
27
15
|
).as(:cross_reference)
|
|
28
16
|
end
|
|
@@ -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) }
|
|
@@ -27,20 +27,11 @@ module Coradoc
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# Cross reference
|
|
30
|
-
rule(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
href: simple(:href),
|
|
36
|
-
name: simple(:name)
|
|
37
|
-
) do
|
|
38
|
-
Model::Inline::CrossReference.new(href: href.to_s, args: [name.to_s])
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
rule(cross_reference: sequence(:xref)) do
|
|
42
|
-
args = xref.size > 1 ? xref[1..] : []
|
|
43
|
-
Model::Inline::CrossReference.new(href: xref[0], args:)
|
|
30
|
+
rule(cross_reference: subtree(:xref)) do
|
|
31
|
+
href = xref[:href].to_s
|
|
32
|
+
text = xref[:text]
|
|
33
|
+
args = text ? [text.to_s] : []
|
|
34
|
+
Model::Inline::CrossReference.new(href:, args:)
|
|
44
35
|
end
|
|
45
36
|
|
|
46
37
|
# Inline image
|
|
@@ -88,11 +79,6 @@ module Coradoc
|
|
|
88
79
|
Coradoc::AsciiDoc::Model::Inline::Footnote.new(text: text_str)
|
|
89
80
|
end
|
|
90
81
|
|
|
91
|
-
# Href arg
|
|
92
|
-
rule(href_arg: simple(:href_arg)) do
|
|
93
|
-
href_arg.to_s
|
|
94
|
-
end
|
|
95
|
-
|
|
96
82
|
# Inline formatting rules generated from a single registry.
|
|
97
83
|
# See InlineRules::FORMATTING_VARIANTS. `span` is special
|
|
98
84
|
# because it carries `text:` + `attributes:` rather than
|