asuka 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +6 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/bin/asuka +7 -0
- data/lib/asuka.rb +16 -0
- data/lib/asuka/accumulator.rb +27 -0
- data/lib/asuka/document.rb +122 -0
- data/lib/asuka/formatter.rb +53 -0
- data/lib/asuka/line_formatter.rb +24 -0
- data/lib/asuka/parser.rb +42 -0
- data/lib/asuka/rules.rb +106 -0
- data/samples/samples.asuka +98 -0
- data/spec/integration/parser_spec.rb +297 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/unit/accumulator_spec.rb +79 -0
- data/spec/unit/blockquote_spec.rb +25 -0
- data/spec/unit/document_spec.rb +59 -0
- data/spec/unit/formatter_spec.rb +93 -0
- data/spec/unit/header_spec.rb +12 -0
- data/spec/unit/line_formatter_spec.rb +132 -0
- data/spec/unit/line_group_spec.rb +14 -0
- data/spec/unit/paragraph_spec.rb +25 -0
- data/spec/unit/rule_spec.rb +11 -0
- data/spec/unit/unordered_list_spec.rb +25 -0
- metadata +114 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
|
2
|
+
# Header
|
3
|
+
|
4
|
+
## Paragraphs
|
5
|
+
|
6
|
+
This is a one-line paragraph.
|
7
|
+
|
8
|
+
This is a LOOOOONG one-line paragraph that goes on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on.
|
9
|
+
|
10
|
+
This is a paragraph with
|
11
|
+
each line terminated with
|
12
|
+
a newline character.
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
This is another paragraph following a few empty lines.
|
17
|
+
|
18
|
+
-
|
19
|
+
--
|
20
|
+
---
|
21
|
+
|
22
|
+
## Lists
|
23
|
+
|
24
|
+
* this
|
25
|
+
* is
|
26
|
+
* a
|
27
|
+
* ul-list
|
28
|
+
|
29
|
+
*this
|
30
|
+
*is
|
31
|
+
*not a ul-list
|
32
|
+
|
33
|
+
-------------------------------------------
|
34
|
+
|
35
|
+
## Blockquotes
|
36
|
+
|
37
|
+
> This is a blockquote
|
38
|
+
|
39
|
+
> This is a multi-line
|
40
|
+
> blockquote with many
|
41
|
+
> needless words
|
42
|
+
|
43
|
+
-------------------------------------------
|
44
|
+
|
45
|
+
## Headers
|
46
|
+
|
47
|
+
# h1
|
48
|
+
## h2
|
49
|
+
### h3
|
50
|
+
#### h4
|
51
|
+
##### h5
|
52
|
+
###### h6
|
53
|
+
####### something else
|
54
|
+
######## something else
|
55
|
+
|
56
|
+
-------------------------------------------
|
57
|
+
|
58
|
+
## Escape Sequences
|
59
|
+
|
60
|
+
Something & "something" else & <.
|
61
|
+
|
62
|
+
4 < 5 > 2
|
63
|
+
|
64
|
+
The <body> tag.
|
65
|
+
|
66
|
+
-------------------------------------------
|
67
|
+
|
68
|
+
## Italic and Bold
|
69
|
+
|
70
|
+
This is a paragraph with *italic* and **bold** words.
|
71
|
+
|
72
|
+
This is a another paragraph with *1*, *2*, *3* and **4** words.
|
73
|
+
|
74
|
+
This is a paragraph with _underscores_.
|
75
|
+
|
76
|
+
This is a paragraph with crazy stuff ***going on*** ****all over the place****.
|
77
|
+
|
78
|
+
* *1*
|
79
|
+
* **2**
|
80
|
+
* ***3***
|
81
|
+
* ****4****
|
82
|
+
* *****5*****
|
83
|
+
* ******6******
|
84
|
+
|
85
|
+
> This is a *magnificent* blockquote
|
86
|
+
> with **magic** formatting.
|
87
|
+
|
88
|
+
-------------------------------------------
|
89
|
+
|
90
|
+
## Links
|
91
|
+
|
92
|
+
Links work [forward][http://nowhere.com] and [http://nowhere.com][backward].
|
93
|
+
|
94
|
+
-------------------------------------------
|
95
|
+
|
96
|
+
## Header with *style*
|
97
|
+
|
98
|
+
Non-matching links http://nowhere.com and nowhere.com.
|
@@ -0,0 +1,297 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
include Asuka
|
4
|
+
|
5
|
+
describe "Parser" do
|
6
|
+
before do
|
7
|
+
@parser = Parser.new
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "types" do
|
11
|
+
before do
|
12
|
+
@content_as_string = "some\ntext"
|
13
|
+
@content_as_array = ["some","text"]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "allows String" do
|
17
|
+
StringIO.should_receive(:new).with(@content_as_string).and_return(stub(:readlines => @content_as_array))
|
18
|
+
@parser.parse("some\ntext").should == [Paragraph.new(@content_as_array)]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "allows Array[String]" do
|
22
|
+
StringIO.should_receive(:new).never
|
23
|
+
@parser.parse(["some","text"]).should == [Paragraph.new(@content_as_array)]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "escaping" do
|
28
|
+
it "allows for reserved HTML characters" do
|
29
|
+
result = @parser.parse(['AT&T, <body>, 4 > 5, "something"'])
|
30
|
+
result.should == [Paragraph.new(['AT&T, <body>, 4 > 5, "something"'])]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "uniform pattern" do
|
35
|
+
describe "of paragraph" do
|
36
|
+
it "with 1 line" do
|
37
|
+
result = @parser.parse(["some"])
|
38
|
+
result.should == [Paragraph.new(["some"])]
|
39
|
+
end
|
40
|
+
|
41
|
+
it "with many lines" do
|
42
|
+
result = @parser.parse(["some","more","text"])
|
43
|
+
result.should == [Paragraph.new(["some","more","text"])]
|
44
|
+
end
|
45
|
+
|
46
|
+
it "with many lines (and spacing)" do
|
47
|
+
result = @parser.parse([" some"," more"," text"])
|
48
|
+
result.should == [Paragraph.new(["some","more","text"])]
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should render styles" do
|
52
|
+
result = @parser.parse(["some","*more*","text"])
|
53
|
+
result.should == [Paragraph.new(["some","<em>more</em>","text"])]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "of blockquote" do
|
58
|
+
it "with 1 line" do
|
59
|
+
result = @parser.parse(["> some"])
|
60
|
+
result.should == [Blockquote.new(["some"])]
|
61
|
+
end
|
62
|
+
|
63
|
+
it "with many lines" do
|
64
|
+
result = @parser.parse(["> some","> more","> text"])
|
65
|
+
result.should == [Blockquote.new(["some","more","text"])]
|
66
|
+
end
|
67
|
+
|
68
|
+
it "with many lines (and spacing)" do
|
69
|
+
result = @parser.parse([" > some"," > more"," > text"])
|
70
|
+
result.should == [Blockquote.new(["some","more","text"])]
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should render styles" do
|
74
|
+
result = @parser.parse(["> some","> *more*","> text"])
|
75
|
+
result.should == [Blockquote.new(["some","<em>more</em>","text"])]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "of unordered list" do
|
80
|
+
it "with 1 line" do
|
81
|
+
result = @parser.parse(["* some"])
|
82
|
+
result.should == [UnorderedList.new(["some"])]
|
83
|
+
end
|
84
|
+
|
85
|
+
it "with many lines" do
|
86
|
+
result = @parser.parse(["* some","* more","* text"])
|
87
|
+
result.should == [UnorderedList.new(["some","more","text"])]
|
88
|
+
end
|
89
|
+
|
90
|
+
it "with many lines (and spacing)" do
|
91
|
+
result = @parser.parse([" * some"," * more"," * text"])
|
92
|
+
result.should == [UnorderedList.new(["some","more","text"])]
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should render styles" do
|
96
|
+
result = @parser.parse(["* some","* *more*","* text"])
|
97
|
+
result.should == [UnorderedList.new(["some","<em>more</em>","text"])]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "of rule (primary syntax)" do
|
102
|
+
it "should create a rule (3)" do
|
103
|
+
result = @parser.parse(["---"])
|
104
|
+
result.should == [Rule.new]
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should create a rule (4)" do
|
108
|
+
result = @parser.parse(["----"])
|
109
|
+
result.should == [Rule.new]
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should create a rule (*)" do
|
113
|
+
result = @parser.parse(["--------------"])
|
114
|
+
result.should == [Rule.new]
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should create a rule (4 and spacing)" do
|
118
|
+
result = @parser.parse([" ---- "])
|
119
|
+
result.should == [Rule.new]
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "of rule (alternative syntax)" do
|
124
|
+
it "should create a rule (3)" do
|
125
|
+
result = @parser.parse(["___"])
|
126
|
+
result.should == [Rule.new]
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should create a rule (4)" do
|
130
|
+
result = @parser.parse(["____"])
|
131
|
+
result.should == [Rule.new]
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should create a rule (*)" do
|
135
|
+
result = @parser.parse(["______________"])
|
136
|
+
result.should == [Rule.new]
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should create a rule (4 and spacing)" do
|
140
|
+
result = @parser.parse([" ____ "])
|
141
|
+
result.should == [Rule.new]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "of header" do
|
146
|
+
it "should create a header (level 1)" do
|
147
|
+
result = @parser.parse(["# some text"])
|
148
|
+
result.should == [Header.new("some text", 1)]
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should create a header (level 2)" do
|
152
|
+
result = @parser.parse(["## some text"])
|
153
|
+
result.should == [Header.new("some text", 2)]
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should create a header (level 6)" do
|
157
|
+
result = @parser.parse(["###### some text"])
|
158
|
+
result.should == [Header.new("some text", 6)]
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should create a header (level 2 and spacing)" do
|
162
|
+
result = @parser.parse([" ## some text"])
|
163
|
+
result.should == [Header.new("some text", 2)]
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should render styles" do
|
167
|
+
result = @parser.parse(["## some *text*"])
|
168
|
+
result.should == [Header.new("some <em>text</em>", 2)]
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "mixed patterns" do
|
174
|
+
describe "of paragraph, paragraph" do
|
175
|
+
it "should detangle them" do
|
176
|
+
result = @parser.parse(["some text","","more text"])
|
177
|
+
result.should == [Paragraph.new(["some text"]),
|
178
|
+
Paragraph.new(["more text"])]
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "of paragraph, (many blanks), paragraph" do
|
183
|
+
it "should detangle them" do
|
184
|
+
result = @parser.parse(["some text","","","","","","more text"])
|
185
|
+
result.should == [Paragraph.new(["some text"]),
|
186
|
+
Paragraph.new(["more text"])]
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "of paragraph, list, paragraph" do
|
191
|
+
it "should detangle them" do
|
192
|
+
result = @parser.parse(["some text","* a list","more text"])
|
193
|
+
result.should == [Paragraph.new(["some text"]),
|
194
|
+
UnorderedList.new(["a list"]),
|
195
|
+
Paragraph.new(["more text"])]
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "of paragraph, blockquote, paragraph" do
|
200
|
+
it "should detangle them" do
|
201
|
+
result = @parser.parse(["some text","> a quote","more text"])
|
202
|
+
result.should == [Paragraph.new(["some text"]),
|
203
|
+
Blockquote.new(["a quote"]),
|
204
|
+
Paragraph.new(["more text"])]
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "of paragraph, rule, header, list" do
|
209
|
+
it "should detangle them" do
|
210
|
+
result = @parser.parse(["some text","---","# header", "* a list","* of 2 items"])
|
211
|
+
result.should == [Paragraph.new(["some text"]),
|
212
|
+
Rule.new,
|
213
|
+
Header.new("header", 1),
|
214
|
+
UnorderedList.new(["a list", "of 2 items"])]
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe "miss matches" do
|
220
|
+
describe "of unordered list" do
|
221
|
+
it "should be a paragraph (mising space)" do
|
222
|
+
result = @parser.parse(["*a list","*that isn't one"])
|
223
|
+
result.should == [Paragraph.new(["*a list","*that isn't one"])]
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should be a paragraph (double)" do
|
227
|
+
result = @parser.parse(["** a list","** that isn't one"])
|
228
|
+
result.should == [Paragraph.new(["** a list","** that isn't one"])]
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
describe "of blockquote" do
|
233
|
+
it "should be a paragraph (missing space)" do
|
234
|
+
result = @parser.parse([">quote",">more text"])
|
235
|
+
result.should == [Paragraph.new([">quote",">more text"])]
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
describe "of rule (primary syntax)" do
|
240
|
+
it "should be a paragraph (1)" do
|
241
|
+
result = @parser.parse(["-"])
|
242
|
+
result.should == [Paragraph.new(["-"])]
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should be a paragraph (2)" do
|
246
|
+
result = @parser.parse(["--"])
|
247
|
+
result.should == [Paragraph.new(["--"])]
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should be a paragraph (3 w/ text)" do
|
251
|
+
result = @parser.parse(["--- text"])
|
252
|
+
result.should == [Paragraph.new(["--- text"])]
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
describe "of rule (alternative syntax)" do
|
257
|
+
it "should be a paragraph (1)" do
|
258
|
+
result = @parser.parse(["_"])
|
259
|
+
result.should == [Paragraph.new(["_"])]
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should be a paragraph (2)" do
|
263
|
+
result = @parser.parse(["__"])
|
264
|
+
result.should == [Paragraph.new(["__"])]
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should be a paragraph (3 w/ text)" do
|
268
|
+
result = @parser.parse(["___ text"])
|
269
|
+
result.should == [Paragraph.new(["___ text"])]
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
describe "of rule (mixed syntax)" do
|
274
|
+
it "should be a paragraph (3)" do
|
275
|
+
result = @parser.parse(["_-_"])
|
276
|
+
result.should == [Paragraph.new(["_-_"])]
|
277
|
+
end
|
278
|
+
|
279
|
+
it "should be a paragraph (*)" do
|
280
|
+
result = @parser.parse(["----____-----"])
|
281
|
+
result.should == [Paragraph.new(["----____-----"])]
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
describe "of header" do
|
286
|
+
it "should be a paragraph (missing space)" do
|
287
|
+
result = @parser.parse(["#header"])
|
288
|
+
result.should == [Paragraph.new(["#header"])]
|
289
|
+
end
|
290
|
+
|
291
|
+
it "should be a paragraph (7)" do
|
292
|
+
result = @parser.parse(["####### header"])
|
293
|
+
result.should == [Paragraph.new(["####### header"])]
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Accumulator" do
|
4
|
+
describe "that is brand new" do
|
5
|
+
before do
|
6
|
+
@acc = Asuka::Accumulator.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "doesn't expose lines" do
|
10
|
+
lambda {
|
11
|
+
@acc.lines
|
12
|
+
}.should raise_error(NoMethodError)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "starts out empty" do
|
16
|
+
@acc.should be_empty
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns nothing" do
|
20
|
+
@acc.flush.should == []
|
21
|
+
end
|
22
|
+
|
23
|
+
it "doesn't yield" do
|
24
|
+
flag = false
|
25
|
+
@acc.flush { |lines| flag = true }
|
26
|
+
flag.should == false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "that is pushed to (once)" do
|
31
|
+
before do
|
32
|
+
@acc = Asuka::Accumulator.new
|
33
|
+
@lines = ["text"]
|
34
|
+
@lines.each { |line| @acc.push(line) }
|
35
|
+
end
|
36
|
+
|
37
|
+
it "is not empty" do
|
38
|
+
@acc.should_not be_empty
|
39
|
+
end
|
40
|
+
|
41
|
+
it "becomes empty after flushing" do
|
42
|
+
@acc.flush
|
43
|
+
@acc.should be_empty
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns what was pushed" do
|
47
|
+
@acc.flush.should == @lines
|
48
|
+
end
|
49
|
+
|
50
|
+
it "yield what was pushed" do
|
51
|
+
@acc.flush { |lines| lines.should == @lines }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "that is pushed to (several times)" do
|
56
|
+
before do
|
57
|
+
@acc = Asuka::Accumulator.new
|
58
|
+
@lines = ["some","more","text"]
|
59
|
+
@lines.each { |line| @acc.push(line) }
|
60
|
+
end
|
61
|
+
|
62
|
+
it "is not empty" do
|
63
|
+
@acc.should_not be_empty
|
64
|
+
end
|
65
|
+
|
66
|
+
it "becomes empty after flushing" do
|
67
|
+
@acc.flush
|
68
|
+
@acc.should be_empty
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns what was pushed" do
|
72
|
+
@acc.flush.should == @lines
|
73
|
+
end
|
74
|
+
|
75
|
+
it "yield what was pushed" do
|
76
|
+
@acc.flush { |lines| lines.should == @lines }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|