arti_mark 0.1.beta3 → 0.1.beta5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -4
- data/README.md +108 -7
- data/lib/arti_mark.rb +30 -35
- data/lib/arti_mark/html/abstract_item_writer.rb +14 -0
- data/lib/arti_mark/html/context.rb +100 -79
- data/lib/arti_mark/html/generator.rb +51 -34
- data/lib/arti_mark/html/header_writer.rb +3 -0
- data/lib/arti_mark/html/pages.rb +56 -0
- data/lib/arti_mark/html/paragraph_writer.rb +52 -0
- data/lib/arti_mark/parser.kpeg +34 -6
- data/lib/arti_mark/parser.kpeg.rb +1015 -128
- data/lib/arti_mark/version.rb +1 -1
- data/spec/arti_mark_spec.rb +338 -82
- data/spec/created_files/.gitignore +1 -0
- data/spec/fixture/test_src_ja.arti +3 -1
- metadata +7 -18
- data/lib/arti_mark/article_parser.rb +0 -12
- data/lib/arti_mark/base_parser.rb +0 -26
- data/lib/arti_mark/block_image_parser.rb +0 -27
- data/lib/arti_mark/command_lexer.rb +0 -83
- data/lib/arti_mark/common_block_parser.rb +0 -36
- data/lib/arti_mark/definition_list_parser.rb +0 -23
- data/lib/arti_mark/div_parser.rb +0 -12
- data/lib/arti_mark/head_parser.rb +0 -20
- data/lib/arti_mark/html/result.rb +0 -27
- data/lib/arti_mark/list_parser.rb +0 -27
- data/lib/arti_mark/ordered_list_parser.rb +0 -14
- data/lib/arti_mark/paragraph_parser.rb +0 -30
- data/lib/arti_mark/section_parser.rb +0 -12
- data/lib/arti_mark/syntax.rb +0 -147
- data/lib/arti_mark/universal_block_parser.rb +0 -10
- data/lib/arti_mark/unordered_list_parser.rb +0 -14
data/lib/arti_mark/version.rb
CHANGED
data/spec/arti_mark_spec.rb
CHANGED
@@ -8,8 +8,8 @@ describe ArtiMark do
|
|
8
8
|
describe 'convert' do
|
9
9
|
it 'should generate valid xhtml' do
|
10
10
|
text = 'some text'
|
11
|
-
artimark = ArtiMark::Document.
|
12
|
-
xhtml = Nokogiri::XML::Document.parse(artimark.
|
11
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
12
|
+
xhtml = Nokogiri::XML::Document.parse(artimark.html[0])
|
13
13
|
expect(xhtml.root.name).to eq('html')
|
14
14
|
expect(xhtml.root.namespaces['xmlns']).to eq('http://www.w3.org/1999/xhtml')
|
15
15
|
expect(xhtml.root['xml:lang']).to eq('ja')
|
@@ -19,8 +19,8 @@ describe ArtiMark do
|
|
19
19
|
end
|
20
20
|
it 'should convert simple paragraph' do
|
21
21
|
text = "ここから、パラグラフがはじまります。\n「二行目です。」\n三行目です。\n\n\n ここから、次のパラグラフです。"
|
22
|
-
artimark = ArtiMark::Document.
|
23
|
-
converted = artimark.
|
22
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
23
|
+
converted = artimark.html
|
24
24
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
25
25
|
expect(body.element_children.size).to eq 2
|
26
26
|
expect(body.element_children[0].selector_and_children).to eq(
|
@@ -36,10 +36,48 @@ describe ArtiMark do
|
|
36
36
|
['p', 'ここから、次のパラグラフです。']]
|
37
37
|
)
|
38
38
|
end
|
39
|
+
it 'should convert simple paragraph in english mode' do
|
40
|
+
text = "paragraph begins.\n2nd line.\n 3rd line.\n\n\n next paragraph."
|
41
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'en', :title => 'the title')
|
42
|
+
converted = artimark.html
|
43
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
44
|
+
expect(body.element_children.size).to eq 2
|
45
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
46
|
+
['p',
|
47
|
+
'paragraph begins.', ['br', ''],
|
48
|
+
'2nd line.', ['br', ''],
|
49
|
+
'3rd line.'
|
50
|
+
]
|
51
|
+
)
|
52
|
+
|
53
|
+
expect(body.element_children[1].selector_and_children).to eq(
|
54
|
+
['p', 'next paragraph.']
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should convert simple paragraph in japanese mode, but paragraph mode is default' do
|
59
|
+
text = "paragraph begins.\n2nd line.\n 3rd line.\n\n\n next paragraph."
|
60
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title', :paragraph_style => :default)
|
61
|
+
converted = artimark.html
|
62
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
63
|
+
expect(body.element_children.size).to eq 2
|
64
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
65
|
+
['p',
|
66
|
+
'paragraph begins.', ['br', ''],
|
67
|
+
'2nd line.', ['br', ''],
|
68
|
+
'3rd line.'
|
69
|
+
]
|
70
|
+
)
|
71
|
+
|
72
|
+
expect(body.element_children[1].selector_and_children).to eq(
|
73
|
+
['p', 'next paragraph.']
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
39
77
|
it 'should convert paragraph with header' do
|
40
78
|
text = "h1: タイトルです。\r\nここから、パラグラフがはじまります。\n\nh2.column:ふたつめの見出しです。\n ここから、次のパラグラフです。\nh3.third.foo: クラスが複数ある見出しです"
|
41
|
-
artimark = ArtiMark::Document.
|
42
|
-
converted = artimark.
|
79
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
80
|
+
converted = artimark.html
|
43
81
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
44
82
|
expect(body.element_children.size).to eq 5
|
45
83
|
expect(body.element_children[0].a).to eq ['h1', 'タイトルです。']
|
@@ -59,8 +97,8 @@ describe ArtiMark do
|
|
59
97
|
|
60
98
|
it 'should convert div and paragraph' do
|
61
99
|
text = "d {\n1st line. \n}"
|
62
|
-
artimark = ArtiMark::Document.
|
63
|
-
converted = artimark.
|
100
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the document title')
|
101
|
+
converted = artimark.html
|
64
102
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
65
103
|
expect(body.element_children[0].selector_and_children).to eq(
|
66
104
|
['div',
|
@@ -73,8 +111,8 @@ describe ArtiMark do
|
|
73
111
|
|
74
112
|
it 'should convert div without pgroup' do
|
75
113
|
text = "d(wo-pgroup) {\n1st line. \n}"
|
76
|
-
artimark = ArtiMark::Document.
|
77
|
-
converted = artimark.
|
114
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
115
|
+
converted = artimark.html
|
78
116
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
79
117
|
expect(body.element_children[0].selector_and_children).to eq(
|
80
118
|
['div',
|
@@ -85,8 +123,8 @@ describe ArtiMark do
|
|
85
123
|
|
86
124
|
it 'should nest div without pgroup' do
|
87
125
|
text = "d(wo-pgroup) {\nd {\nnested.\n} \n}"
|
88
|
-
artimark = ArtiMark::Document.
|
89
|
-
converted = artimark.
|
126
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
127
|
+
converted = artimark.html
|
90
128
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
91
129
|
expect(body.element_children[0].selector_and_children).to eq(
|
92
130
|
['div',
|
@@ -99,8 +137,8 @@ describe ArtiMark do
|
|
99
137
|
|
100
138
|
it 'should nest div without pgroup and with pgroup' do
|
101
139
|
text = "d(wo-pgroup) {\nd {\nnested.\n} \n}\nd {\nin pgroup\n}"
|
102
|
-
artimark = ArtiMark::Document.
|
103
|
-
converted = artimark.
|
140
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
141
|
+
converted = artimark.html
|
104
142
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
105
143
|
expect(body.element_children[0].selector_and_children).to eq(
|
106
144
|
['div',
|
@@ -119,8 +157,8 @@ describe ArtiMark do
|
|
119
157
|
|
120
158
|
it 'should convert div with class' do
|
121
159
|
text = "d.preface-one {\n h1: title.\n}"
|
122
|
-
artimark = ArtiMark::Document.
|
123
|
-
converted = artimark.
|
160
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
161
|
+
converted = artimark.html
|
124
162
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
125
163
|
expect(body.element_children[0].selector_and_children).to eq(
|
126
164
|
['div.preface-one',
|
@@ -131,8 +169,8 @@ describe ArtiMark do
|
|
131
169
|
|
132
170
|
it 'should convert div with id and class' do
|
133
171
|
text = "d#thecontents.preface-one {\nh1: title.\n}"
|
134
|
-
artimark = ArtiMark::Document.
|
135
|
-
converted = artimark.
|
172
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
173
|
+
converted = artimark.html
|
136
174
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
137
175
|
expect(body.element_children[0].selector_and_children).to eq(
|
138
176
|
['div#thecontents.preface-one',
|
@@ -143,8 +181,8 @@ describe ArtiMark do
|
|
143
181
|
|
144
182
|
it 'should convert nested div' do
|
145
183
|
text = "d.preface {\n outer div. \n d.nested {\n nested!\n}\nouter div again.\n}"
|
146
|
-
artimark = ArtiMark::Document.
|
147
|
-
converted = artimark.
|
184
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
185
|
+
converted = artimark.html
|
148
186
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
149
187
|
expect(body.element_children[0].selector_and_children).to eq(
|
150
188
|
['div.preface',
|
@@ -165,8 +203,8 @@ describe ArtiMark do
|
|
165
203
|
|
166
204
|
it 'should convert article' do
|
167
205
|
text = "art {\n in the article.\n}"
|
168
|
-
artimark = ArtiMark::Document.
|
169
|
-
converted = artimark.
|
206
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
207
|
+
converted = artimark.html
|
170
208
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
171
209
|
expect(body.element_children[0].selector_and_children).to eq(
|
172
210
|
['article',
|
@@ -179,8 +217,22 @@ describe ArtiMark do
|
|
179
217
|
|
180
218
|
it 'should convert article with other notation' do
|
181
219
|
text = "arti {\n in the article.\n}"
|
182
|
-
artimark = ArtiMark::Document.
|
183
|
-
converted = artimark.
|
220
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
221
|
+
converted = artimark.html
|
222
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
223
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
224
|
+
['article',
|
225
|
+
['div.pgroup',
|
226
|
+
['p', 'in the article.']
|
227
|
+
]
|
228
|
+
]
|
229
|
+
)
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'should convert article with yet anther notation' do
|
233
|
+
text = "article {\n in the article.\n}"
|
234
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
235
|
+
converted = artimark.html
|
184
236
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
185
237
|
expect(body.element_children[0].selector_and_children).to eq(
|
186
238
|
['article',
|
@@ -191,11 +243,60 @@ describe ArtiMark do
|
|
191
243
|
)
|
192
244
|
end
|
193
245
|
|
246
|
+
it 'should convert section ' do
|
247
|
+
text = "art {\nsec {\n section in the article. \n}\n}"
|
248
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
249
|
+
converted = artimark.html
|
250
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
251
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
252
|
+
['article',
|
253
|
+
['section',
|
254
|
+
['div.pgroup',
|
255
|
+
['p', 'section in the article.']
|
256
|
+
]
|
257
|
+
]
|
258
|
+
]
|
259
|
+
)
|
260
|
+
end
|
261
|
+
|
262
|
+
it 'should convert section with other notation' do
|
263
|
+
text = "art {\nsect {\n section in the article. \n}\n}"
|
264
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
265
|
+
converted = artimark.html
|
266
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
267
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
268
|
+
['article',
|
269
|
+
['section',
|
270
|
+
['div.pgroup',
|
271
|
+
['p', 'section in the article.']
|
272
|
+
]
|
273
|
+
]
|
274
|
+
]
|
275
|
+
)
|
276
|
+
end
|
277
|
+
|
278
|
+
it 'should convert section with yet other notation' do
|
279
|
+
text = "art {\nsection {\n section in the article. \n}\n}"
|
280
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
281
|
+
converted = artimark.html
|
282
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
283
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
284
|
+
['article',
|
285
|
+
['section',
|
286
|
+
['div.pgroup',
|
287
|
+
['p', 'section in the article.']
|
288
|
+
]
|
289
|
+
]
|
290
|
+
]
|
291
|
+
)
|
292
|
+
end
|
293
|
+
|
294
|
+
|
194
295
|
|
195
296
|
it 'should handle block image' do
|
196
297
|
text = "this is normal line.\nimage(./image1.jpg, alt text): caption text"
|
197
|
-
artimark = ArtiMark::Document.
|
198
|
-
converted = artimark.
|
298
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
299
|
+
converted = artimark.html
|
199
300
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
200
301
|
expect(body.element_children[0].selector_and_children).to eq(
|
201
302
|
['div.pgroup',
|
@@ -212,8 +313,8 @@ describe ArtiMark do
|
|
212
313
|
|
213
314
|
it 'should handle block image with before caption' do
|
214
315
|
text = "this is normal line.\nimage(./image1.jpg, alt text, caption_before: true): caption text"
|
215
|
-
artimark = ArtiMark::Document.
|
216
|
-
converted = artimark.
|
316
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
317
|
+
converted = artimark.html
|
217
318
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
218
319
|
expect(body.element_children[0].selector_and_children).to eq(
|
219
320
|
['div.pgroup',
|
@@ -230,8 +331,8 @@ describe ArtiMark do
|
|
230
331
|
|
231
332
|
it 'should handle block image without caption' do
|
232
333
|
text = "this is normal line.\nimage(./image1.jpg, alt text):"
|
233
|
-
artimark = ArtiMark::Document.
|
234
|
-
converted = artimark.
|
334
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
335
|
+
converted = artimark.html
|
235
336
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
236
337
|
expect(body.element_children[0].selector_and_children).to eq(
|
237
338
|
['div.pgroup',
|
@@ -247,8 +348,8 @@ describe ArtiMark do
|
|
247
348
|
|
248
349
|
it 'should handle page change article' do
|
249
350
|
text = "this is start.\nnewpage(page changed):\nthis is second page.\nnewpage:\nand the third."
|
250
|
-
artimark = ArtiMark::Document.
|
251
|
-
converted = artimark.
|
351
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
352
|
+
converted = artimark.html
|
252
353
|
expect(converted.size).to eq 3
|
253
354
|
body1 = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
254
355
|
expect(body1.element_children[0].selector_and_children).to eq(
|
@@ -278,8 +379,8 @@ describe ArtiMark do
|
|
278
379
|
|
279
380
|
it 'should handle stylesheets' do
|
280
381
|
text = "d.styled {\n this is styled document.\n}"
|
281
|
-
artimark = ArtiMark::Document.
|
282
|
-
converted = artimark.
|
382
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the document title', :stylesheets => ['reset.css', 'mystyle.css'])
|
383
|
+
converted = artimark.html
|
283
384
|
head = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:head')
|
284
385
|
expect(head.element_children[0].a).to eq ['title', 'the document title']
|
285
386
|
expect(head.element_children[1].a).to eq ["link[rel='stylesheet'][type='text/css'][href='reset.css']", '']
|
@@ -288,8 +389,8 @@ describe ArtiMark do
|
|
288
389
|
|
289
390
|
it 'should handle link' do
|
290
391
|
text = " link to [link(http://github.com/skoji/artimark){artimark repository}]. \ncan you see this?"
|
291
|
-
artimark = ArtiMark::Document.
|
292
|
-
converted = artimark.
|
392
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
393
|
+
converted = artimark.html
|
293
394
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
294
395
|
expect(body.element_children[0].selector_and_children).to eq(
|
295
396
|
['div.pgroup',
|
@@ -305,8 +406,8 @@ describe ArtiMark do
|
|
305
406
|
|
306
407
|
it 'should handle link with l' do
|
307
408
|
text = "link to [l(http://github.com/skoji/artimark){artimark repository}]. \ncan you see this?"
|
308
|
-
artimark = ArtiMark::Document.
|
309
|
-
converted = artimark.
|
409
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
410
|
+
converted = artimark.html
|
310
411
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
311
412
|
expect(body.element_children[0].selector_and_children).to eq(
|
312
413
|
['div.pgroup',
|
@@ -322,8 +423,8 @@ describe ArtiMark do
|
|
322
423
|
|
323
424
|
it 'should handle custom paragraph' do
|
324
425
|
text = "this is normal line.\np.custom: this text is in custom class."
|
325
|
-
artimark = ArtiMark::Document.
|
326
|
-
converted = artimark.
|
426
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
427
|
+
converted = artimark.html
|
327
428
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
328
429
|
expect(body.element_children[0].selector_and_children).to eq(
|
329
430
|
['div.pgroup',
|
@@ -335,8 +436,8 @@ describe ArtiMark do
|
|
335
436
|
|
336
437
|
it 'should handle span' do
|
337
438
|
text = "p.custom: this text is in [s.keyword{custom}] class."
|
338
|
-
artimark = ArtiMark::Document.
|
339
|
-
converted = artimark.
|
439
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
440
|
+
converted = artimark.html
|
340
441
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
341
442
|
expect(body.element_children[0].selector_and_children).to eq(
|
342
443
|
['div.pgroup',
|
@@ -347,8 +448,8 @@ describe ArtiMark do
|
|
347
448
|
|
348
449
|
it 'should handle any block' do
|
349
450
|
text = "this is normal line.\ncite {\n this block should be in cite. \n}"
|
350
|
-
artimark = ArtiMark::Document.
|
351
|
-
converted = artimark.
|
451
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
452
|
+
converted = artimark.html
|
352
453
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
353
454
|
expect(body.element_children[0].selector_and_children).to eq(
|
354
455
|
['div.pgroup',
|
@@ -366,8 +467,8 @@ describe ArtiMark do
|
|
366
467
|
|
367
468
|
it 'should handle inline image' do
|
368
469
|
text = "simple image [img(./image1.jpg, alt)]."
|
369
|
-
artimark = ArtiMark::Document.
|
370
|
-
converted = artimark.
|
470
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
471
|
+
converted = artimark.html
|
371
472
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
372
473
|
expect(body.element_children[0].selector_and_children).to eq(
|
373
474
|
['div.pgroup',
|
@@ -378,8 +479,8 @@ describe ArtiMark do
|
|
378
479
|
|
379
480
|
it 'should handle any inline' do
|
380
481
|
text = "should be [strong{marked as strong}]."
|
381
|
-
artimark = ArtiMark::Document.
|
382
|
-
converted = artimark.
|
482
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
483
|
+
converted = artimark.html
|
383
484
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
384
485
|
expect(body.element_children[0].selector_and_children).to eq(
|
385
486
|
['div.pgroup',
|
@@ -389,16 +490,16 @@ describe ArtiMark do
|
|
389
490
|
|
390
491
|
it 'should convert inline command within line block' do
|
391
492
|
text = "h1: [tcy{20}]縦中横タイトル"
|
392
|
-
artimark = ArtiMark::Document.
|
393
|
-
converted = artimark.
|
493
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
494
|
+
converted = artimark.html
|
394
495
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
395
496
|
expect(body.element_children[0].selector_and_children).to eq ['h1', ['span.tcy', '20'], '縦中横タイトル']
|
396
497
|
end
|
397
498
|
|
398
499
|
it 'should handle ruby' do
|
399
500
|
text = "[ruby(とんぼ){蜻蛉}]の[ruby(めがね){眼鏡}]はみずいろめがね"
|
400
|
-
artimark = ArtiMark::Document.
|
401
|
-
converted = artimark.
|
501
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
502
|
+
converted = artimark.html
|
402
503
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
403
504
|
expect(body.element_children[0].selector_and_children).to eq ['div.pgroup', ['p',
|
404
505
|
['ruby', '蜻蛉', ['rp','('],['rt','とんぼ'],['rp', ')']],
|
@@ -409,8 +510,8 @@ describe ArtiMark do
|
|
409
510
|
|
410
511
|
it 'should handle tatechuyoko' do
|
411
512
|
text = "[tcy{10}]年前のことだった"
|
412
|
-
artimark = ArtiMark::Document.
|
413
|
-
converted = artimark.
|
513
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
514
|
+
converted = artimark.html
|
414
515
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
415
516
|
expect(body.element_children[0].selector_and_children).to eq(
|
416
517
|
['div.pgroup',
|
@@ -420,8 +521,8 @@ describe ArtiMark do
|
|
420
521
|
|
421
522
|
it 'should handle ordered list ' do
|
422
523
|
text = "this is normal line.\n1: for the 1st.\n2: secondly, blah.\n3: and last...\nthe ordered list ends."
|
423
|
-
artimark = ArtiMark::Document.
|
424
|
-
converted = artimark.
|
524
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
525
|
+
converted = artimark.html
|
425
526
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
426
527
|
expect(body.element_children.size).to eq 3
|
427
528
|
expect(body.element_children[0].selector_and_children).to eq(
|
@@ -442,8 +543,8 @@ describe ArtiMark do
|
|
442
543
|
|
443
544
|
it 'should handle unordered list ' do
|
444
545
|
text = "this is normal line.\n*: for the 1st.\n*: secondly, blah.\n*: and last...\nthe ordered list ends."
|
445
|
-
artimark = ArtiMark::Document.
|
446
|
-
converted = artimark.
|
546
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
547
|
+
converted = artimark.html
|
447
548
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
448
549
|
expect(body.element_children.size).to eq 3
|
449
550
|
expect(body.element_children[0].selector_and_children).to eq(
|
@@ -464,8 +565,8 @@ describe ArtiMark do
|
|
464
565
|
|
465
566
|
it 'should handle definition list ' do
|
466
567
|
text = "this is normal line.\n;: 1st : this is the first definition\n;: 2nd : blah :blah.\n;: 3rd: this term is the last.\nthe list ends."
|
467
|
-
artimark = ArtiMark::Document.
|
468
|
-
converted = artimark.
|
568
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
569
|
+
converted = artimark.html
|
469
570
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
470
571
|
expect(body.element_children.size).to eq 3
|
471
572
|
expect(body.element_children[0].selector_and_children).to eq(
|
@@ -486,8 +587,8 @@ describe ArtiMark do
|
|
486
587
|
|
487
588
|
it 'should escape html' do
|
488
589
|
text = ";:definition<div>:</div>&"
|
489
|
-
artimark = ArtiMark::Document.
|
490
|
-
converted = artimark.
|
590
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
591
|
+
converted = artimark.html
|
491
592
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
492
593
|
expect(body.element_children[0].selector_and_children).to eq(
|
493
594
|
['dl',
|
@@ -497,8 +598,8 @@ describe ArtiMark do
|
|
497
598
|
|
498
599
|
it 'should specify stylesheets' do
|
499
600
|
text = "stylesheets:css/default.css, css/specific.css, css/iphone.css:(only screen and (min-device-width : 320px) and (max-device-width : 480px))\n\ntext."
|
500
|
-
artimark = ArtiMark::Document.
|
501
|
-
converted = artimark.
|
601
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the document title')
|
602
|
+
converted = artimark.html
|
502
603
|
head = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:head')
|
503
604
|
expect(head.element_children[0].a).to eq ['title', 'the document title']
|
504
605
|
expect(head.element_children[1].a).to eq ["link[rel='stylesheet'][type='text/css'][href='css/default.css']", '']
|
@@ -514,25 +615,43 @@ describe ArtiMark do
|
|
514
615
|
|
515
616
|
it 'should specify title' do
|
516
617
|
text = "title:the title of the book in the text.\n\ntext."
|
517
|
-
artimark = ArtiMark::Document.
|
518
|
-
converted = artimark.
|
618
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
619
|
+
converted = artimark.html
|
519
620
|
head = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:head')
|
520
621
|
expect(head.element_children[0].a).to eq ['title', 'the title of the book in the text.']
|
622
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
623
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
624
|
+
['div.pgroup',
|
625
|
+
['p',
|
626
|
+
'text.']])
|
627
|
+
|
521
628
|
end
|
522
629
|
|
523
|
-
it 'should specify
|
524
|
-
text = "
|
525
|
-
artimark = ArtiMark::Document.
|
526
|
-
converted = artimark.
|
527
|
-
|
528
|
-
|
630
|
+
it 'should specify title on each page' do
|
631
|
+
text = "title:page1\n\n1st page.\nnewpage:\ntitle:page2\nh1:2nd page"
|
632
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title', :paragraph_style => :use_paragraph_group)
|
633
|
+
converted = artimark.html
|
634
|
+
# 1st page
|
635
|
+
head = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:head')
|
636
|
+
expect(head.element_children[0].a).to eq ['title', 'page1']
|
637
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
638
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
639
|
+
['div.pgroup',
|
640
|
+
['p',
|
641
|
+
'1st page.']])
|
642
|
+
# 2nd page
|
643
|
+
head = Nokogiri::XML::Document.parse(converted[1]).root.at_xpath('xmlns:head')
|
644
|
+
expect(head.element_children[0].a).to eq ['title', 'page2']
|
645
|
+
body = Nokogiri::XML::Document.parse(converted[1]).root.at_xpath('xmlns:body')
|
646
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
647
|
+
['h1',"2nd page"])
|
529
648
|
end
|
530
649
|
|
531
650
|
|
532
651
|
it 'should ignore comments' do
|
533
|
-
text = "
|
534
|
-
artimark = ArtiMark::Document.
|
535
|
-
converted = artimark.
|
652
|
+
text = "# この行はコメントです\nここから、パラグラフがはじまります。\n # これもコメント\n「二行目です。」\n三行目です。\n\n# これもコメント\n\n ここから、次のパラグラフです。"
|
653
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
654
|
+
converted = artimark.html
|
536
655
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
537
656
|
expect(body.element_children.size).to eq 2
|
538
657
|
|
@@ -552,12 +671,14 @@ describe ArtiMark do
|
|
552
671
|
|
553
672
|
it 'should handle preprocessor' do
|
554
673
|
text = "pre-preprocess text"
|
555
|
-
artimark = ArtiMark::Document.
|
556
|
-
|
557
|
-
|
558
|
-
|
674
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title') do
|
675
|
+
|arti|
|
676
|
+
arti.preprocessor do
|
677
|
+
|text|
|
678
|
+
text.gsub('pre-preprocess', 'post-process')
|
679
|
+
end
|
559
680
|
end
|
560
|
-
converted = artimark.
|
681
|
+
converted = artimark.html
|
561
682
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
562
683
|
expect(body.element_children[0].selector_and_children).to eq(
|
563
684
|
['div.pgroup',
|
@@ -568,8 +689,8 @@ describe ArtiMark do
|
|
568
689
|
|
569
690
|
it 'should convert h1 in article after title' do
|
570
691
|
text = "stylesheets: css/default.css\ntitle: foo\narticle.atogaki {\n\nh1: あとがき。\n\natogaki\n}"
|
571
|
-
artimark = ArtiMark::Document.
|
572
|
-
converted = artimark.
|
692
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
693
|
+
converted = artimark.html
|
573
694
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
574
695
|
expect(body.element_children[0].selector_and_children).to eq(
|
575
696
|
["article.atogaki",
|
@@ -579,6 +700,141 @@ describe ArtiMark do
|
|
579
700
|
)
|
580
701
|
end
|
581
702
|
|
703
|
+
it 'should convert preformatted text' do
|
704
|
+
text = <<EOF
|
705
|
+
normal line.
|
706
|
+
pre <<END
|
707
|
+
d {
|
708
|
+
this will not converted to div or p or pgroup.
|
709
|
+
line_command: this will be not converted too.
|
710
|
+
}
|
711
|
+
END
|
712
|
+
EOF
|
713
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
714
|
+
converted = artimark.html
|
715
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
716
|
+
expect(body.element_children[0].selector_and_children).to eq(["div.pgroup", ["p", "normal line."]])
|
717
|
+
expect(body.element_children[1].selector_and_children).to eq(["pre", "d {\n this will not converted to div or p or pgroup.\nline_command: this will be not converted too.\n}"])
|
718
|
+
end
|
719
|
+
it 'should convert preformatted code' do
|
720
|
+
text = <<EOF
|
721
|
+
normal line.
|
722
|
+
precode <<END
|
723
|
+
d {
|
724
|
+
this will not converted to div or p or pgroup.
|
725
|
+
line_command: this will be not converted too.
|
726
|
+
}
|
727
|
+
END
|
728
|
+
normal line again.
|
729
|
+
EOF
|
730
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
731
|
+
converted = artimark.html
|
732
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
733
|
+
expect(body.element_children[0].selector_and_children).to eq(["div.pgroup", ["p", "normal line."]])
|
734
|
+
expect(body.element_children[1].selector_and_children).to eq(["pre", ["code", "d {\n this will not converted to div or p or pgroup.\nline_command: this will be not converted too.\n}"]])
|
735
|
+
expect(body.element_children[2].selector_and_children).to eq(["div.pgroup", ["p", "normal line again."]])
|
736
|
+
end
|
737
|
+
|
738
|
+
it 'should raise error' do
|
739
|
+
text = "d {\n block is\nd {\n nested but\nd {\n not terminated }"
|
740
|
+
expect { ArtiMark::Document.parse(text, :lang => 'ja', :title => 'foo') }.to raise_error KPeg::CompiledParser::ParseError
|
741
|
+
end
|
742
|
+
|
743
|
+
describe 'markdown style' do
|
744
|
+
it 'should convert markdown style heading' do
|
745
|
+
text = "=: タイトルです。\r\nこれは、セクションの中です。"
|
746
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
747
|
+
converted = artimark.html
|
748
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
749
|
+
expect(body.element_children.size).to eq 1
|
750
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
751
|
+
['section',
|
752
|
+
['h1', 'タイトルです。'],
|
753
|
+
['div.pgroup',
|
754
|
+
['p', 'これは、セクションの中です。']]]
|
755
|
+
)
|
756
|
+
end
|
757
|
+
it 'should markdown style heading interrupted by other headed section' do
|
758
|
+
text = "=: タイトルです。\r\nこれは、セクションの中です。\n =: また次のセクションです。\n次のセクションの中です。"
|
759
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
760
|
+
converted = artimark.html
|
761
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
762
|
+
expect(body.element_children.size).to eq 2
|
763
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
764
|
+
['section',
|
765
|
+
['h1', 'タイトルです。'],
|
766
|
+
['div.pgroup',
|
767
|
+
['p', 'これは、セクションの中です。']]])
|
768
|
+
expect(body.element_children[1].selector_and_children).to eq(
|
769
|
+
['section',
|
770
|
+
['h1', 'また次のセクションです。'],
|
771
|
+
['div.pgroup',
|
772
|
+
['p', '次のセクションの中です。']]]
|
773
|
+
)
|
774
|
+
end
|
775
|
+
it 'should markdown style heading not interrupted by other explicit section' do
|
776
|
+
text = "=: タイトルです。\r\nこれは、セクションの中です。\n section {\n h2: また次のセクションです。\n入れ子になります。\n}\nこのように。"
|
777
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
778
|
+
converted = artimark.html
|
779
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
780
|
+
expect(body.element_children.size).to eq 1
|
781
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
782
|
+
['section',
|
783
|
+
['h1', 'タイトルです。'],
|
784
|
+
['div.pgroup',
|
785
|
+
['p', 'これは、セクションの中です。']],
|
786
|
+
['section',
|
787
|
+
['h2', 'また次のセクションです。'],
|
788
|
+
['div.pgroup',
|
789
|
+
['p', '入れ子になります。']]],
|
790
|
+
['div.pgroup',
|
791
|
+
['p', 'このように。']]]
|
792
|
+
)
|
793
|
+
end
|
794
|
+
it 'should markdown style heading not interrupted by smaller section' do
|
795
|
+
text = "=: タイトルです。\r\nこれは、セクションの中です。\n ==: また次のセクションです。\n 入れ子になります。\n===: さらに中のセクション \nさらに入れ子になっているはず。\n=:ここで次のセクションです。\n脱出しているはずです。"
|
796
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
797
|
+
converted = artimark.html
|
798
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
799
|
+
expect(body.element_children.size).to eq 2
|
800
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
801
|
+
['section',
|
802
|
+
['h1', 'タイトルです。'],
|
803
|
+
['div.pgroup',
|
804
|
+
['p', 'これは、セクションの中です。']],
|
805
|
+
['section',
|
806
|
+
['h2', 'また次のセクションです。'],
|
807
|
+
['div.pgroup',
|
808
|
+
['p', '入れ子になります。']],
|
809
|
+
['section',
|
810
|
+
['h3', 'さらに中のセクション'],
|
811
|
+
['div.pgroup',
|
812
|
+
['p', 'さらに入れ子になっているはず。']]]]] )
|
813
|
+
expect(body.element_children[1].selector_and_children).to eq(
|
814
|
+
['section',
|
815
|
+
['h1', 'ここで次のセクションです。'],
|
816
|
+
['div.pgroup',
|
817
|
+
['p', '脱出しているはずです。']]])
|
582
818
|
|
819
|
+
end
|
820
|
+
end
|
821
|
+
describe 'create file' do
|
822
|
+
before { @basedir = File.join(File.dirname(__FILE__), 'created_files') }
|
823
|
+
after { Dir.glob(File.join(@basedir, '*.xhtml')) { |file| File.delete file } }
|
824
|
+
it 'should create default file' do
|
825
|
+
text = "some text"
|
826
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the title')
|
827
|
+
artimark.html.write_as_files(directory: @basedir)
|
828
|
+
expect(File.basename(Dir.glob(File.join(@basedir, '*.xhtml'))[0])).to match /noramark_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}_00001.xhtml/
|
829
|
+
end
|
830
|
+
it 'should create named file' do
|
831
|
+
text = "some text\nnewpage:\nnext page"
|
832
|
+
artimark = ArtiMark::Document.parse(text, :lang => 'ja', :title => 'the document title', filename_base: 'nora-test-file', sequence_format: '%03d' )
|
833
|
+
artimark.html.write_as_files(directory: @basedir)
|
834
|
+
files = Dir.glob(File.join(@basedir, '*.xhtml'))
|
835
|
+
expect(File.basename(files[0])).to eq 'nora-test-file_001.xhtml'
|
836
|
+
expect(File.basename(files[1])).to eq 'nora-test-file_002.xhtml'
|
837
|
+
end
|
838
|
+
end
|
583
839
|
end
|
584
840
|
end
|