arti_mark 0.0.1.beta0

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.
@@ -0,0 +1,457 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/spec_helper.rb'
3
+ require File.dirname(__FILE__) + '/../lib/arti_mark'
4
+ require 'nokogiri'
5
+ require File.dirname(__FILE__) + '/nokogiri_test_helper.rb'
6
+
7
+ describe ArtiMark do
8
+ describe 'convert' do
9
+ it 'should generate valid xhtml' do
10
+ text = 'some text'
11
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the title')
12
+ xhtml = Nokogiri::XML::Document.parse(artimark.convert(text)[0])
13
+ expect(xhtml.root.name).to eq('html')
14
+ expect(xhtml.root.namespaces['xmlns']).to eq('http://www.w3.org/1999/xhtml')
15
+ expect(xhtml.root['xml:lang']).to eq('ja')
16
+ expect(xhtml.root.element_children[0].name).to eq 'head'
17
+ expect(xhtml.root.at_xpath('xmlns:head/xmlns:title').text).to eq('the title')
18
+ expect(xhtml.root.element_children[1].name).to eq 'body'
19
+ end
20
+ it 'should convert simple paragraph' do
21
+ text = "ここから、パラグラフがはじまります。\n「二行目です。」\n三行目です。\n\n\n ここから、次のパラグラフです。"
22
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
23
+ converted = artimark.convert(text)
24
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
25
+ expect(body.element_children.size).to eq 2
26
+
27
+ expect(body.element_children[0].selector_and_childs).to eq(
28
+ ['div.pgroup',
29
+ ['p', 'ここから、パラグラフがはじまります。'],
30
+ ['p.noindent', '「二行目です。」'],
31
+ ['p', '三行目です。']
32
+ ]
33
+ )
34
+
35
+ expect(body.element_children[1].selector_and_childs).to eq(
36
+ ['div.pgroup',
37
+ ['p', 'ここから、次のパラグラフです。']]
38
+ )
39
+ end
40
+ it 'should convert paragraph with header' do
41
+ text = "h1: タイトルです。\r\nここから、パラグラフがはじまります。\n\nh2.column:ふたつめの見出しです。\n ここから、次のパラグラフです。\nh3.third.foo: クラスが複数ある見出しです"
42
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
43
+ converted = artimark.convert(text)
44
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
45
+ expect(body.element_children.size).to eq 5
46
+ expect(body.element_children[0].a).to eq ['h1', 'タイトルです。']
47
+ expect(body.element_children[1].selector_and_childs).to eq(
48
+ ['div.pgroup',
49
+ ['p', 'ここから、パラグラフがはじまります。']
50
+ ]
51
+ )
52
+ expect(body.element_children[2].a).to eq ['h2.column', 'ふたつめの見出しです。']
53
+ expect(body.element_children[3].selector_and_childs).to eq(
54
+ ['div.pgroup',
55
+ ['p', 'ここから、次のパラグラフです。']
56
+ ]
57
+ )
58
+ expect(body.element_children[4].a).to eq ['h3.third.foo', 'クラスが複数ある見出しです']
59
+ end
60
+
61
+ it 'should convert div and paragraph' do
62
+ text = "d {\n1st line. \n}"
63
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
64
+ converted = artimark.convert(text)
65
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
66
+ expect(body.element_children[0].selector_and_childs).to eq(
67
+ ['div',
68
+ ['div.pgroup',
69
+ ['p', '1st line.']
70
+ ]
71
+ ]
72
+ )
73
+ end
74
+ it 'should convert div without pgroup' do
75
+ text = "d(wo-pgroup) {\n1st line. \n}"
76
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
77
+ converted = artimark.convert(text)
78
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
79
+ expect(body.element_children[0].selector_and_childs).to eq(
80
+ ['div',
81
+ ['p', '1st line.']
82
+ ]
83
+ )
84
+ end
85
+
86
+ it 'should nest div without pgroup' do
87
+ text = "d(wo-pgroup) {\nd {\nnested.\n} \n}"
88
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
89
+ converted = artimark.convert(text)
90
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
91
+ expect(body.element_children[0].selector_and_childs).to eq(
92
+ ['div',
93
+ ['div',
94
+ ['p', 'nested.']
95
+ ]
96
+ ]
97
+ )
98
+ end
99
+
100
+ it 'should convert div with class' do
101
+ text = "d.preface-one {\n h1: title.\n}"
102
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
103
+ converted = artimark.convert(text)
104
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
105
+ expect(body.element_children[0].selector_and_childs).to eq(
106
+ ['div.preface-one',
107
+ ['h1', 'title.']
108
+ ]
109
+ )
110
+ end
111
+ it 'should convert nested div' do
112
+ text = "d.preface {\n outer div. \n d.nested {\n nested!\n}\nouter div again.\n}"
113
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
114
+ converted = artimark.convert(text)
115
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
116
+ expect(body.element_children[0].selector_and_childs).to eq(
117
+ ['div.preface',
118
+ ['div.pgroup',
119
+ ['p', 'outer div.']
120
+ ],
121
+ ['div.nested',
122
+ ['div.pgroup',
123
+ ['p', 'nested!']
124
+ ]
125
+ ],
126
+ ['div.pgroup',
127
+ ['p', 'outer div again.']
128
+ ],
129
+ ]
130
+ )
131
+ end
132
+
133
+ it 'should convert article' do
134
+ text = "art {\n in the article.\n}"
135
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
136
+ converted = artimark.convert(text)
137
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
138
+ expect(body.element_children[0].selector_and_childs).to eq(
139
+ ['article',
140
+ ['div.pgroup',
141
+ ['p', 'in the article.']
142
+ ]
143
+ ]
144
+ )
145
+ end
146
+
147
+ it 'should handle block image' do
148
+ text = "this is normal line.\nimage(./image1.jpg, alt text): caption text"
149
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
150
+ converted = artimark.convert(text)
151
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
152
+ expect(body.element_children[0].selector_and_childs).to eq(
153
+ ['div.pgroup',
154
+ ['p', 'this is normal line.']
155
+ ]
156
+ )
157
+ expect(body.element_children[1].selector_and_childs).to eq(
158
+ ['div.img-wrap',
159
+ ["img[src='./image1.jpg'][alt='alt text']", ''],
160
+ ['p', 'caption text']
161
+ ]
162
+ )
163
+ end
164
+
165
+ it 'should handle page change article' do
166
+ text = "this is start.\nnewpage(page changed):\nthis is second page.\nnewpage:\nand the third."
167
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
168
+ converted = artimark.convert(text)
169
+ expect(converted.size).to eq 3
170
+ body1 = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
171
+ expect(body1.element_children[0].selector_and_childs).to eq(
172
+ ['div.pgroup',
173
+ ['p', 'this is start.']
174
+ ]
175
+ )
176
+
177
+ head2 = Nokogiri::XML::Document.parse(converted[1]).root.at_xpath('xmlns:head')
178
+ expect(head2.element_children[0].a).to eq ['title', 'page changed']
179
+ body2 = Nokogiri::XML::Document.parse(converted[1]).root.at_xpath('xmlns:body')
180
+ expect(body2.element_children[0].selector_and_childs).to eq(
181
+ ['div.pgroup',
182
+ ['p', 'this is second page.']
183
+ ]
184
+ )
185
+
186
+ head3 = Nokogiri::XML::Document.parse(converted[2]).root.at_xpath('xmlns:head')
187
+ expect(head3.element_children[0].a).to eq ['title', 'page changed']
188
+ body3 = Nokogiri::XML::Document.parse(converted[2]).root.at_xpath('xmlns:body')
189
+ expect(body3.element_children[0].selector_and_childs).to eq(
190
+ ['div.pgroup',
191
+ ['p', 'and the third.']
192
+ ]
193
+ )
194
+ end
195
+
196
+ it 'should handle stylesheets' do
197
+ text = "d.styled {\n this is styled document.\n}"
198
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title', :stylesheets => ['reset.css', 'mystyle.css'])
199
+ converted = artimark.convert(text)
200
+ head = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:head')
201
+ expect(head.element_children[0].a).to eq ['title', 'the document title']
202
+ expect(head.element_children[1].a).to eq ["link[rel='stylesheet'][type='text/css'][href='reset.css']", '']
203
+ expect(head.element_children[2].a).to eq ["link[rel='stylesheet'][type='text/css'][href='mystyle.css']", '']
204
+ end
205
+
206
+ it 'should handle link' do
207
+ text = "link to [link(http://github.com/skoji/artimark){artimark repository}]. \ncan you see this?"
208
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
209
+ converted = artimark.convert(text)
210
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
211
+ expect(body.element_children[0].selector_and_childs).to eq(
212
+ ['div.pgroup',
213
+ ['p',
214
+ 'link to ',
215
+ ["a[href='http://github.com/skoji/artimark']", 'artimark repository'],
216
+ '.'
217
+ ],
218
+ ['p', 'can you see this?']
219
+ ]
220
+ )
221
+ end
222
+ it 'should handle link with l' do
223
+ text = "link to [l(http://github.com/skoji/artimark){artimark repository}]. \ncan you see this?"
224
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
225
+ converted = artimark.convert(text)
226
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
227
+ expect(body.element_children[0].selector_and_childs).to eq(
228
+ ['div.pgroup',
229
+ ['p',
230
+ 'link to ',
231
+ ["a[href='http://github.com/skoji/artimark']", 'artimark repository'],
232
+ '.'
233
+ ],
234
+ ['p', 'can you see this?']
235
+ ]
236
+ )
237
+ end
238
+ it 'should handle custom paragraph' do
239
+ text = "this is normal line.\np.custom: this text is in custom class."
240
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
241
+ converted = artimark.convert(text)
242
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
243
+ expect(body.element_children[0].selector_and_childs).to eq(
244
+ ['div.pgroup',
245
+ ['p', 'this is normal line.'],
246
+ ['p.custom', 'this text is in custom class.']
247
+ ]
248
+ )
249
+ end
250
+ it 'should handle span' do
251
+ text = "p.custom: this text is in [s.keyword{custom}] class."
252
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
253
+ converted = artimark.convert(text)
254
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
255
+ expect(body.element_children[0].selector_and_childs).to eq(
256
+ ['div.pgroup',
257
+ ['p.custom', 'this text is in ', ['span.keyword', 'custom'], ' class.'
258
+ ]]
259
+ )
260
+ end
261
+ it 'should handle any block' do
262
+ text = "this is normal line.\ncite {\n this block should be in cite. \n}"
263
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
264
+ converted = artimark.convert(text)
265
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
266
+ expect(body.element_children[0].selector_and_childs).to eq(
267
+ ['div.pgroup',
268
+ ['p', 'this is normal line.']
269
+ ]
270
+ )
271
+ expect(body.element_children[1].selector_and_childs).to eq(
272
+ ['cite',
273
+ ['div.pgroup',
274
+ ['p', 'this block should be in cite.']
275
+ ]
276
+ ]
277
+ )
278
+ end
279
+ it 'should handle inline image' do
280
+ text = "simple image [img(caption){./image1.jpg}]."
281
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
282
+ converted = artimark.convert(text)
283
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
284
+ expect(body.element_children[0].selector_and_childs).to eq(
285
+ ['div.pgroup',
286
+ ['p',
287
+ 'simple image ', ["img[src='./image1.jpg'][alt='caption']", ''], '.']]
288
+ )
289
+ end
290
+
291
+ it 'should handle any inline' do
292
+ text = "this is normal line.\nin this line, this should be [strong{marked as strong}]."
293
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
294
+ converted = artimark.convert(text)
295
+ r = converted[0].rstrip.split(/\r?\n/).map { |line| line.chomp }
296
+ expect(r.shift.strip).to eq('<?xml version="1.0" encoding="UTF-8"?>')
297
+ expect(r.shift.strip).to eq('<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">')
298
+ expect(r.shift.strip).to eq('<head>')
299
+ expect(r.shift.strip).to eq('<title>the document title</title>')
300
+ expect(r.shift.strip).to eq('</head>')
301
+ expect(r.shift.strip).to eq('<body>')
302
+ expect(r.shift.strip).to eq("<div class='pgroup'>")
303
+ expect(r.shift.strip).to eq("<p>this is normal line.</p>")
304
+ expect(r.shift.strip).to eq("<p>in this line, this should be <strong>marked as strong</strong>.</p>")
305
+ expect(r.shift.strip).to eq("</div>")
306
+ expect(r.shift.strip).to eq("</body>")
307
+ expect(r.shift.strip).to eq("</html>")
308
+ end
309
+ it 'should generate toc: with newpage parameter' do
310
+ text = "newpage(1st chapter):\n1st chapter.\nnewpage(2nd chapter):\n2nd chapger.\nnewpage: 2nd chapter continued.\nnewpage(3rd chapter):\n3rd chapter."
311
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
312
+ artimark.convert(text)
313
+ toc = artimark.toc
314
+ expect(toc[0]).to eq('1st chapter')
315
+ expect(toc[1]).to eq('2nd chapter')
316
+ expect(toc[2]).to be_nil
317
+ expect(toc[3]).to eq('3rd chapter')
318
+ end
319
+
320
+ it 'should generate toc with h parameter' do
321
+ text = "newpage:\nh1(in-toc): 1st chapter\n content.\nnewpage:\nh1(in-toc): 2nd chapter\ncontent.\nnewpage: 2nd chapter continued.\nnewpage:\nh1(in-toc): 3rd chapter\n content."
322
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
323
+ artimark.convert(text)
324
+ toc = artimark.toc
325
+ expect(toc[0]).to eq('1st chapter')
326
+ expect(toc[1]).to eq('2nd chapter')
327
+ expect(toc[2]).to be_nil
328
+ expect(toc[3]).to eq('3rd chapter')
329
+ end
330
+
331
+ it 'should handle ruby' do
332
+ text = "[ruby(とんぼ){蜻蛉}]の[ruby(めがね){眼鏡}]はみずいろめがね"
333
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
334
+ converted = artimark.convert(text)
335
+ r = converted[0].rstrip.split(/\r?\n/).map { |line| line.chomp }
336
+ expect(r.shift.strip).to eq('<?xml version="1.0" encoding="UTF-8"?>')
337
+ expect(r.shift.strip).to eq('<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">')
338
+ expect(r.shift.strip).to eq('<head>')
339
+ expect(r.shift.strip).to eq('<title>the document title</title>')
340
+ expect(r.shift.strip).to eq('</head>')
341
+ expect(r.shift.strip).to eq('<body>')
342
+ expect(r.shift.strip).to eq("<div class='pgroup'>")
343
+ expect(r.shift.strip).to eq("<p><ruby>蜻蛉<rp>(</rp><rt>とんぼ</rt><rp>)</rp></ruby>の<ruby>眼鏡<rp>(</rp><rt>めがね</rt><rp>)</rp></ruby>はみずいろめがね</p>")
344
+ expect(r.shift.strip).to eq("</div>")
345
+ expect(r.shift.strip).to eq("</body>")
346
+ expect(r.shift.strip).to eq("</html>")
347
+ end
348
+
349
+
350
+ it 'should handle ordered list ' do
351
+ text = "this is normal line.\n1: for the 1st.\n2: secondly, blah.\n3: and last...\nthe ordered list ends."
352
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
353
+ converted = artimark.convert(text)
354
+ r = converted[0].rstrip.split(/\r?\n/).map { |line| line.chomp }
355
+ expect(r.shift.strip).to eq('<?xml version="1.0" encoding="UTF-8"?>')
356
+ expect(r.shift.strip).to eq('<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">')
357
+ expect(r.shift.strip).to eq('<head>')
358
+ expect(r.shift.strip).to eq('<title>the document title</title>')
359
+ expect(r.shift.strip).to eq('</head>')
360
+ expect(r.shift.strip).to eq('<body>')
361
+ expect(r.shift.strip).to eq("<div class='pgroup'>")
362
+ expect(r.shift.strip).to eq("<p>this is normal line.</p>")
363
+ expect(r.shift.strip).to eq("</div>")
364
+ expect(r.shift.strip).to eq("<ol>")
365
+ expect(r.shift.strip).to eq("<li>for the 1st.</li>")
366
+ expect(r.shift.strip).to eq("<li>secondly, blah.</li>")
367
+ expect(r.shift.strip).to eq("<li>and last...</li>")
368
+ expect(r.shift.strip).to eq("</ol>")
369
+ expect(r.shift.strip).to eq("<div class='pgroup'>")
370
+ expect(r.shift.strip).to eq("<p>the ordered list ends.</p>")
371
+ expect(r.shift.strip).to eq("</div>")
372
+ expect(r.shift.strip).to eq("</body>")
373
+ expect(r.shift.strip).to eq("</html>")
374
+ end
375
+ it 'should handle unordered list ' do
376
+ text = "this is normal line.\n*: for the 1st.\n*: secondly, blah.\n*: and last...\nthe ordered list ends."
377
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
378
+ converted = artimark.convert(text)
379
+ r = converted[0].rstrip.split(/\r?\n/).map { |line| line.chomp }
380
+ expect(r.shift.strip).to eq('<?xml version="1.0" encoding="UTF-8"?>')
381
+ expect(r.shift.strip).to eq('<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">')
382
+ expect(r.shift.strip).to eq('<head>')
383
+ expect(r.shift.strip).to eq('<title>the document title</title>')
384
+ expect(r.shift.strip).to eq('</head>')
385
+ expect(r.shift.strip).to eq('<body>')
386
+ expect(r.shift.strip).to eq("<div class='pgroup'>")
387
+ expect(r.shift.strip).to eq("<p>this is normal line.</p>")
388
+ expect(r.shift.strip).to eq("</div>")
389
+ expect(r.shift.strip).to eq("<ul>")
390
+ expect(r.shift.strip).to eq("<li>for the 1st.</li>")
391
+ expect(r.shift.strip).to eq("<li>secondly, blah.</li>")
392
+ expect(r.shift.strip).to eq("<li>and last...</li>")
393
+ expect(r.shift.strip).to eq("</ul>")
394
+ expect(r.shift.strip).to eq("<div class='pgroup'>")
395
+ expect(r.shift.strip).to eq("<p>the ordered list ends.</p>")
396
+ expect(r.shift.strip).to eq("</div>")
397
+ expect(r.shift.strip).to eq("</body>")
398
+ expect(r.shift.strip).to eq("</html>")
399
+ end
400
+ it 'should handle definition list ' do
401
+ 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."
402
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
403
+ converted = artimark.convert(text)
404
+ r = converted[0].rstrip.split(/\r?\n/).map { |line| line.chomp }
405
+ expect(r.shift.strip).to eq('<?xml version="1.0" encoding="UTF-8"?>')
406
+ expect(r.shift.strip).to eq('<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">')
407
+ expect(r.shift.strip).to eq('<head>')
408
+ expect(r.shift.strip).to eq('<title>the document title</title>')
409
+ expect(r.shift.strip).to eq('</head>')
410
+ expect(r.shift.strip).to eq('<body>')
411
+ expect(r.shift.strip).to eq("<div class='pgroup'>")
412
+ expect(r.shift.strip).to eq("<p>this is normal line.</p>")
413
+ expect(r.shift.strip).to eq("</div>")
414
+ expect(r.shift.strip).to eq("<dl>")
415
+ expect(r.shift.strip).to eq("<dt>1st</dt><dd>this is the first definition</dd>")
416
+ expect(r.shift.strip).to eq("<dt>2nd</dt><dd>blah :blah.</dd>")
417
+ expect(r.shift.strip).to eq("<dt>3rd</dt><dd>this term is the last.</dd>")
418
+ expect(r.shift.strip).to eq("</dl>")
419
+ expect(r.shift.strip).to eq("<div class='pgroup'>")
420
+ expect(r.shift.strip).to eq("<p>the list ends.</p>")
421
+ expect(r.shift.strip).to eq("</div>")
422
+ expect(r.shift.strip).to eq("</body>")
423
+ expect(r.shift.strip).to eq("</html>")
424
+ end
425
+
426
+ it 'should escape html' do
427
+ text = ";:definition<>:<>&"
428
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
429
+ converted = artimark.convert(text)
430
+ r = converted[0].rstrip.split(/\r?\n/).map { |line| line.chomp }
431
+ expect(r.shift.strip).to eq('<?xml version="1.0" encoding="UTF-8"?>')
432
+ expect(r.shift.strip).to eq('<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">')
433
+ expect(r.shift.strip).to eq('<head>')
434
+ expect(r.shift.strip).to eq('<title>the document title</title>')
435
+ expect(r.shift.strip).to eq('</head>')
436
+ expect(r.shift.strip).to eq('<body>')
437
+ expect(r.shift.strip).to eq('<dl>')
438
+ expect(r.shift.strip).to eq('<dt>definition&lt;&gt;</dt><dd>&lt;&gt;&amp;</dd>')
439
+ end
440
+ it 'should specify stylesheets' do
441
+ text = "stylesheets:css/default.css, css/specific.css, css/iphone.css:(only screen and (min-device-width : 320px) and (max-device-width : 480px))\ntext."
442
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
443
+ converted = artimark.convert(text)
444
+ r = converted[0].rstrip.split(/\r?\n/).map { |line| line.chomp }
445
+ expect(r.shift.strip).to eq('<?xml version="1.0" encoding="UTF-8"?>')
446
+ expect(r.shift.strip).to eq('<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">')
447
+ expect(r.shift.strip).to eq('<head>')
448
+ expect(r.shift.strip).to eq('<title>the document title</title>')
449
+ expect(r.shift.strip).to eq('<link rel="stylesheet" type="text/css" href="css/default.css" />')
450
+ expect(r.shift.strip).to eq('<link rel="stylesheet" type="text/css" href="css/specific.css" />')
451
+ expect(r.shift.strip).to eq('<link rel="stylesheet" type="text/css" media="only screen and (min-device-width : 320px) and (max-device-width : 480px)" href="css/iphone.css" />')
452
+ expect(r.shift.strip).to eq('</head>')
453
+ expect(r.shift.strip).to eq('<body>')
454
+ end
455
+ end
456
+ end
457
+
@@ -0,0 +1,48 @@
1
+ sect.preface {
2
+ h1: 前書き
3
+ 前書きのようなものをここでかく。
4
+ 「前書き」とは英語では[s.strong{preface}]のことだろうか。
5
+ }
6
+
7
+ newpage:
8
+
9
+ art.main {
10
+ h1: 本文
11
+ ここからが本文。
12
+ チェックする項目は
13
+
14
+ 1: ol要素が出ること
15
+ 2: ul要素がでること
16
+ 3: dl要素
17
+ 4: spanがでること
18
+
19
+ である。
20
+
21
+ [s.strong{ArtiMark}] の要素は、次のものからなる。
22
+
23
+ *: 行
24
+ *: パラグラフ
25
+ *: 行コマンド
26
+ *: ブロックコマンド
27
+ *: インラインコマンド
28
+
29
+ ;: 行: 行コマンドでマークアップされていない行は、pタグで囲まれる。
30
+ ;: パラグラフ: 空行で区切られた一連の行は、div class='pgroup' で囲まれる。空行ではなく、別のコマンドによってもパラグラフは生成される。
31
+
32
+ コマンドについて説明する。
33
+
34
+ ;:コマンド文字列: <コマンド名>[.クラス名]*[#id名]*[(パラメータ)]
35
+ ;: 行コマンド : 行先頭に、<コマンド文字列>: がくる。続く行末までの文字が処理対象となる。p/h以外のブロック要素を生成する行コマンドは、暗黙のブロックを中断する。
36
+ ;: ブロックコマンド : 行先頭に<コマンド文字列>{ がくる。その行では文字を続けない。} 単独の行で閉じる。
37
+ ;: インラインコマンド : 行の途中にあらわれる[<コマンド文字列>{<文字>}] の列。
38
+
39
+ 定義済みコマンドは次のとおり。
40
+
41
+ ;.commands: 行コマンド: p
42
+ ;: パラグラフを中断する行コマンド: newpage, image, h1, h2, h3, h4, h5, h6, *(箇条書き), 数字(列挙), ;(定義リスト)
43
+ ;:ブロックコマンド: d, art, sec。未定義であっても、ブロックコマンドの形式をしていればなんでも<コマンド名> ... </コマンド名> に展開される。
44
+ ;:インラインコマンド: s, l, img。 その他は、インラインコマンドの形式をしていれば、なんでも<コマンド名> ... </コマンド名> に展開される。
45
+
46
+
47
+
48
+ }
@@ -0,0 +1,41 @@
1
+ module Nokogiri
2
+ module XML
3
+ class Element
4
+ def selector
5
+ sel = name
6
+ if !self['id'].nil?
7
+ sel = sel + '#' + self['id'].split(' ').join('#')
8
+ end
9
+ if !self['class'].nil?
10
+ sel = sel + '.' + self['class'].split(' ').join('.')
11
+ end
12
+ attributes.select{|k,v| k != 'class' && k != 'id'}.each {
13
+ |name, value|
14
+ sel = sel + "[#{name}='#{value}']"
15
+ }
16
+ sel
17
+ end
18
+ def selector_and_text
19
+ [selector, text]
20
+ end
21
+ alias a selector_and_text
22
+ def child_loop
23
+ yield self
24
+ end
25
+ def child_a(index)
26
+ element_children[index].selector_and_text
27
+ end
28
+ def selector_and_childs
29
+ [selector] + children.select{|c| c.elem? || c.text.strip.size > 0}.map{|c|
30
+ if !c.elem?
31
+ c.text
32
+ elsif c.element_children.size == 0
33
+ c.selector_and_text
34
+ else
35
+ c.selector_and_childs
36
+ end
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,29 @@
1
+ begin
2
+ require 'rspec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ RSpec.configure do |config|
10
+ # Use color in STDOUT
11
+ config.color_enabled = true
12
+ # Use color not only in STDOUT but also in pagers and files
13
+ config.tty = true
14
+ # Use the specified formatter
15
+ config.formatter = :documentation # :progress, :html, :textmate
16
+ end
17
+
18
+ require 'rspec/core/formatters/base_text_formatter'
19
+ module RSpec
20
+ module Core
21
+ module Formatters
22
+ class DocumentationFormatter < BaseTextFormatter
23
+ # def green(text); color(text, "\e[42m") end
24
+ def red(text); color(text, "\e[41m") end
25
+ # def magenta(text); color(text, "\e[45m") end
26
+ end
27
+ end
28
+ end
29
+ end