coradoc-adoc 2.0.22 → 2.0.24
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/model/attribute_list.rb +31 -4
- data/lib/coradoc/asciidoc/model/base.rb +7 -0
- data/lib/coradoc/asciidoc/model/image/attribute_extractor.rb +142 -0
- data/lib/coradoc/asciidoc/model/image/block_image.rb +8 -0
- data/lib/coradoc/asciidoc/model/image/core.rb +35 -26
- data/lib/coradoc/asciidoc/model/image/inline_image.rb +7 -0
- data/lib/coradoc/asciidoc/model/image.rb +1 -0
- data/lib/coradoc/asciidoc/parser/attribute_list.rb +4 -1
- data/lib/coradoc/asciidoc/serializer/serializers/image/core.rb +3 -1
- data/lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb +6 -1
- data/lib/coradoc/asciidoc/transform/element_transformers/block_transformer.rb +39 -16
- data/lib/coradoc/asciidoc/transform/element_transformers/document_transformer.rb +2 -27
- data/lib/coradoc/asciidoc/transform/element_transformers/include_transformer.rb +2 -1
- data/lib/coradoc/asciidoc/transform/element_transformers/inline_transformer.rb +12 -6
- data/lib/coradoc/asciidoc/transform/element_transformers/list_transformer.rb +10 -4
- data/lib/coradoc/asciidoc/transform/element_transformers/other_transformer.rb +25 -22
- data/lib/coradoc/asciidoc/transform/element_transformers/table_transformer.rb +6 -3
- data/lib/coradoc/asciidoc/transform/from_core_model.rb +16 -40
- data/lib/coradoc/asciidoc/transform/inline_transform_visitor.rb +23 -5
- data/lib/coradoc/asciidoc/transform/to_core_model.rb +30 -6
- data/lib/coradoc/asciidoc/transformer/block_rules.rb +19 -5
- data/lib/coradoc/asciidoc/transformer/header_rules.rb +12 -3
- data/lib/coradoc/asciidoc/transformer/inline_rules.rb +68 -20
- data/lib/coradoc/asciidoc/transformer/list_rules.rb +20 -5
- data/lib/coradoc/asciidoc/transformer/misc_rules.rb +31 -12
- data/lib/coradoc/asciidoc/transformer/source_line_extractor.rb +67 -0
- data/lib/coradoc/asciidoc/transformer/structural_rules.rb +7 -3
- data/lib/coradoc/asciidoc/transformer/text_rules.rb +33 -9
- data/lib/coradoc/asciidoc/transformer.rb +6 -1
- data/lib/coradoc/asciidoc/version.rb +1 -1
- metadata +3 -1
|
@@ -12,16 +12,25 @@ module Coradoc
|
|
|
12
12
|
comment_text: simple(:comment_text),
|
|
13
13
|
line_break: simple(:line_break)
|
|
14
14
|
}) do
|
|
15
|
-
Model::CommentLine.new(
|
|
15
|
+
Model::CommentLine.new(
|
|
16
|
+
text: comment_text,
|
|
17
|
+
line_break: line_break,
|
|
18
|
+
source_line: SourceLineExtractor.extract(comment_text)
|
|
19
|
+
)
|
|
16
20
|
end
|
|
17
21
|
|
|
18
22
|
rule(comment_block: { comment_text: simple(:comment_text) }) do
|
|
19
|
-
Model::CommentBlock.new(
|
|
23
|
+
Model::CommentBlock.new(
|
|
24
|
+
text: comment_text,
|
|
25
|
+
source_line: SourceLineExtractor.extract(comment_text)
|
|
26
|
+
)
|
|
20
27
|
end
|
|
21
28
|
|
|
22
29
|
# Page break
|
|
23
30
|
rule(page_break: simple(:page_break)) do
|
|
24
|
-
Model::Break::PageBreak.new
|
|
31
|
+
Model::Break::PageBreak.new(
|
|
32
|
+
source_line: SourceLineExtractor.extract(page_break)
|
|
33
|
+
)
|
|
25
34
|
end
|
|
26
35
|
|
|
27
36
|
# Tag
|
|
@@ -30,7 +39,8 @@ module Coradoc
|
|
|
30
39
|
name: tag[:name],
|
|
31
40
|
attrs: tag[:attribute_list],
|
|
32
41
|
line_break: tag[:line_break],
|
|
33
|
-
prefix: tag[:prefix]
|
|
42
|
+
prefix: tag[:prefix],
|
|
43
|
+
source_line: SourceLineExtractor.extract(tag)
|
|
34
44
|
)
|
|
35
45
|
end
|
|
36
46
|
|
|
@@ -45,7 +55,7 @@ module Coradoc
|
|
|
45
55
|
end
|
|
46
56
|
|
|
47
57
|
rule(positional: simple(:positional)) do
|
|
48
|
-
positional
|
|
58
|
+
positional
|
|
49
59
|
end
|
|
50
60
|
|
|
51
61
|
rule(attribute_array: nil) do
|
|
@@ -53,11 +63,16 @@ module Coradoc
|
|
|
53
63
|
end
|
|
54
64
|
|
|
55
65
|
rule(attribute_array: sequence(:attributes)) do
|
|
56
|
-
attr_list = Model::AttributeList.new
|
|
66
|
+
attr_list = Model::AttributeList.new(
|
|
67
|
+
source_line: SourceLineExtractor.extract(attributes)
|
|
68
|
+
)
|
|
57
69
|
attributes.each do |a|
|
|
58
|
-
|
|
70
|
+
case a
|
|
71
|
+
when Parslet::Slice
|
|
72
|
+
attr_list.add_positional(a.to_s)
|
|
73
|
+
when String
|
|
59
74
|
attr_list.add_positional(a)
|
|
60
|
-
|
|
75
|
+
when Model::Attribute
|
|
61
76
|
attr_list.add_named(a.key, a.value)
|
|
62
77
|
end
|
|
63
78
|
end
|
|
@@ -104,7 +119,8 @@ module Coradoc
|
|
|
104
119
|
Model::Include.new(
|
|
105
120
|
path: path.to_s,
|
|
106
121
|
attributes: attribute_list,
|
|
107
|
-
line_break: line_break
|
|
122
|
+
line_break: line_break,
|
|
123
|
+
source_line: SourceLineExtractor.extract(path)
|
|
108
124
|
)
|
|
109
125
|
end
|
|
110
126
|
|
|
@@ -119,7 +135,8 @@ module Coradoc
|
|
|
119
135
|
Model::Audio.new(
|
|
120
136
|
src: path.to_s,
|
|
121
137
|
attributes: attribute_list,
|
|
122
|
-
line_break: line_break
|
|
138
|
+
line_break: line_break,
|
|
139
|
+
source_line: SourceLineExtractor.extract(path)
|
|
123
140
|
)
|
|
124
141
|
end
|
|
125
142
|
|
|
@@ -134,7 +151,8 @@ module Coradoc
|
|
|
134
151
|
Model::Video.new(
|
|
135
152
|
src: path.to_s,
|
|
136
153
|
attributes: attribute_list,
|
|
137
|
-
line_break: line_break
|
|
154
|
+
line_break: line_break,
|
|
155
|
+
source_line: SourceLineExtractor.extract(path)
|
|
138
156
|
)
|
|
139
157
|
end
|
|
140
158
|
|
|
@@ -162,7 +180,8 @@ module Coradoc
|
|
|
162
180
|
date: attrs[:date],
|
|
163
181
|
from: attrs[:from],
|
|
164
182
|
to: attrs[:to],
|
|
165
|
-
content: Transformer.lines_to_text_elements(lines)
|
|
183
|
+
content: Transformer.lines_to_text_elements(lines),
|
|
184
|
+
source_line: SourceLineExtractor.extract(reviewer_note)
|
|
166
185
|
)
|
|
167
186
|
end
|
|
168
187
|
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'parslet'
|
|
4
|
+
|
|
5
|
+
module Coradoc
|
|
6
|
+
module AsciiDoc
|
|
7
|
+
class Transformer < Parslet::Transform
|
|
8
|
+
# Walks a Parslet AST subtree (Hash/Array/Slice/String/Model) and
|
|
9
|
+
# returns the 1-indexed source line of the first +Parslet::Slice+
|
|
10
|
+
# or Model::Base#source_line it finds.
|
|
11
|
+
#
|
|
12
|
+
# Parslet preserves byte offsets on every matched slice
|
|
13
|
+
# (+slice.line_and_column+ returns +[line, column]+); the
|
|
14
|
+
# transformer receives these slices in the AST but most rules
|
|
15
|
+
# discard the position when building Model objects. This helper
|
|
16
|
+
# recovers the start line of any subtree so transformer rules
|
|
17
|
+
# can populate +Model::Base#source_line+ without changing the
|
|
18
|
+
# parser.
|
|
19
|
+
#
|
|
20
|
+
# Handles two distinct shapes:
|
|
21
|
+
# * Pre-transform AST (Hash/Array of Parslet::Slice) — used by
|
|
22
|
+
# rules that bind raw slices via +simple(:x)+.
|
|
23
|
+
# * Post-transform Model tree (Model::Base instances whose
|
|
24
|
+
# +source_line+ was populated by an earlier rule) — used by
|
|
25
|
+
# rules that bind via +subtree(:x)+ and receive already-
|
|
26
|
+
# transformed content.
|
|
27
|
+
#
|
|
28
|
+
# Returns nil when no position is found (programmatic input,
|
|
29
|
+
# already-stripped ASTs, etc.) — callers should treat nil as
|
|
30
|
+
# "source position unavailable".
|
|
31
|
+
module SourceLineExtractor
|
|
32
|
+
module_function
|
|
33
|
+
|
|
34
|
+
def extract(node)
|
|
35
|
+
case node
|
|
36
|
+
when Parslet::Slice then line_of(node)
|
|
37
|
+
when Coradoc::AsciiDoc::Model::Base then node.source_line
|
|
38
|
+
when Hash then extract_from_hash(node)
|
|
39
|
+
when Array then extract_from_array(node)
|
|
40
|
+
else nil
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def line_of(slice)
|
|
45
|
+
line, _column = slice.line_and_column
|
|
46
|
+
line
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def extract_from_hash(hash)
|
|
50
|
+
hash.each_value do |value|
|
|
51
|
+
line = extract(value)
|
|
52
|
+
return line if line
|
|
53
|
+
end
|
|
54
|
+
nil
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def extract_from_array(array)
|
|
58
|
+
array.each do |value|
|
|
59
|
+
line = extract(value)
|
|
60
|
+
return line if line
|
|
61
|
+
end
|
|
62
|
+
nil
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -72,6 +72,7 @@ module Coradoc
|
|
|
72
72
|
opts = { rows: Transformer.regroup_table_rows(rows, attrs), attrs: attrs }
|
|
73
73
|
opts[:id] = id if id
|
|
74
74
|
opts[:title] = title unless title.nil? || title.empty?
|
|
75
|
+
opts[:source_line] = SourceLineExtractor.extract(table)
|
|
75
76
|
Model::Table.new(**opts)
|
|
76
77
|
end
|
|
77
78
|
|
|
@@ -84,7 +85,8 @@ module Coradoc
|
|
|
84
85
|
Model::Title.new(
|
|
85
86
|
content: text,
|
|
86
87
|
level_int: level.size - 1,
|
|
87
|
-
line_break: line_break
|
|
88
|
+
line_break: line_break,
|
|
89
|
+
source_line: SourceLineExtractor.extract(level)
|
|
88
90
|
)
|
|
89
91
|
end
|
|
90
92
|
|
|
@@ -98,7 +100,8 @@ module Coradoc
|
|
|
98
100
|
content: text,
|
|
99
101
|
level_int: level.size - 1,
|
|
100
102
|
line_break: line_break,
|
|
101
|
-
id: name
|
|
103
|
+
id: name,
|
|
104
|
+
source_line: SourceLineExtractor.extract(name)
|
|
102
105
|
)
|
|
103
106
|
end
|
|
104
107
|
|
|
@@ -117,7 +120,8 @@ module Coradoc
|
|
|
117
120
|
id: id,
|
|
118
121
|
attribute_list: attribute_list,
|
|
119
122
|
contents: contents,
|
|
120
|
-
sections: sections
|
|
123
|
+
sections: sections,
|
|
124
|
+
source_line: SourceLineExtractor.extract(section)
|
|
121
125
|
)
|
|
122
126
|
end
|
|
123
127
|
|
|
@@ -9,7 +9,10 @@ module Coradoc
|
|
|
9
9
|
transformer_class.class_eval do
|
|
10
10
|
# Text Model
|
|
11
11
|
rule(text: simple(:text)) do
|
|
12
|
-
Model::TextElement.new(
|
|
12
|
+
Model::TextElement.new(
|
|
13
|
+
content: text.to_s,
|
|
14
|
+
source_line: Transformer::SourceLineExtractor.extract(text)
|
|
15
|
+
)
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
rule(text_string: subtree(:text_string)) do
|
|
@@ -17,19 +20,34 @@ module Coradoc
|
|
|
17
20
|
end
|
|
18
21
|
|
|
19
22
|
rule(text: simple(:text), line_break: simple(:line_break)) do
|
|
20
|
-
Model::TextElement.new(
|
|
23
|
+
Model::TextElement.new(
|
|
24
|
+
content: text.to_s,
|
|
25
|
+
line_break: line_break,
|
|
26
|
+
source_line: Transformer::SourceLineExtractor.extract(text)
|
|
27
|
+
)
|
|
21
28
|
end
|
|
22
29
|
|
|
23
30
|
rule(text: sequence(:text), line_break: simple(:line_break)) do
|
|
24
|
-
Model::TextElement.new(
|
|
31
|
+
Model::TextElement.new(
|
|
32
|
+
content: text,
|
|
33
|
+
line_break: line_break,
|
|
34
|
+
source_line: Transformer::SourceLineExtractor.extract(text)
|
|
35
|
+
)
|
|
25
36
|
end
|
|
26
37
|
|
|
27
38
|
rule(id: simple(:id), text: simple(:text)) do
|
|
28
|
-
Model::TextElement.new(
|
|
39
|
+
Model::TextElement.new(
|
|
40
|
+
content: text.to_s,
|
|
41
|
+
id: id.to_s,
|
|
42
|
+
source_line: Transformer::SourceLineExtractor.extract(id)
|
|
43
|
+
)
|
|
29
44
|
end
|
|
30
45
|
|
|
31
46
|
rule(text: sequence(:text)) do
|
|
32
|
-
Model::TextElement.new(
|
|
47
|
+
Model::TextElement.new(
|
|
48
|
+
content: text,
|
|
49
|
+
source_line: Transformer::SourceLineExtractor.extract(text)
|
|
50
|
+
)
|
|
33
51
|
end
|
|
34
52
|
|
|
35
53
|
rule(
|
|
@@ -40,7 +58,8 @@ module Coradoc
|
|
|
40
58
|
Model::TextElement.new(
|
|
41
59
|
content: text.to_s,
|
|
42
60
|
id: id.to_s,
|
|
43
|
-
line_break: line_break
|
|
61
|
+
line_break: line_break,
|
|
62
|
+
source_line: Transformer::SourceLineExtractor.extract(id)
|
|
44
63
|
)
|
|
45
64
|
end
|
|
46
65
|
|
|
@@ -52,13 +71,17 @@ module Coradoc
|
|
|
52
71
|
Model::TextElement.new(
|
|
53
72
|
content: text,
|
|
54
73
|
id: id.to_s,
|
|
55
|
-
line_break: line_break
|
|
74
|
+
line_break: line_break,
|
|
75
|
+
source_line: Transformer::SourceLineExtractor.extract(id)
|
|
56
76
|
)
|
|
57
77
|
end
|
|
58
78
|
|
|
59
79
|
# Line break
|
|
60
80
|
rule(line_break: simple(:line_break)) do
|
|
61
|
-
Model::LineBreak.new(
|
|
81
|
+
Model::LineBreak.new(
|
|
82
|
+
line_break:,
|
|
83
|
+
source_line: Transformer::SourceLineExtractor.extract(line_break)
|
|
84
|
+
)
|
|
62
85
|
end
|
|
63
86
|
|
|
64
87
|
# Unparsed text
|
|
@@ -72,7 +95,8 @@ module Coradoc
|
|
|
72
95
|
content: Transformer.lines_to_text_elements(paragraph[:lines]),
|
|
73
96
|
id: paragraph[:id],
|
|
74
97
|
attributes: paragraph[:attribute_list],
|
|
75
|
-
title: paragraph[:title]
|
|
98
|
+
title: paragraph[:title],
|
|
99
|
+
source_line: Transformer::SourceLineExtractor.extract(paragraph)
|
|
76
100
|
)
|
|
77
101
|
end
|
|
78
102
|
end
|
|
@@ -33,6 +33,7 @@ module Coradoc
|
|
|
33
33
|
autoload :BlockTypeClassifier, "#{__dir__}/transformer/block_type_classifier"
|
|
34
34
|
autoload :TableLayout, "#{__dir__}/transformer/table_layout"
|
|
35
35
|
autoload :TableCellBuilder, "#{__dir__}/transformer/table_cell_builder"
|
|
36
|
+
autoload :SourceLineExtractor, "#{__dir__}/transformer/source_line_extractor"
|
|
36
37
|
|
|
37
38
|
# Apply all rule modules (triggers autoload)
|
|
38
39
|
HeaderRules.apply(self)
|
|
@@ -139,7 +140,11 @@ module Coradoc
|
|
|
139
140
|
text_content
|
|
140
141
|
end
|
|
141
142
|
|
|
142
|
-
Model::TextElement.new(
|
|
143
|
+
Model::TextElement.new(
|
|
144
|
+
content: transformed,
|
|
145
|
+
line_break: line[:line_break],
|
|
146
|
+
source_line: SourceLineExtractor.extract(line)
|
|
147
|
+
)
|
|
143
148
|
end
|
|
144
149
|
end
|
|
145
150
|
|
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.
|
|
4
|
+
version: 2.0.24
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -146,6 +146,7 @@ files:
|
|
|
146
146
|
- lib/coradoc/asciidoc/model/header.rb
|
|
147
147
|
- lib/coradoc/asciidoc/model/highlight.rb
|
|
148
148
|
- lib/coradoc/asciidoc/model/image.rb
|
|
149
|
+
- lib/coradoc/asciidoc/model/image/attribute_extractor.rb
|
|
149
150
|
- lib/coradoc/asciidoc/model/image/block_image.rb
|
|
150
151
|
- lib/coradoc/asciidoc/model/image/block_image/attribute_list.rb
|
|
151
152
|
- lib/coradoc/asciidoc/model/image/core.rb
|
|
@@ -342,6 +343,7 @@ files:
|
|
|
342
343
|
- lib/coradoc/asciidoc/transformer/inline_rules.rb
|
|
343
344
|
- lib/coradoc/asciidoc/transformer/list_rules.rb
|
|
344
345
|
- lib/coradoc/asciidoc/transformer/misc_rules.rb
|
|
346
|
+
- lib/coradoc/asciidoc/transformer/source_line_extractor.rb
|
|
345
347
|
- lib/coradoc/asciidoc/transformer/structural_rules.rb
|
|
346
348
|
- lib/coradoc/asciidoc/transformer/table_cell_builder.rb
|
|
347
349
|
- lib/coradoc/asciidoc/transformer/table_layout.rb
|