coradoc 1.1.2 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coradoc/element/attribute_list.rb +13 -1
- data/lib/coradoc/element/base.rb +2 -0
- data/lib/coradoc/element/block/core.rb +4 -3
- data/lib/coradoc/element/block/example.rb +1 -1
- data/lib/coradoc/element/block/listing.rb +21 -0
- data/lib/coradoc/element/block/literal.rb +4 -2
- data/lib/coradoc/element/block/open.rb +22 -0
- data/lib/coradoc/element/block.rb +3 -1
- data/lib/coradoc/element/list/core.rb +2 -2
- data/lib/coradoc/element/list/ordered.rb +1 -0
- data/lib/coradoc/element/list/unordered.rb +1 -0
- data/lib/coradoc/element/list_item.rb +13 -5
- data/lib/coradoc/element/section.rb +2 -2
- data/lib/coradoc/element/text_element.rb +9 -0
- data/lib/coradoc/input/html/converters/base.rb +2 -2
- data/lib/coradoc/input/html/converters/div.rb +1 -0
- data/lib/coradoc/input/html/converters/table.rb +7 -1
- data/lib/coradoc/input/html/postprocessor.rb +77 -15
- data/lib/coradoc/parser/asciidoc/attribute_list.rb +7 -1
- data/lib/coradoc/parser/asciidoc/base.rb +52 -134
- data/lib/coradoc/parser/asciidoc/block.rb +51 -38
- data/lib/coradoc/parser/asciidoc/content.rb +13 -3
- data/lib/coradoc/parser/asciidoc/list.rb +56 -22
- data/lib/coradoc/parser/asciidoc/paragraph.rb +16 -4
- data/lib/coradoc/parser/asciidoc/section.rb +3 -1
- data/lib/coradoc/parser/asciidoc/term.rb +2 -0
- data/lib/coradoc/parser/asciidoc/text.rb +161 -0
- data/lib/coradoc/parser/base.rb +4 -28
- data/lib/coradoc/transformer.rb +23 -39
- data/lib/coradoc/version.rb +1 -1
- data/utils/round_trip.rb +1 -1
- metadata +5 -2
@@ -0,0 +1,161 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Parser
|
3
|
+
module Asciidoc
|
4
|
+
module Text
|
5
|
+
|
6
|
+
def space?
|
7
|
+
space.maybe
|
8
|
+
end
|
9
|
+
|
10
|
+
def space
|
11
|
+
str(' ').repeat(1)
|
12
|
+
end
|
13
|
+
|
14
|
+
def text
|
15
|
+
match("[^\n]").repeat(1)
|
16
|
+
end
|
17
|
+
|
18
|
+
def line_start?
|
19
|
+
match('^[^\n]').present?
|
20
|
+
end
|
21
|
+
|
22
|
+
def line_ending
|
23
|
+
str("\n") #| match('[\z]')# | match('$')
|
24
|
+
end
|
25
|
+
|
26
|
+
def eof?
|
27
|
+
any.absent?
|
28
|
+
end
|
29
|
+
|
30
|
+
def line_end
|
31
|
+
str("\n") | str("\r\n") | eof?
|
32
|
+
end
|
33
|
+
|
34
|
+
def endline
|
35
|
+
newline | any.absent?
|
36
|
+
end
|
37
|
+
|
38
|
+
# def endline_single
|
39
|
+
# newline_single | any.absent?
|
40
|
+
# end
|
41
|
+
|
42
|
+
def newline
|
43
|
+
(str("\n") | str("\r\n")).repeat(1)
|
44
|
+
end
|
45
|
+
|
46
|
+
def newline_single
|
47
|
+
(str("\n") | str("\r\n"))
|
48
|
+
end
|
49
|
+
|
50
|
+
def keyword
|
51
|
+
(match('[a-zA-Z0-9_\-.,]') | str(".")).repeat(1)
|
52
|
+
end
|
53
|
+
|
54
|
+
def empty_line
|
55
|
+
match("^\n")
|
56
|
+
end
|
57
|
+
|
58
|
+
def digit
|
59
|
+
match("[0-9]")
|
60
|
+
end
|
61
|
+
|
62
|
+
def digits
|
63
|
+
match("[0-9]").repeat(1)
|
64
|
+
end
|
65
|
+
|
66
|
+
def word
|
67
|
+
match("[a-zA-Z0-9_-]").repeat(1)
|
68
|
+
end
|
69
|
+
|
70
|
+
def words
|
71
|
+
word >> (space? >> word).repeat
|
72
|
+
end
|
73
|
+
|
74
|
+
def rich_texts
|
75
|
+
rich_text >> (space? >> rich_text).repeat
|
76
|
+
end
|
77
|
+
|
78
|
+
def rich_text
|
79
|
+
(match("[a-zA-Z0-9_-]") | str(".") | str("*") | match("@")).repeat(1)
|
80
|
+
end
|
81
|
+
|
82
|
+
def email
|
83
|
+
word >> str("@") >> word >> str(".") >> word
|
84
|
+
end
|
85
|
+
|
86
|
+
def special_character
|
87
|
+
match("^[*:=-]") | str("[#") | str("[[")
|
88
|
+
end
|
89
|
+
|
90
|
+
def date
|
91
|
+
digit.repeat(2, 4) >> str("-") >>
|
92
|
+
digit.repeat(1, 2) >> str("-") >> digit.repeat(1, 2)
|
93
|
+
end
|
94
|
+
|
95
|
+
def attr_name
|
96
|
+
match("[^\t\s]").repeat(1)
|
97
|
+
end
|
98
|
+
|
99
|
+
def file_path
|
100
|
+
match('[^\[]').repeat(1)
|
101
|
+
end
|
102
|
+
|
103
|
+
def include_directive
|
104
|
+
(str("include::") >>
|
105
|
+
file_path.as(:path) >>
|
106
|
+
attribute_list >>
|
107
|
+
(newline | str("")).as(:line_break)
|
108
|
+
).as(:include)
|
109
|
+
end
|
110
|
+
|
111
|
+
def inline_image
|
112
|
+
(str("image::") >>
|
113
|
+
file_path.as(:path) >>
|
114
|
+
attribute_list >>
|
115
|
+
(line_ending)
|
116
|
+
).as(:inline_image)
|
117
|
+
end
|
118
|
+
|
119
|
+
def block_image
|
120
|
+
(block_id.maybe >>
|
121
|
+
block_title.maybe >>
|
122
|
+
(attribute_list >> newline).maybe >>
|
123
|
+
match('^i') >> str("mage::") >>
|
124
|
+
file_path.as(:path) >>
|
125
|
+
attribute_list(:attribute_list_macro) >>
|
126
|
+
newline.as(:line_break)
|
127
|
+
).as(:block_image)
|
128
|
+
end
|
129
|
+
|
130
|
+
def comment_line
|
131
|
+
tag.absent? >>
|
132
|
+
(str('//') >> str("/").absent? >>
|
133
|
+
space? >>
|
134
|
+
text.as(:comment_text)
|
135
|
+
).as(:comment_line)
|
136
|
+
end
|
137
|
+
|
138
|
+
def tag
|
139
|
+
(str('//') >> str('/').absent? >>
|
140
|
+
space? >>
|
141
|
+
(str('tag') | str('end')).as(:prefix) >>
|
142
|
+
str('::') >> str(':').absent? >>
|
143
|
+
match('[^\[]').repeat(1).as(:name) >>
|
144
|
+
attribute_list >>
|
145
|
+
line_ending.maybe.as(:line_break)
|
146
|
+
).as(:tag)
|
147
|
+
end
|
148
|
+
|
149
|
+
def comment_block
|
150
|
+
( str('////') >> line_ending >>
|
151
|
+
((line_ending >> str('////')).absent? >> any
|
152
|
+
).repeat.as(:comment_text) >>
|
153
|
+
line_ending >> str('////')
|
154
|
+
).as(:comment_block)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
|
data/lib/coradoc/parser/base.rb
CHANGED
@@ -1,36 +1,12 @@
|
|
1
|
+
require "digest"
|
1
2
|
require "parslet"
|
2
3
|
require "parslet/convenience"
|
3
4
|
|
4
|
-
require_relative "asciidoc/attribute_list"
|
5
5
|
require_relative "asciidoc/base"
|
6
|
-
require_relative "asciidoc/block"
|
7
|
-
require_relative "asciidoc/citation"
|
8
|
-
require_relative "asciidoc/content"
|
9
|
-
require_relative "asciidoc/document_attributes"
|
10
|
-
require_relative "asciidoc/header"
|
11
|
-
require_relative "asciidoc/inline"
|
12
|
-
require_relative "asciidoc/list"
|
13
|
-
require_relative "asciidoc/paragraph"
|
14
|
-
require_relative "asciidoc/section"
|
15
|
-
require_relative "asciidoc/table"
|
16
|
-
require_relative "asciidoc/term"
|
17
6
|
|
18
7
|
module Coradoc
|
19
8
|
module Parser
|
20
|
-
class Base <
|
21
|
-
include Coradoc::Parser::Asciidoc::AttributeList
|
22
|
-
include Coradoc::Parser::Asciidoc::Base
|
23
|
-
include Coradoc::Parser::Asciidoc::Block
|
24
|
-
include Coradoc::Parser::Asciidoc::Citation
|
25
|
-
include Coradoc::Parser::Asciidoc::Content
|
26
|
-
include Coradoc::Parser::Asciidoc::DocumentAttributes
|
27
|
-
include Coradoc::Parser::Asciidoc::Header
|
28
|
-
include Coradoc::Parser::Asciidoc::Inline
|
29
|
-
include Coradoc::Parser::Asciidoc::List
|
30
|
-
include Coradoc::Parser::Asciidoc::Paragraph
|
31
|
-
include Coradoc::Parser::Asciidoc::Section
|
32
|
-
include Coradoc::Parser::Asciidoc::Table
|
33
|
-
include Coradoc::Parser::Asciidoc::Term
|
9
|
+
class Base < Coradoc::Parser::Asciidoc::Base
|
34
10
|
|
35
11
|
root :document
|
36
12
|
rule(:document) do
|
@@ -43,8 +19,8 @@ module Coradoc
|
|
43
19
|
tag |
|
44
20
|
comment_block |
|
45
21
|
comment_line |
|
46
|
-
block
|
47
|
-
section
|
22
|
+
block |
|
23
|
+
section |
|
48
24
|
include_directive |
|
49
25
|
document_attributes |
|
50
26
|
list |
|
data/lib/coradoc/transformer.rb
CHANGED
@@ -156,27 +156,25 @@ module Coradoc
|
|
156
156
|
)
|
157
157
|
}
|
158
158
|
|
159
|
-
rule(bold_constrained: {
|
160
|
-
content: simple(:text)
|
161
|
-
}){
|
159
|
+
rule(bold_constrained: sequence(:text)){
|
162
160
|
Element::Inline::Bold.new(text, unconstrained: false)
|
163
161
|
}
|
164
162
|
|
165
|
-
rule(bold_unconstrained:
|
163
|
+
rule(bold_unconstrained: sequence(:text)) {
|
166
164
|
Element::Inline::Bold.new(text, unconstrained: true)
|
167
165
|
}
|
168
166
|
|
169
|
-
rule(highlight_constrained:
|
167
|
+
rule(highlight_constrained: sequence(:text)) {
|
170
168
|
Element::Inline::Highlight.new(text, unconstrained: false)
|
171
169
|
}
|
172
|
-
rule(highlight_unconstrained:
|
170
|
+
rule(highlight_unconstrained: sequence(:text)) {
|
173
171
|
Element::Inline::Highlight.new(text, unconstrained: true)
|
174
172
|
}
|
175
173
|
|
176
|
-
rule(italic_constrained:
|
174
|
+
rule(italic_constrained: sequence(:text)) {
|
177
175
|
Element::Inline::Italic.new(text, unconstrained: false)
|
178
176
|
}
|
179
|
-
rule(italic_unconstrained:
|
177
|
+
rule(italic_unconstrained: sequence(:text)) {
|
180
178
|
Element::Inline::Italic.new(text, unconstrained: true)
|
181
179
|
}
|
182
180
|
|
@@ -300,25 +298,24 @@ module Coradoc
|
|
300
298
|
if attribute_list
|
301
299
|
if (attribute_list.positional == [] &&
|
302
300
|
attribute_list.named.keys[0] == "reviewer")
|
303
|
-
Element::Block::ReviewerComment.new(
|
304
|
-
opts
|
305
|
-
)
|
301
|
+
Element::Block::ReviewerComment.new(opts)
|
306
302
|
elsif (attribute_list.positional[0] == "sidebar" &&
|
307
303
|
attribute_list.named == {})
|
308
|
-
Element::Block::Side.new(
|
309
|
-
|
310
|
-
)
|
304
|
+
Element::Block::Side.new(opts)
|
305
|
+
else
|
306
|
+
Element::Block::Side.new(opts)
|
311
307
|
end
|
312
308
|
else
|
309
|
+
Element::Block::Side.new(opts)
|
313
310
|
end
|
314
311
|
elsif delimiter_c == "="
|
315
312
|
Element::Block::Example.new(title, opts)
|
316
313
|
elsif delimiter_c == "+"
|
317
314
|
Element::Block::Pass.new(opts)
|
318
|
-
elsif delimiter_c == "-"
|
319
|
-
|
320
|
-
|
321
|
-
|
315
|
+
elsif delimiter_c == "-" && delimiter.size == 2
|
316
|
+
Element::Block::Open.new(title, opts)
|
317
|
+
elsif delimiter_c == "-"&& delimiter.size >= 4
|
318
|
+
Element::Block::SourceCode.new(title, opts)
|
322
319
|
elsif delimiter_c == "_"
|
323
320
|
Element::Block::Quote.new(title, opts)
|
324
321
|
end
|
@@ -379,28 +376,15 @@ module Coradoc
|
|
379
376
|
Element::Table.new(title, rows, opts)
|
380
377
|
end
|
381
378
|
|
382
|
-
rule(list_item:
|
383
|
-
marker
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
line_break: line_break
|
390
|
-
)
|
391
|
-
end
|
392
|
-
|
393
|
-
rule(list_item: simple(:list_item),
|
394
|
-
marker: simple(:marker),
|
395
|
-
id: simple(:id),
|
396
|
-
text: simple(:text),
|
397
|
-
line_break: simple(:line_break)) do
|
379
|
+
rule(list_item: subtree(:list_item)) do
|
380
|
+
marker = list_item[:marker]
|
381
|
+
id = list_item[:id]
|
382
|
+
text = list_item[:text]
|
383
|
+
attached = list_item[:attached]
|
384
|
+
nested = list_item[:nested]
|
385
|
+
line_break = list_item[:line_break]
|
398
386
|
Element::ListItem.new(
|
399
|
-
text,
|
400
|
-
id: id,
|
401
|
-
marker: marker.to_s,
|
402
|
-
line_break: line_break
|
403
|
-
)
|
387
|
+
text, id:, marker:, attached:, nested:, line_break: )
|
404
388
|
end
|
405
389
|
|
406
390
|
|
data/lib/coradoc/version.rb
CHANGED
data/utils/round_trip.rb
CHANGED
@@ -30,7 +30,7 @@ adoc_files.each do |file_path|
|
|
30
30
|
generated_adoc = Coradoc::Generator.gen_adoc(doc)
|
31
31
|
cleaned_adoc = Coradoc::Input::HTML.cleaner.tidy(generated_adoc)
|
32
32
|
File.open("#{file_path}.roundtrip","w"){|f| f.write(cleaned_adoc)}
|
33
|
-
`diff -
|
33
|
+
`diff -BNaur #{file_path} #{file_path}.roundtrip > #{file_path}.roundtrip.diff`
|
34
34
|
# rescue
|
35
35
|
# puts "unsuccessful..."
|
36
36
|
# end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coradoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-12-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: marcel
|
@@ -293,7 +293,9 @@ files:
|
|
293
293
|
- lib/coradoc/element/block.rb
|
294
294
|
- lib/coradoc/element/block/core.rb
|
295
295
|
- lib/coradoc/element/block/example.rb
|
296
|
+
- lib/coradoc/element/block/listing.rb
|
296
297
|
- lib/coradoc/element/block/literal.rb
|
298
|
+
- lib/coradoc/element/block/open.rb
|
297
299
|
- lib/coradoc/element/block/pass.rb
|
298
300
|
- lib/coradoc/element/block/quote.rb
|
299
301
|
- lib/coradoc/element/block/reviewer_comment.rb
|
@@ -410,6 +412,7 @@ files:
|
|
410
412
|
- lib/coradoc/parser/asciidoc/section.rb
|
411
413
|
- lib/coradoc/parser/asciidoc/table.rb
|
412
414
|
- lib/coradoc/parser/asciidoc/term.rb
|
415
|
+
- lib/coradoc/parser/asciidoc/text.rb
|
413
416
|
- lib/coradoc/parser/base.rb
|
414
417
|
- lib/coradoc/reverse_adoc.rb
|
415
418
|
- lib/coradoc/transformer.rb
|