arti_mark 0.0.1.beta4 → 0.1.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ require 'arti_mark/parser.kpeg'
2
+
3
+ module ArtiMark
4
+ class Parser
5
+ def create_item(type, command, children = [], raw: nil)
6
+ children[0].sub!(/^[[:space:]]+/, '') if !children.nil? && children[0].is_a?(String)
7
+ item = {:type => type, :children => children, :raw_text => raw }.merge command || {}
8
+ item[:args] ||= []
9
+ item[:named_args] = Hash[*(item[:args].select { |x| x.include?(':') }.map { |x| v = x.split(':', 2); [v[0].strip.to_sym, v[1]]}.flatten)]
10
+ item
11
+ end
12
+
13
+ def parse_text(content)
14
+ content.inject([]) do
15
+ |result, item|
16
+ if item.is_a? String
17
+ s = result.last
18
+ if s.is_a? String
19
+ result.pop
20
+ else
21
+ s = ''
22
+ end
23
+ result.push s + item
24
+ else
25
+ result.push item
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
@@ -1,3 +1,3 @@
1
1
  module ArtiMark
2
- VERSION = "0.0.1.beta4"
2
+ VERSION = "0.1.beta1"
3
3
  end
data/lib/arti_mark.rb CHANGED
@@ -15,47 +15,36 @@ require "arti_mark/unordered_list_parser"
15
15
  require "arti_mark/definition_list_parser"
16
16
  require "arti_mark/universal_block_parser"
17
17
  require 'arti_mark/syntax'
18
- require 'arti_mark/result'
19
- require 'arti_mark/context'
18
+
19
+ require 'arti_mark/html/generator'
20
+ require 'arti_mark/parser'
20
21
 
21
22
  module ArtiMark
22
23
  class Document
23
24
  def initialize(param = {})
24
- @context = Context.new(param)
25
- @syntax = Syntax.new
26
25
  @preprocessors = [
27
26
  Proc.new { |text| text.gsub(/\r?\n(\r?\n)+/, "\n\n") },
28
27
  Proc.new { |text| text.strip.gsub(/ /, ' ') } # convert Japanese full-width spece to normal space
29
28
  ]
29
+ @generator = Html::Generator.new(param)
30
30
  end
31
31
 
32
32
  def preprocessor(&block)
33
33
  @preprocessors << block
34
34
  end
35
35
 
36
- def parser(parser)
37
- @syntax.append_parser(parser)
38
- end
39
-
40
36
  def convert(text)
41
37
  @preprocessors.each {
42
38
  |pr|
43
39
  text = pr.call(text)
44
40
  }
45
- # split text to lines
46
- lines = text.split(/\r?\n/).map { |line| line.strip }
47
- process_lines(lines, @context)
48
- @context.result
49
- end
50
-
51
- def toc
52
- @context.toc
53
- end
54
-
55
- def process_lines(lines, context)
56
- while (lines.size > 0)
57
- @syntax.parse(lines, context)
41
+ @parser = Parser.new(text)
42
+ if (!@parser.parse)
43
+ puts @parser.show_error
44
+ exit -1
58
45
  end
46
+ @generator.convert(@parser.result)
47
+
59
48
  end
60
49
 
61
50
  end
@@ -23,7 +23,6 @@ describe ArtiMark do
23
23
  converted = artimark.convert(text)
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
-
27
26
  expect(body.element_children[0].selector_and_children).to eq(
28
27
  ['div.pgroup',
29
28
  ['p', 'ここから、パラグラフがはじまります。'],
@@ -72,33 +71,34 @@ describe ArtiMark do
72
71
  )
73
72
  end
74
73
 
75
- it 'should convert div and paragraph with alternate style' do
76
- text = "d {---\n1st line. \n---}"
74
+ it 'should convert div without pgroup' do
75
+ text = "d(wo-pgroup) {\n1st line. \n}"
77
76
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
78
77
  converted = artimark.convert(text)
79
78
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
80
79
  expect(body.element_children[0].selector_and_children).to eq(
81
80
  ['div',
82
- ['div.pgroup',
83
81
  ['p', '1st line.']
84
- ]
85
82
  ]
86
83
  )
87
84
  end
88
- it 'should convert div without pgroup' do
89
- text = "d(wo-pgroup) {\n1st line. \n}"
85
+
86
+ it 'should nest div without pgroup' do
87
+ text = "d(wo-pgroup) {\nd {\nnested.\n} \n}"
90
88
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
91
89
  converted = artimark.convert(text)
92
90
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
93
91
  expect(body.element_children[0].selector_and_children).to eq(
94
92
  ['div',
95
- ['p', '1st line.']
93
+ ['div',
94
+ ['p', 'nested.']
95
+ ]
96
96
  ]
97
97
  )
98
98
  end
99
99
 
100
- it 'should nest div without pgroup' do
101
- text = "d(wo-pgroup) {\nd {\nnested.\n} \n}"
100
+ it 'should nest div without pgroup and with pgroup' do
101
+ text = "d(wo-pgroup) {\nd {\nnested.\n} \n}\nd {\nin pgroup\n}"
102
102
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
103
103
  converted = artimark.convert(text)
104
104
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
@@ -107,10 +107,16 @@ describe ArtiMark do
107
107
  ['div',
108
108
  ['p', 'nested.']
109
109
  ]
110
- ]
111
- )
110
+ ])
111
+ expect(body.element_children[1].selector_and_children).to eq(
112
+ ['div',
113
+ ['div.pgroup',
114
+ ['p', 'in pgroup']
115
+ ]
116
+ ])
112
117
  end
113
118
 
119
+
114
120
  it 'should convert div with class' do
115
121
  text = "d.preface-one {\n h1: title.\n}"
116
122
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
@@ -124,7 +130,7 @@ describe ArtiMark do
124
130
  end
125
131
 
126
132
  it 'should convert div with id and class' do
127
- text = "d#thecontents.preface-one {\n h1: title.\n}"
133
+ text = "d#thecontents.preface-one {\nh1: title.\n}"
128
134
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
129
135
  converted = artimark.convert(text)
130
136
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
@@ -156,52 +162,7 @@ describe ArtiMark do
156
162
  ]
157
163
  )
158
164
  end
159
-
160
- it 'should convert nested div with alternate style inside' do
161
- text = "d.preface {\n outer div. \n d.nested {---\n nested!\n---}\nouter div again.\n}"
162
- artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
163
- converted = artimark.convert(text)
164
- body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
165
- expect(body.element_children[0].selector_and_children).to eq(
166
- ['div.preface',
167
- ['div.pgroup',
168
- ['p', 'outer div.']
169
- ],
170
- ['div.nested',
171
- ['div.pgroup',
172
- ['p', 'nested!']
173
- ]
174
- ],
175
- ['div.pgroup',
176
- ['p', 'outer div again.']
177
- ],
178
- ]
179
- )
180
- end
181
165
 
182
- it 'should convert nested div with alternate style outside' do
183
- text = "d.preface {---\n outer div. \n}\nyou can write curly brace as above.\nd.nested {\n nested!\n}\nouter div again.\n---}"
184
- artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
185
- converted = artimark.convert(text)
186
- body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
187
- expect(body.element_children[0].selector_and_children).to eq(
188
- ['div.preface',
189
- ['div.pgroup',
190
- ['p', 'outer div.'],
191
- ['p', '}'],
192
- ['p', 'you can write curly brace as above.']
193
- ],
194
- ['div.nested',
195
- ['div.pgroup',
196
- ['p', 'nested!']
197
- ]
198
- ],
199
- ['div.pgroup',
200
- ['p', 'outer div again.']
201
- ],
202
- ]
203
- )
204
- end
205
166
  it 'should convert article' do
206
167
  text = "art {\n in the article.\n}"
207
168
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
@@ -252,6 +213,22 @@ describe ArtiMark do
252
213
  )
253
214
  end
254
215
 
216
+ it 'should handle block image without caption' do
217
+ text = "this is normal line.\nimage(./image1.jpg, alt text):"
218
+ artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
219
+ converted = artimark.convert(text)
220
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
221
+ expect(body.element_children[0].selector_and_children).to eq(
222
+ ['div.pgroup',
223
+ ['p', 'this is normal line.']
224
+ ]
225
+ )
226
+ expect(body.element_children[1].selector_and_children).to eq(
227
+ ['div.img-wrap',
228
+ ["img[src='./image1.jpg'][alt='alt text']", '']
229
+ ]
230
+ )
231
+ end
255
232
 
256
233
  it 'should handle page change article' do
257
234
  text = "this is start.\nnewpage(page changed):\nthis is second page.\nnewpage:\nand the third."
@@ -295,7 +272,7 @@ describe ArtiMark do
295
272
  end
296
273
 
297
274
  it 'should handle link' do
298
- text = "link to [link(http://github.com/skoji/artimark){artimark repository}]. \ncan you see this?"
275
+ text = " link to [link(http://github.com/skoji/artimark){artimark repository}]. \ncan you see this?"
299
276
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
300
277
  converted = artimark.convert(text)
301
278
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
@@ -310,6 +287,7 @@ describe ArtiMark do
310
287
  ]
311
288
  )
312
289
  end
290
+
313
291
  it 'should handle link with l' do
314
292
  text = "link to [l(http://github.com/skoji/artimark){artimark repository}]. \ncan you see this?"
315
293
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
@@ -326,6 +304,7 @@ describe ArtiMark do
326
304
  ]
327
305
  )
328
306
  end
307
+
329
308
  it 'should handle custom paragraph' do
330
309
  text = "this is normal line.\np.custom: this text is in custom class."
331
310
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
@@ -338,6 +317,7 @@ describe ArtiMark do
338
317
  ]
339
318
  )
340
319
  end
320
+
341
321
  it 'should handle span' do
342
322
  text = "p.custom: this text is in [s.keyword{custom}] class."
343
323
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
@@ -349,6 +329,7 @@ describe ArtiMark do
349
329
  ]]
350
330
  )
351
331
  end
332
+
352
333
  it 'should handle any block' do
353
334
  text = "this is normal line.\ncite {\n this block should be in cite. \n}"
354
335
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
@@ -367,15 +348,16 @@ describe ArtiMark do
367
348
  ]
368
349
  )
369
350
  end
351
+
370
352
  it 'should handle inline image' do
371
- text = "simple image [img(caption){./image1.jpg}]."
353
+ text = "simple image [img(./image1.jpg, alt)]."
372
354
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
373
355
  converted = artimark.convert(text)
374
356
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
375
357
  expect(body.element_children[0].selector_and_children).to eq(
376
358
  ['div.pgroup',
377
359
  ['p',
378
- 'simple image ', ["img[src='./image1.jpg'][alt='caption']", ''], '.']]
360
+ 'simple image ', ["img[src='./image1.jpg'][alt='alt']", ''], '.']]
379
361
  )
380
362
  end
381
363
 
@@ -390,28 +372,6 @@ describe ArtiMark do
390
372
  )
391
373
  end
392
374
 
393
- it 'should generate toc: with newpage parameter' do
394
- text = "newpage(1st chapter):\n1st chapter.\nnewpage(2nd chapter):\n2nd chapger.\nnewpage: 2nd chapter continued.\nnewpage(3rd chapter):\n3rd chapter."
395
- artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
396
- artimark.convert(text)
397
- toc = artimark.toc
398
- expect(toc[0]).to eq('1st chapter')
399
- expect(toc[1]).to eq('2nd chapter')
400
- expect(toc[2]).to be_nil
401
- expect(toc[3]).to eq('3rd chapter')
402
- end
403
-
404
- it 'should generate toc with h parameter' do
405
- 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."
406
- artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
407
- artimark.convert(text)
408
- toc = artimark.toc
409
- expect(toc[0]).to eq('1st chapter')
410
- expect(toc[1]).to eq('2nd chapter')
411
- expect(toc[2]).to be_nil
412
- expect(toc[3]).to eq('3rd chapter')
413
- end
414
-
415
375
  it 'should convert inline command within line block' do
416
376
  text = "h1: [tcy{20}]縦中横タイトル"
417
377
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
@@ -424,19 +384,14 @@ describe ArtiMark do
424
384
  text = "[ruby(とんぼ){蜻蛉}]の[ruby(めがね){眼鏡}]はみずいろめがね"
425
385
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
426
386
  converted = artimark.convert(text)
427
- r = converted[0].rstrip.split(/\r?\n/).map { |line| line.chomp }
428
- expect(r.shift.strip).to eq('<?xml version="1.0" encoding="UTF-8"?>')
429
- expect(r.shift.strip).to eq('<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">')
430
- expect(r.shift.strip).to eq('<head>')
431
- expect(r.shift.strip).to eq('<title>the document title</title>')
432
- expect(r.shift.strip).to eq('</head>')
433
- expect(r.shift.strip).to eq('<body>')
434
- expect(r.shift.strip).to eq("<div class='pgroup'>")
435
- expect(r.shift.strip).to eq("<p><ruby>蜻蛉<rp>(</rp><rt>とんぼ</rt><rp>)</rp></ruby>の<ruby>眼鏡<rp>(</rp><rt>めがね</rt><rp>)</rp></ruby>はみずいろめがね</p>")
436
- expect(r.shift.strip).to eq("</div>")
437
- expect(r.shift.strip).to eq("</body>")
438
- expect(r.shift.strip).to eq("</html>")
387
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
388
+ expect(body.element_children[0].selector_and_children).to eq ['div.pgroup', ['p',
389
+ ['ruby', '蜻蛉', ['rp','('],['rt','とんぼ'],['rp', ')']],
390
+ '',
391
+ ['ruby', '眼鏡', ['rp','('],['rt','めがね'],['rp', ')']],
392
+ 'はみずいろめがね']]
439
393
  end
394
+
440
395
  it 'should handle tatechuyoko' do
441
396
  text = "[tcy{10}]年前のことだった"
442
397
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
@@ -452,92 +407,79 @@ describe ArtiMark do
452
407
  text = "this is normal line.\n1: for the 1st.\n2: secondly, blah.\n3: and last...\nthe ordered list ends."
453
408
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
454
409
  converted = artimark.convert(text)
455
- r = converted[0].rstrip.split(/\r?\n/).map { |line| line.chomp }
456
- expect(r.shift.strip).to eq('<?xml version="1.0" encoding="UTF-8"?>')
457
- expect(r.shift.strip).to eq('<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">')
458
- expect(r.shift.strip).to eq('<head>')
459
- expect(r.shift.strip).to eq('<title>the document title</title>')
460
- expect(r.shift.strip).to eq('</head>')
461
- expect(r.shift.strip).to eq('<body>')
462
- expect(r.shift.strip).to eq("<div class='pgroup'>")
463
- expect(r.shift.strip).to eq("<p>this is normal line.</p>")
464
- expect(r.shift.strip).to eq("</div>")
465
- expect(r.shift.strip).to eq("<ol>")
466
- expect(r.shift.strip).to eq("<li>for the 1st.</li>")
467
- expect(r.shift.strip).to eq("<li>secondly, blah.</li>")
468
- expect(r.shift.strip).to eq("<li>and last...</li>")
469
- expect(r.shift.strip).to eq("</ol>")
470
- expect(r.shift.strip).to eq("<div class='pgroup'>")
471
- expect(r.shift.strip).to eq("<p>the ordered list ends.</p>")
472
- expect(r.shift.strip).to eq("</div>")
473
- expect(r.shift.strip).to eq("</body>")
474
- expect(r.shift.strip).to eq("</html>")
410
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
411
+ expect(body.element_children.size).to eq 3
412
+ expect(body.element_children[0].selector_and_children).to eq(
413
+ ['div.pgroup',
414
+ ['p', 'this is normal line.']
415
+ ])
416
+ expect(body.element_children[1].selector_and_children).to eq(
417
+ ['ol',
418
+ ['li', 'for the 1st.'],
419
+ ['li', 'secondly, blah.'],
420
+ ['li', 'and last...']
421
+ ])
422
+ expect(body.element_children[2].selector_and_children).to eq(
423
+ ['div.pgroup',
424
+ ['p', 'the ordered list ends.']
425
+ ])
475
426
  end
427
+
476
428
  it 'should handle unordered list ' do
477
429
  text = "this is normal line.\n*: for the 1st.\n*: secondly, blah.\n*: and last...\nthe ordered list ends."
478
430
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
479
431
  converted = artimark.convert(text)
480
- r = converted[0].rstrip.split(/\r?\n/).map { |line| line.chomp }
481
- expect(r.shift.strip).to eq('<?xml version="1.0" encoding="UTF-8"?>')
482
- expect(r.shift.strip).to eq('<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">')
483
- expect(r.shift.strip).to eq('<head>')
484
- expect(r.shift.strip).to eq('<title>the document title</title>')
485
- expect(r.shift.strip).to eq('</head>')
486
- expect(r.shift.strip).to eq('<body>')
487
- expect(r.shift.strip).to eq("<div class='pgroup'>")
488
- expect(r.shift.strip).to eq("<p>this is normal line.</p>")
489
- expect(r.shift.strip).to eq("</div>")
490
- expect(r.shift.strip).to eq("<ul>")
491
- expect(r.shift.strip).to eq("<li>for the 1st.</li>")
492
- expect(r.shift.strip).to eq("<li>secondly, blah.</li>")
493
- expect(r.shift.strip).to eq("<li>and last...</li>")
494
- expect(r.shift.strip).to eq("</ul>")
495
- expect(r.shift.strip).to eq("<div class='pgroup'>")
496
- expect(r.shift.strip).to eq("<p>the ordered list ends.</p>")
497
- expect(r.shift.strip).to eq("</div>")
498
- expect(r.shift.strip).to eq("</body>")
499
- expect(r.shift.strip).to eq("</html>")
432
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
433
+ expect(body.element_children.size).to eq 3
434
+ expect(body.element_children[0].selector_and_children).to eq(
435
+ ['div.pgroup',
436
+ ['p', 'this is normal line.']
437
+ ])
438
+ expect(body.element_children[1].selector_and_children).to eq(
439
+ ['ul',
440
+ ['li', 'for the 1st.'],
441
+ ['li', 'secondly, blah.'],
442
+ ['li', 'and last...']
443
+ ])
444
+ expect(body.element_children[2].selector_and_children).to eq(
445
+ ['div.pgroup',
446
+ ['p', 'the ordered list ends.']
447
+ ])
500
448
  end
449
+
501
450
  it 'should handle definition list ' do
502
451
  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."
503
452
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
504
453
  converted = artimark.convert(text)
505
- r = converted[0].rstrip.split(/\r?\n/).map { |line| line.chomp }
506
- expect(r.shift.strip).to eq('<?xml version="1.0" encoding="UTF-8"?>')
507
- expect(r.shift.strip).to eq('<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">')
508
- expect(r.shift.strip).to eq('<head>')
509
- expect(r.shift.strip).to eq('<title>the document title</title>')
510
- expect(r.shift.strip).to eq('</head>')
511
- expect(r.shift.strip).to eq('<body>')
512
- expect(r.shift.strip).to eq("<div class='pgroup'>")
513
- expect(r.shift.strip).to eq("<p>this is normal line.</p>")
514
- expect(r.shift.strip).to eq("</div>")
515
- expect(r.shift.strip).to eq("<dl>")
516
- expect(r.shift.strip).to eq("<dt>1st</dt><dd>this is the first definition</dd>")
517
- expect(r.shift.strip).to eq("<dt>2nd</dt><dd>blah :blah.</dd>")
518
- expect(r.shift.strip).to eq("<dt>3rd</dt><dd>this term is the last.</dd>")
519
- expect(r.shift.strip).to eq("</dl>")
520
- expect(r.shift.strip).to eq("<div class='pgroup'>")
521
- expect(r.shift.strip).to eq("<p>the list ends.</p>")
522
- expect(r.shift.strip).to eq("</div>")
523
- expect(r.shift.strip).to eq("</body>")
524
- expect(r.shift.strip).to eq("</html>")
454
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
455
+ expect(body.element_children.size).to eq 3
456
+ expect(body.element_children[0].selector_and_children).to eq(
457
+ ['div.pgroup',
458
+ ['p', 'this is normal line.']
459
+ ])
460
+ expect(body.element_children[1].selector_and_children).to eq(
461
+ ['dl',
462
+ ['dt', '1st'],['dd', 'this is the first definition'],
463
+ ['dt', '2nd'],['dd', 'blah :blah.'],
464
+ ['dt', '3rd'],['dd', 'this term is the last.'],
465
+ ])
466
+ expect(body.element_children[2].selector_and_children).to eq(
467
+ ['div.pgroup',
468
+ ['p', 'the list ends.']
469
+ ])
525
470
  end
526
471
 
527
472
  it 'should escape html' do
528
- text = ";:definition<>:<>&"
473
+ text = ";:definition<div>:</div>&"
529
474
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
530
475
  converted = artimark.convert(text)
531
- r = converted[0].rstrip.split(/\r?\n/).map { |line| line.chomp }
532
- expect(r.shift.strip).to eq('<?xml version="1.0" encoding="UTF-8"?>')
533
- expect(r.shift.strip).to eq('<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">')
534
- expect(r.shift.strip).to eq('<head>')
535
- expect(r.shift.strip).to eq('<title>the document title</title>')
536
- expect(r.shift.strip).to eq('</head>')
537
- expect(r.shift.strip).to eq('<body>')
538
- expect(r.shift.strip).to eq('<dl>')
539
- expect(r.shift.strip).to eq('<dt>definition&lt;&gt;</dt><dd>&lt;&gt;&amp;</dd>')
476
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
477
+ expect(body.element_children[0].selector_and_children).to eq(
478
+ ['dl',
479
+ ['dt', 'definition<div>'],['dd', '</div>&']
480
+ ])
540
481
  end
482
+
541
483
  it 'should specify stylesheets' do
542
484
  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."
543
485
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
@@ -571,6 +513,7 @@ describe ArtiMark do
571
513
  expect(root['lang']).to eq 'ja'
572
514
  end
573
515
 
516
+
574
517
  it 'should ignore comments' do
575
518
  text = "#この行はコメントです\nここから、パラグラフがはじまります。\n#これもコメント\n「二行目です。」\n三行目です。\n\n#これもコメント\n\n ここから、次のパラグラフです。"
576
519
  artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
@@ -607,58 +550,5 @@ describe ArtiMark do
607
550
  ]
608
551
  )
609
552
  end
610
- it 'should handle custom block parser' do
611
- class TheParser
612
- include ArtiMark::BaseParser
613
- def accept?(lines)
614
- lex_line_command(lines[0])[:cmd] =~ /svg/
615
- end
616
- def parse(lines, r, syntax)
617
- lexed = lex_line_command(lines[0])
618
- lines.shift
619
- src = lexed[:params][0].strip
620
- caption = lexed[:text].strip
621
- r << "<div><svg xmlns='http://www.w3.org/2000/svg' version='1.1' xmlns:xlink='http://www.w3.org/1999/xlink' width='100%' height='100%' viewBox='0 0 200 200' ><image xlink:href='#{src}' /><p>#{caption}</p></sgv></div>"
622
- end
623
- end
624
- text="svg(img.jpg):caption"
625
- artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
626
- artimark.parser(TheParser.new)
627
- converted = artimark.convert(text)
628
- body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
629
- expect(body.element_children[0].selector_and_children).to eq(
630
- ['div',
631
- ["svg[version='1.1'][width='100%'][height='100%'][viewBox='0 0 200 200']", ["image[href='img.jpg']", ''], ['p', 'caption']]
632
- ]
633
- )
634
- end
635
- it 'should handle custom block parser with named param' do
636
- class TheParser
637
- include ArtiMark::BaseParser
638
- def accept?(lines)
639
- lex_line_command(lines[0])[:cmd] =~ /svg/
640
- end
641
- def parse(lines, r, syntax)
642
- lexed = lex_line_command(lines[0])
643
- lines.shift
644
- src = lexed[:params][0].strip
645
- width = lexed[:named_params][:width]
646
- height = lexed[:named_params][:height]
647
- caption = lexed[:text].strip
648
- r << "<div><svg xmlns='http://www.w3.org/2000/svg' version='1.1' xmlns:xlink='http://www.w3.org/1999/xlink' width='100%' height='100%' viewBox='0 0 200 200' ><image xlink:href='#{src}' width='#{width}' height='#{height}' /><p>#{caption}</p></sgv></div>"
649
- end
650
- end
651
- text="svg(img.jpg, width:200, height:200):caption"
652
- artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
653
- artimark.parser(TheParser.new)
654
- converted = artimark.convert(text)
655
- body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
656
- expect(body.element_children[0].selector_and_children).to eq(
657
- ['div',
658
- ["svg[version='1.1'][width='100%'][height='100%'][viewBox='0 0 200 200']", ["image[href='img.jpg'][width='200'][height='200']", ''], ['p', 'caption']]
659
- ]
660
- )
661
- end
662
553
  end
663
554
  end
664
-