nora_mark 0.2beta19 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/dependabot.yml +8 -0
  4. data/.github/workflows/test.yml +19 -0
  5. data/.rubocop.yml +3 -0
  6. data/.travis.yml +2 -2
  7. data/CHANGELOG.md +5 -0
  8. data/Gemfile +0 -1
  9. data/README.md +1 -2
  10. data/Rakefile +1 -4
  11. data/lib/nora_mark/document.rb +14 -14
  12. data/lib/nora_mark/extensions.rb +6 -6
  13. data/lib/nora_mark/html/abstract_node_writer.rb +2 -1
  14. data/lib/nora_mark/html/context.rb +16 -14
  15. data/lib/nora_mark/html/default_transformer.rb +36 -38
  16. data/lib/nora_mark/html/frontmatter_writer.rb +2 -2
  17. data/lib/nora_mark/html/generator.rb +19 -22
  18. data/lib/nora_mark/html/pages.rb +13 -14
  19. data/lib/nora_mark/html/paragraph_writer.rb +24 -26
  20. data/lib/nora_mark/html/raw_text_block_writer.rb +2 -1
  21. data/lib/nora_mark/html/tag_writer.rb +14 -13
  22. data/lib/nora_mark/html/util.rb +5 -5
  23. data/lib/nora_mark/node.rb +45 -55
  24. data/lib/nora_mark/node_set.rb +1 -1
  25. data/lib/nora_mark/node_util.rb +7 -8
  26. data/lib/nora_mark/parser.kpeg.rb +16 -16
  27. data/lib/nora_mark/parser.rb +1 -3
  28. data/lib/nora_mark/rake_task.rb +16 -20
  29. data/lib/nora_mark/transformer.rb +13 -15
  30. data/lib/nora_mark/version.rb +1 -1
  31. data/lib/nora_mark.rb +0 -4
  32. data/lib/tilt/nora_mark.rb +1 -1
  33. data/nora_mark.gemspec +6 -5
  34. data/spec/extensions_spec.rb +1 -2
  35. data/spec/fixtures/test-plugins/nora_mark_tester.rb +3 -1
  36. data/spec/node_spec.rb +69 -49
  37. data/spec/nokogiri_test_helper.rb +9 -7
  38. data/spec/nora_mark_spec.rb +437 -498
  39. data/spec/spec_helper.rb +1 -5
  40. data/spec/tilt_spec.rb +1 -1
  41. data/spec/transformer_spec.rb +16 -18
  42. metadata +36 -27
@@ -1,10 +1,11 @@
1
1
  # -*- encoding: utf-8 -*-
2
+
2
3
  require File.dirname(__FILE__) + '/spec_helper.rb'
3
4
  require File.dirname(__FILE__) + '/../lib/nora_mark'
4
5
  require 'nokogiri'
5
6
  require File.dirname(__FILE__) + '/nokogiri_test_helper.rb'
6
7
 
7
- describe NoraMark::Document do
8
+ describe NoraMark::Document do
8
9
  describe 'parse' do
9
10
  it 'generate valid xhtml' do
10
11
  text = 'some text'
@@ -29,18 +30,17 @@ describe NoraMark::Document do
29
30
  expect(body.element_children.size).to eq 2
30
31
  expect(body.element_children[0].selector_and_children)
31
32
  .to eq(
32
- ['div.pgroup',
33
- ['p', 'ここから、パラグラフがはじまります。'],
34
- ['p.noindent', '「二行目です。」'],
35
- ['p', '三行目です。']
36
- ]
37
- )
33
+ ['div.pgroup',
34
+ ['p', 'ここから、パラグラフがはじまります。'],
35
+ ['p.noindent', '「二行目です。」'],
36
+ ['p', '三行目です。']]
37
+ )
38
38
 
39
39
  expect(body.element_children[1].selector_and_children)
40
40
  .to eq(
41
- ['div.pgroup',
42
- ['p', 'ここから、次のパラグラフです。']]
43
- )
41
+ ['div.pgroup',
42
+ ['p', 'ここから、次のパラグラフです。']]
43
+ )
44
44
  end
45
45
  it 'convert simple paragraph with BOM' do
46
46
  text = "\uFEFFここから、パラグラフがはじまります。\n「二行目です。」\n三行目です。\n\n\n ここから、次のパラグラフです。"
@@ -50,18 +50,17 @@ describe NoraMark::Document do
50
50
  expect(body.element_children.size).to eq 2
51
51
  expect(body.element_children[0].selector_and_children)
52
52
  .to eq(
53
- ['div.pgroup',
54
- ['p', 'ここから、パラグラフがはじまります。'],
55
- ['p.noindent', '「二行目です。」'],
56
- ['p', '三行目です。']
57
- ]
58
- )
53
+ ['div.pgroup',
54
+ ['p', 'ここから、パラグラフがはじまります。'],
55
+ ['p.noindent', '「二行目です。」'],
56
+ ['p', '三行目です。']]
57
+ )
59
58
 
60
59
  expect(body.element_children[1].selector_and_children)
61
60
  .to eq(
62
- ['div.pgroup',
63
- ['p', 'ここから、次のパラグラフです。']]
64
- )
61
+ ['div.pgroup',
62
+ ['p', 'ここから、次のパラグラフです。']]
63
+ )
65
64
  end
66
65
 
67
66
  it 'convert simple paragraph in english mode' do
@@ -72,20 +71,18 @@ describe NoraMark::Document do
72
71
  expect(body.element_children.size).to eq 2
73
72
  expect(body.element_children[0].selector_and_children)
74
73
  .to eq(
75
- ['p',
76
- 'paragraph begins.', ['br', ''],
77
- '2nd line.', ['br', ''],
78
- '3rd line.'
79
- ]
80
- )
74
+ ['p',
75
+ 'paragraph begins.', ['br', ''],
76
+ '2nd line.', ['br', ''],
77
+ '3rd line.']
78
+ )
81
79
 
82
80
  expect(body.element_children[1].selector_and_children)
83
81
  .to eq(
84
- ['p', 'next paragraph.']
85
- )
82
+ ['p', 'next paragraph.']
83
+ )
86
84
  end
87
85
 
88
-
89
86
  it 'convert simple paragraph in english mode specified in frontmatter' do
90
87
  text = "---\nlang: en\ntitle: the title\n---\n\n\n\nparagraph begins.\n2nd line.\n 3rd line.\n\n\n next paragraph."
91
88
  noramark = NoraMark::Document.parse(text)
@@ -94,17 +91,16 @@ describe NoraMark::Document do
94
91
  expect(body.element_children.size).to eq 2
95
92
  expect(body.element_children[0].selector_and_children)
96
93
  .to eq(
97
- ['p',
98
- 'paragraph begins.', ['br', ''],
99
- '2nd line.', ['br', ''],
100
- '3rd line.'
101
- ]
102
- )
94
+ ['p',
95
+ 'paragraph begins.', ['br', ''],
96
+ '2nd line.', ['br', ''],
97
+ '3rd line.']
98
+ )
103
99
 
104
100
  expect(body.element_children[1].selector_and_children)
105
101
  .to eq(
106
- ['p', 'next paragraph.']
107
- )
102
+ ['p', 'next paragraph.']
103
+ )
108
104
  end
109
105
 
110
106
  it 'convert simple paragraph in japanese mode, but paragraph mode is default' do
@@ -115,17 +111,16 @@ describe NoraMark::Document do
115
111
  expect(body.element_children.size).to eq 2
116
112
  expect(body.element_children[0].selector_and_children)
117
113
  .to eq(
118
- ['p',
119
- 'paragraph begins.', ['br', ''],
120
- '2nd line.', ['br', ''],
121
- '3rd line.'
122
- ]
123
- )
114
+ ['p',
115
+ 'paragraph begins.', ['br', ''],
116
+ '2nd line.', ['br', ''],
117
+ '3rd line.']
118
+ )
124
119
 
125
120
  expect(body.element_children[1].selector_and_children)
126
121
  .to eq(
127
- ['p', 'next paragraph.']
128
- )
122
+ ['p', 'next paragraph.']
123
+ )
129
124
  end
130
125
 
131
126
  it 'convert simple paragraph in japanese mode, but paragraph mode is default (using frontmatter)' do
@@ -136,17 +131,16 @@ describe NoraMark::Document do
136
131
  expect(body.element_children.size).to eq 2
137
132
  expect(body.element_children[0].selector_and_children)
138
133
  .to eq(
139
- ['p',
140
- 'paragraph begins.', ['br', ''],
141
- '2nd line.', ['br', ''],
142
- '3rd line.'
143
- ]
144
- )
134
+ ['p',
135
+ 'paragraph begins.', ['br', ''],
136
+ '2nd line.', ['br', ''],
137
+ '3rd line.']
138
+ )
145
139
 
146
140
  expect(body.element_children[1].selector_and_children)
147
141
  .to eq(
148
- ['p', 'next paragraph.']
149
- )
142
+ ['p', 'next paragraph.']
143
+ )
150
144
  end
151
145
  end
152
146
  describe 'attribute handling' do
@@ -156,9 +150,9 @@ describe NoraMark::Document do
156
150
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
157
151
  expect(body.element_children[0].selector_and_children)
158
152
  .to eq(
159
- ['p',
160
- ["span[data-type='foobar']", 'lorem ipsum']]
161
- )
153
+ ['p',
154
+ ["span[data-type='foobar']", 'lorem ipsum']]
155
+ )
162
156
  end
163
157
  end
164
158
  describe 'divs and hN headers' do
@@ -171,17 +165,15 @@ describe NoraMark::Document do
171
165
  expect(body.element_children[0].a).to eq ['h1', 'タイトルです。']
172
166
  expect(body.element_children[1].selector_and_children)
173
167
  .to eq(
174
- ['div.pgroup',
175
- ['p', 'ここから、パラグラフがはじまります。']
176
- ]
177
- )
168
+ ['div.pgroup',
169
+ ['p', 'ここから、パラグラフがはじまります。']]
170
+ )
178
171
  expect(body.element_children[2].a).to eq ['h2.column', 'ふたつめの見出しです。']
179
172
  expect(body.element_children[3].selector_and_children)
180
173
  .to eq(
181
- ['div.pgroup',
182
- ['p', 'ここから、次のパラグラフです。']
183
- ]
184
- )
174
+ ['div.pgroup',
175
+ ['p', 'ここから、次のパラグラフです。']]
176
+ )
185
177
  expect(body.element_children[4].a).to eq ['h3.third.foo', 'クラスが複数ある見出しです']
186
178
  end
187
179
 
@@ -192,15 +184,12 @@ describe NoraMark::Document do
192
184
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
193
185
  expect(body.element_children[0].selector_and_children)
194
186
  .to eq(
195
- ['div',
196
- ['div.pgroup',
197
- ['p', '1st line.']
198
- ]
199
- ]
200
- )
187
+ ['div',
188
+ ['div.pgroup',
189
+ ['p', '1st line.']]]
190
+ )
201
191
  end
202
192
 
203
-
204
193
  it 'parse div without pgroup' do
205
194
  text = "d('wo-pgroup') {\n1st line. \n}"
206
195
  noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title')
@@ -208,10 +197,9 @@ describe NoraMark::Document do
208
197
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
209
198
  expect(body.element_children[0].selector_and_children)
210
199
  .to eq(
211
- ['div',
212
- ['p', '1st line.']
213
- ]
214
- )
200
+ ['div',
201
+ ['p', '1st line.']]
202
+ )
215
203
  end
216
204
 
217
205
  it 'parse nested div without pgroup' do
@@ -221,12 +209,10 @@ describe NoraMark::Document do
221
209
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
222
210
  expect(body.element_children[0].selector_and_children)
223
211
  .to eq(
224
- ['div',
225
- ['div',
226
- ['p', 'nested.']
227
- ]
228
- ]
229
- )
212
+ ['div',
213
+ ['div',
214
+ ['p', 'nested.']]]
215
+ )
230
216
  end
231
217
 
232
218
  it 'handle divs with empty lines' do
@@ -236,17 +222,15 @@ describe NoraMark::Document do
236
222
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
237
223
  expect(body.element_children[0].selector_and_children)
238
224
  .to eq(
239
- ['div',
240
- ['p', '1st line.']
241
- ])
225
+ ['div',
226
+ ['p', '1st line.']]
227
+ )
242
228
  expect(body.element_children[1].selector_and_children)
243
229
  .to eq(
244
- ['div',
245
- ['div.pgroup',
246
- ['p', '2nd div.']]
247
- ]
248
-
249
- )
230
+ ['div',
231
+ ['div.pgroup',
232
+ ['p', '2nd div.']]]
233
+ )
250
234
  end
251
235
 
252
236
  it 'parse nested div without pgroup and with pgroup' do
@@ -256,18 +240,16 @@ describe NoraMark::Document do
256
240
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
257
241
  expect(body.element_children[0].selector_and_children)
258
242
  .to eq(
259
- ['div',
260
- ['div',
261
- ['p', 'nested.']
262
- ]
263
- ])
243
+ ['div',
244
+ ['div',
245
+ ['p', 'nested.']]]
246
+ )
264
247
  expect(body.element_children[1].selector_and_children)
265
248
  .to eq(
266
- ['div',
267
- ['div.pgroup',
268
- ['p', 'in pgroup']
269
- ]
270
- ])
249
+ ['div',
250
+ ['div.pgroup',
251
+ ['p', 'in pgroup']]]
252
+ )
271
253
  end
272
254
 
273
255
  it 'parse div with class' do
@@ -277,10 +259,9 @@ describe NoraMark::Document do
277
259
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
278
260
  expect(body.element_children[0].selector_and_children)
279
261
  .to eq(
280
- ['div.preface-one',
281
- ['h1', 'title.']
282
- ]
283
- )
262
+ ['div.preface-one',
263
+ ['h1', 'title.']]
264
+ )
284
265
  end
285
266
 
286
267
  it 'parse div with id and class' do
@@ -290,10 +271,9 @@ describe NoraMark::Document do
290
271
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
291
272
  expect(body.element_children[0].selector_and_children(remove_id: false))
292
273
  .to eq(
293
- ['div#thecontents.preface-one',
294
- ['h1#heading_index_1', 'title.']
295
- ]
296
- )
274
+ ['div#thecontents.preface-one',
275
+ ['h1#heading_index_1', 'title.']]
276
+ )
297
277
  end
298
278
 
299
279
  it 'parse nested div' do
@@ -303,20 +283,15 @@ describe NoraMark::Document do
303
283
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
304
284
  expect(body.element_children[0].selector_and_children)
305
285
  .to eq(
306
- ['div.preface',
307
- ['div.pgroup',
308
- ['p', 'outer div.']
309
- ],
310
- ['div.nested',
311
- ['div.pgroup',
312
- ['p', 'nested!']
313
- ]
314
- ],
315
- ['div.pgroup',
316
- ['p', 'outer div again.']
317
- ],
318
- ]
319
- )
286
+ ['div.preface',
287
+ ['div.pgroup',
288
+ ['p', 'outer div.']],
289
+ ['div.nested',
290
+ ['div.pgroup',
291
+ ['p', 'nested!']]],
292
+ ['div.pgroup',
293
+ ['p', 'outer div again.']],]
294
+ )
320
295
  end
321
296
  end
322
297
  describe 'article and section' do
@@ -327,12 +302,10 @@ describe NoraMark::Document do
327
302
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
328
303
  expect(body.element_children[0].selector_and_children)
329
304
  .to eq(
330
- ['article',
331
- ['div.pgroup',
332
- ['p', 'in the article.']
333
- ]
334
- ]
335
- )
305
+ ['article',
306
+ ['div.pgroup',
307
+ ['p', 'in the article.']]]
308
+ )
336
309
  end
337
310
 
338
311
  it 'parse article with other notation' do
@@ -342,12 +315,10 @@ describe NoraMark::Document do
342
315
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
343
316
  expect(body.element_children[0].selector_and_children)
344
317
  .to eq(
345
- ['article',
346
- ['div.pgroup',
347
- ['p', 'in the article.']
348
- ]
349
- ]
350
- )
318
+ ['article',
319
+ ['div.pgroup',
320
+ ['p', 'in the article.']]]
321
+ )
351
322
  end
352
323
 
353
324
  it 'parse article with yet anther notation' do
@@ -357,12 +328,10 @@ describe NoraMark::Document do
357
328
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
358
329
  expect(body.element_children[0].selector_and_children)
359
330
  .to eq(
360
- ['article',
361
- ['div.pgroup',
362
- ['p', 'in the article.']
363
- ]
364
- ]
365
- )
331
+ ['article',
332
+ ['div.pgroup',
333
+ ['p', 'in the article.']]]
334
+ )
366
335
  end
367
336
 
368
337
  it 'parse section ' do
@@ -372,14 +341,11 @@ describe NoraMark::Document do
372
341
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
373
342
  expect(body.element_children[0].selector_and_children)
374
343
  .to eq(
375
- ['article',
376
- ['section',
377
- ['div.pgroup',
378
- ['p', 'section in the article.']
379
- ]
380
- ]
381
- ]
382
- )
344
+ ['article',
345
+ ['section',
346
+ ['div.pgroup',
347
+ ['p', 'section in the article.']]]]
348
+ )
383
349
  end
384
350
 
385
351
  it 'parse section with other notation' do
@@ -389,14 +355,11 @@ describe NoraMark::Document do
389
355
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
390
356
  expect(body.element_children[0].selector_and_children)
391
357
  .to eq(
392
- ['article',
393
- ['section',
394
- ['div.pgroup',
395
- ['p', 'section in the article.']
396
- ]
397
- ]
398
- ]
399
- )
358
+ ['article',
359
+ ['section',
360
+ ['div.pgroup',
361
+ ['p', 'section in the article.']]]]
362
+ )
400
363
  end
401
364
 
402
365
  it 'parse section with yet other notation' do
@@ -406,14 +369,11 @@ describe NoraMark::Document do
406
369
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
407
370
  expect(body.element_children[0].selector_and_children)
408
371
  .to eq(
409
- ['article',
410
- ['section',
411
- ['div.pgroup',
412
- ['p', 'section in the article.']
413
- ]
414
- ]
415
- ]
416
- )
372
+ ['article',
373
+ ['section',
374
+ ['div.pgroup',
375
+ ['p', 'section in the article.']]]]
376
+ )
417
377
  end
418
378
  end
419
379
  describe 'other block command' do
@@ -424,17 +384,15 @@ describe NoraMark::Document do
424
384
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
425
385
  expect(body.element_children[0].selector_and_children)
426
386
  .to eq(
427
- ['div.pgroup',
428
- ['p', 'this is normal line.']
429
- ]
430
- )
387
+ ['div.pgroup',
388
+ ['p', 'this is normal line.']]
389
+ )
431
390
  expect(body.element_children[1].selector_and_children)
432
391
  .to eq(
433
- ['figure.img-wrap',
434
- ["img[src='./image1.jpg'][alt='alt text']", ''],
435
- ['figcaption', 'caption text']
436
- ]
437
- )
392
+ ['figure.img-wrap',
393
+ ["img[src='./image1.jpg'][alt='alt text']", ''],
394
+ ['figcaption', 'caption text']]
395
+ )
438
396
  end
439
397
 
440
398
  it 'handle block image with before caption' do
@@ -444,17 +402,15 @@ describe NoraMark::Document do
444
402
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
445
403
  expect(body.element_children[0].selector_and_children)
446
404
  .to eq(
447
- ['div.pgroup',
448
- ['p', 'this is normal line.']
449
- ]
450
- )
405
+ ['div.pgroup',
406
+ ['p', 'this is normal line.']]
407
+ )
451
408
  expect(body.element_children[1].selector_and_children)
452
409
  .to eq(
453
- ['figure.img-wrap',
454
- ['figcaption', 'caption text'],
455
- ["img[src='./image1.jpg'][alt='alt text']", '']
456
- ]
457
- )
410
+ ['figure.img-wrap',
411
+ ['figcaption', 'caption text'],
412
+ ["img[src='./image1.jpg'][alt='alt text']", '']]
413
+ )
458
414
  end
459
415
 
460
416
  it 'handle block image without caption' do
@@ -464,16 +420,14 @@ describe NoraMark::Document do
464
420
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
465
421
  expect(body.element_children[0].selector_and_children)
466
422
  .to eq(
467
- ['div.pgroup',
468
- ['p', 'this is normal line.']
469
- ]
470
- )
423
+ ['div.pgroup',
424
+ ['p', 'this is normal line.']]
425
+ )
471
426
  expect(body.element_children[1].selector_and_children)
472
427
  .to eq(
473
- ['figure.img-wrap',
474
- ["img[src='./image1.jpg'][alt='alt text']", '']
475
- ]
476
- )
428
+ ['figure.img-wrap',
429
+ ["img[src='./image1.jpg'][alt='alt text']", '']]
430
+ )
477
431
  end
478
432
 
479
433
  it 'handle page change article' do
@@ -485,30 +439,27 @@ describe NoraMark::Document do
485
439
  body1 = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
486
440
  expect(body1.element_children[0].selector_and_children)
487
441
  .to eq(
488
- ['div.pgroup',
489
- ['p', 'this is start.']
490
- ]
491
- )
442
+ ['div.pgroup',
443
+ ['p', 'this is start.']]
444
+ )
492
445
 
493
446
  head2 = Nokogiri::XML::Document.parse(converted[1]).root.at_xpath('xmlns:head')
494
447
  expect(head2.element_children[0].a).to eq ['title', 'page changed']
495
448
  body2 = Nokogiri::XML::Document.parse(converted[1]).root.at_xpath('xmlns:body')
496
449
  expect(body2.element_children[0].selector_and_children)
497
450
  .to eq(
498
- ['div.pgroup',
499
- ['p', 'this is second page.']
500
- ]
501
- )
451
+ ['div.pgroup',
452
+ ['p', 'this is second page.']]
453
+ )
502
454
 
503
455
  head3 = Nokogiri::XML::Document.parse(converted[2]).root.at_xpath('xmlns:head')
504
- expect(head3.element_children[0].a).to eq ['title', 'the title']
456
+ expect(head3.element_children[0].a).to eq ['title', 'the title']
505
457
  body3 = Nokogiri::XML::Document.parse(converted[2]).root.at_xpath('xmlns:body')
506
458
  expect(body3.element_children[0].selector_and_children)
507
459
  .to eq(
508
- ['div.pgroup',
509
- ['p', 'and the third.']
510
- ]
511
- )
460
+ ['div.pgroup',
461
+ ['p', 'and the third.']]
462
+ )
512
463
  end
513
464
 
514
465
  it 'handle stylesheets' do
@@ -528,11 +479,10 @@ describe NoraMark::Document do
528
479
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
529
480
  expect(body.element_children[0].selector_and_children)
530
481
  .to eq(
531
- ['div.pgroup',
532
- ['p', 'this is normal line.'],
533
- ['p.custom', 'this text is in custom class.']
534
- ]
535
- )
482
+ ['div.pgroup',
483
+ ['p', 'this is normal line.'],
484
+ ['p.custom', 'this text is in custom class.']]
485
+ )
536
486
  end
537
487
 
538
488
  it 'handle any block' do
@@ -542,18 +492,15 @@ describe NoraMark::Document do
542
492
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
543
493
  expect(body.element_children[0].selector_and_children)
544
494
  .to eq(
545
- ['div.pgroup',
546
- ['p', 'this is normal line.']
547
- ]
548
- )
495
+ ['div.pgroup',
496
+ ['p', 'this is normal line.']]
497
+ )
549
498
  expect(body.element_children[1].selector_and_children)
550
499
  .to eq(
551
- ['cite',
552
- ['div.pgroup',
553
- ['p', 'this block should be in cite.']
554
- ]
555
- ]
556
- )
500
+ ['cite',
501
+ ['div.pgroup',
502
+ ['p', 'this block should be in cite.']]]
503
+ )
557
504
  end
558
505
  it 'convert h1 in article after title' do
559
506
  text = "---\nstylesheets: css/default.css\ntitle: foo\n---\narticle.atogaki {\n\nh1: あとがき。\n\natogaki\n}"
@@ -562,13 +509,12 @@ describe NoraMark::Document do
562
509
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
563
510
  expect(body.element_children[0].selector_and_children)
564
511
  .to eq(
565
- ["article.atogaki",
566
- ["h1", "あとがき。"],
567
- ["div.pgroup",
568
- ["p", "atogaki"]]]
569
- )
512
+ ["article.atogaki",
513
+ ["h1", "あとがき。"],
514
+ ["div.pgroup",
515
+ ["p", "atogaki"]]]
516
+ )
570
517
  end
571
-
572
518
  end
573
519
  describe 'inline' do
574
520
  it 'handle link' do
@@ -578,15 +524,13 @@ describe NoraMark::Document do
578
524
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
579
525
  expect(body.element_children[0].selector_and_children)
580
526
  .to eq(
581
- ['div.pgroup',
582
- ['p',
583
- 'link to ',
584
- ["a[href='http://github.com/skoji/noramark']", 'noramark repository'],
585
- '.'
586
- ],
587
- ['p', 'can you see this?']
588
- ]
589
- )
527
+ ['div.pgroup',
528
+ ['p',
529
+ 'link to ',
530
+ ["a[href='http://github.com/skoji/noramark']", 'noramark repository'],
531
+ '.'],
532
+ ['p', 'can you see this?']]
533
+ )
590
534
  end
591
535
 
592
536
  it 'handle link with l' do
@@ -596,15 +540,13 @@ describe NoraMark::Document do
596
540
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
597
541
  expect(body.element_children[0].selector_and_children)
598
542
  .to eq(
599
- ['div.pgroup',
600
- ['p',
601
- 'link to ',
602
- ["a[href='http://github.com/skoji/noramark']", 'noramark repository'],
603
- '.'
604
- ],
605
- ['p', 'can you see this?']
606
- ]
607
- )
543
+ ['div.pgroup',
544
+ ['p',
545
+ 'link to ',
546
+ ["a[href='http://github.com/skoji/noramark']", 'noramark repository'],
547
+ '.'],
548
+ ['p', 'can you see this?']]
549
+ )
608
550
  end
609
551
 
610
552
  it 'handle span' do
@@ -614,10 +556,9 @@ describe NoraMark::Document do
614
556
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
615
557
  expect(body.element_children[0].selector_and_children)
616
558
  .to eq(
617
- ['div.pgroup',
618
- ['p.custom', 'this text is in ', ['span.keyword', 'custom'], ' class.'
619
- ]]
620
- )
559
+ ['div.pgroup',
560
+ ['p.custom', 'this text is in ', ['span.keyword', 'custom'], ' class.']]
561
+ )
621
562
  end
622
563
 
623
564
  it 'handle inline image' do
@@ -627,10 +568,10 @@ describe NoraMark::Document do
627
568
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
628
569
  expect(body.element_children[0].selector_and_children)
629
570
  .to eq(
630
- ['div.pgroup',
631
- ['p',
632
- 'simple image ', ["img[src='./image1.jpg'][alt='alt']", ''], '.']]
633
- )
571
+ ['div.pgroup',
572
+ ['p',
573
+ 'simple image ', ["img[src='./image1.jpg'][alt='alt']", ''], '.']]
574
+ )
634
575
  end
635
576
 
636
577
  it 'handle any inline' do
@@ -640,9 +581,9 @@ describe NoraMark::Document do
640
581
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
641
582
  expect(body.element_children[0].selector_and_children)
642
583
  .to eq(
643
- ['div.pgroup',
644
- ['p', 'should be ', ['strong', 'marked as strong'],'.']]
645
- )
584
+ ['div.pgroup',
585
+ ['p', 'should be ', ['strong', 'marked as strong'], '.']]
586
+ )
646
587
  end
647
588
 
648
589
  it 'convert inline command within line block' do
@@ -658,10 +599,10 @@ describe NoraMark::Document do
658
599
  noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title')
659
600
  converted = noramark.html
660
601
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
661
- expect(body.element_children[0].selector_and_children).to eq ['div.pgroup', ['p',
662
- ['ruby', '蜻蛉', ['rp','('],['rt','とんぼ'],['rp', ')']],
663
- 'の',
664
- ['ruby', '眼鏡', ['rp','('],['rt','めがね'],['rp', ')']],
602
+ expect(body.element_children[0].selector_and_children).to eq ['div.pgroup', ['p',
603
+ ['ruby', '蜻蛉', ['rp', '('], ['rt', 'とんぼ'], ['rp', ')']],
604
+ 'の',
605
+ ['ruby', '眼鏡', ['rp', '('], ['rt', 'めがね'], ['rp', ')']],
665
606
  'はみずいろめがね']]
666
607
  end
667
608
 
@@ -672,54 +613,54 @@ describe NoraMark::Document do
672
613
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
673
614
  expect(body.element_children[0].selector_and_children)
674
615
  .to eq(
675
- ['div.pgroup',
676
- ['p', ['span.tcy', '10'], '年前のことだった']
677
- ])
616
+ ['div.pgroup',
617
+ ['p', ['span.tcy', '10'], '年前のことだった']]
618
+ )
678
619
  end
679
620
 
680
621
  it 'handle code inline' do
681
622
  text = "`this is inside code and [s{will not parsed}]`. you see?"
682
623
  noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title')
683
- converted = noramark.html
624
+ converted = noramark.html
684
625
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
685
626
  expect(body.element_children[0].selector_and_children)
686
627
  .to eq(
687
- ['div.pgroup',
688
- ['p', ['code', 'this is inside code and [s{will not parsed}]'], '. you see?']
689
- ])
628
+ ['div.pgroup',
629
+ ['p', ['code', 'this is inside code and [s{will not parsed}]'], '. you see?']]
630
+ )
690
631
  end
691
632
  it 'handle code escaped inline' do
692
633
  text = "\\`this is not inside code and [strong{will be parsed}]\\`. you see?"
693
634
  noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title')
694
- converted = noramark.html
635
+ converted = noramark.html
695
636
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
696
637
  expect(body.element_children[0].selector_and_children)
697
638
  .to eq(
698
- ['div.pgroup',
699
- ['p', '`this is not inside code and ', ['strong', 'will be parsed'], '`. you see?']
700
- ])
639
+ ['div.pgroup',
640
+ ['p', '`this is not inside code and ', ['strong', 'will be parsed'], '`. you see?']]
641
+ )
701
642
  end
702
643
  it 'handle code inline (long format)' do
703
644
  text = "[code.the-class{this is inside code and `backquote will not be parsed`}]. you see?"
704
645
  noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title')
705
- converted = noramark.html
646
+ converted = noramark.html
706
647
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
707
648
  expect(body.element_children[0].selector_and_children)
708
649
  .to eq(
709
- ['div.pgroup',
710
- ['p', ['code.the-class', 'this is inside code and `backquote will not be parsed`'], '. you see?']
711
- ])
650
+ ['div.pgroup',
651
+ ['p', ['code.the-class', 'this is inside code and `backquote will not be parsed`'], '. you see?']]
652
+ )
712
653
  end
713
654
  it 'handle non-escaped inline' do
714
655
  text = "the text following will not be escaped: [noescape{©}]"
715
656
  noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title')
716
- converted = noramark.html
657
+ converted = noramark.html
717
658
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
718
659
  expect(body.element_children[0].selector_and_children)
719
660
  .to eq(
720
- ['div.pgroup',
721
- ['p', 'the text following will not be escaped: ©']
722
- ])
661
+ ['div.pgroup',
662
+ ['p', 'the text following will not be escaped: ©']]
663
+ )
723
664
  end
724
665
  end
725
666
  describe 'list' do
@@ -731,21 +672,21 @@ describe NoraMark::Document do
731
672
  expect(body.element_children.size).to eq 3
732
673
  expect(body.element_children[0].selector_and_children)
733
674
  .to eq(
734
- ['div.pgroup',
735
- ['p', 'this is normal line.']
736
- ])
675
+ ['div.pgroup',
676
+ ['p', 'this is normal line.']]
677
+ )
737
678
  expect(body.element_children[1].selector_and_children)
738
679
  .to eq(
739
- ['ol',
740
- ['li', 'for the 1st.'],
741
- ['li', 'secondly, blah.'],
742
- ['li', 'and last...']
743
- ])
680
+ ['ol',
681
+ ['li', 'for the 1st.'],
682
+ ['li', 'secondly, blah.'],
683
+ ['li', 'and last...']]
684
+ )
744
685
  expect(body.element_children[2].selector_and_children)
745
686
  .to eq(
746
- ['div.pgroup',
747
- ['p', 'the ordered list ends.']
748
- ])
687
+ ['div.pgroup',
688
+ ['p', 'the ordered list ends.']]
689
+ )
749
690
  end
750
691
 
751
692
  it 'handle unordered list ' do
@@ -756,21 +697,21 @@ describe NoraMark::Document do
756
697
  expect(body.element_children.size).to eq 3
757
698
  expect(body.element_children[0].selector_and_children)
758
699
  .to eq(
759
- ['div.pgroup',
760
- ['p', 'this is normal line.']
761
- ])
700
+ ['div.pgroup',
701
+ ['p', 'this is normal line.']]
702
+ )
762
703
  expect(body.element_children[1].selector_and_children)
763
704
  .to eq(
764
- ['ul',
765
- ['li', 'for the 1st.'],
766
- ['li', 'secondly, blah.'],
767
- ['li', 'and last...']
768
- ])
705
+ ['ul',
706
+ ['li', 'for the 1st.'],
707
+ ['li', 'secondly, blah.'],
708
+ ['li', 'and last...']]
709
+ )
769
710
  expect(body.element_children[2].selector_and_children)
770
711
  .to eq(
771
- ['div.pgroup',
772
- ['p', 'the ordered list ends.']
773
- ])
712
+ ['div.pgroup',
713
+ ['p', 'the ordered list ends.']]
714
+ )
774
715
  end
775
716
 
776
717
  it 'handle nested unordered list ' do
@@ -781,22 +722,22 @@ describe NoraMark::Document do
781
722
  expect(body.element_children.size).to eq 3
782
723
  expect(body.element_children[0].selector_and_children)
783
724
  .to eq(
784
- ['div.pgroup',
785
- ['p', 'this is normal line.']
786
- ])
725
+ ['div.pgroup',
726
+ ['p', 'this is normal line.']]
727
+ )
787
728
  expect(body.element_children[1].selector_and_children)
788
729
  .to eq(
789
- ['ul',
790
- ['li', 'for the 1st.',
791
- ['ul',
792
- ['li', 'nested.']]],
793
- ['li', 'and last...']
794
- ])
730
+ ['ul',
731
+ ['li', 'for the 1st.',
732
+ ['ul',
733
+ ['li', 'nested.']]],
734
+ ['li', 'and last...']]
735
+ )
795
736
  expect(body.element_children[2].selector_and_children)
796
737
  .to eq(
797
- ['div.pgroup',
798
- ['p', 'the ordered list ends.']
799
- ])
738
+ ['div.pgroup',
739
+ ['p', 'the ordered list ends.']]
740
+ )
800
741
  end
801
742
 
802
743
  it 'handle definition list ' do
@@ -807,21 +748,21 @@ describe NoraMark::Document do
807
748
  expect(body.element_children.size).to eq 3
808
749
  expect(body.element_children[0].selector_and_children)
809
750
  .to eq(
810
- ['div.pgroup',
811
- ['p', 'this is normal line.']
812
- ])
751
+ ['div.pgroup',
752
+ ['p', 'this is normal line.']]
753
+ )
813
754
  expect(body.element_children[1].selector_and_children)
814
755
  .to eq(
815
- ['dl',
816
- ['dt', '1st'],['dd', 'this is the first definition'],
817
- ['dt', '2nd'],['dd', 'blah :blah.'],
818
- ['dt', '3rd'],['dd', 'this term is the last.'],
819
- ])
756
+ ['dl',
757
+ ['dt', '1st'], ['dd', 'this is the first definition'],
758
+ ['dt', '2nd'], ['dd', 'blah :blah.'],
759
+ ['dt', '3rd'], ['dd', 'this term is the last.'],]
760
+ )
820
761
  expect(body.element_children[2].selector_and_children)
821
762
  .to eq(
822
- ['div.pgroup',
823
- ['p', 'the list ends.']
824
- ])
763
+ ['div.pgroup',
764
+ ['p', 'the list ends.']]
765
+ )
825
766
  end
826
767
 
827
768
  it 'handle long definition list ' do
@@ -832,21 +773,21 @@ describe NoraMark::Document do
832
773
  expect(body.element_children.size).to eq 3
833
774
  expect(body.element_children[0].selector_and_children)
834
775
  .to eq(
835
- ['div.pgroup',
836
- ['p', 'this is normal line.']
837
- ])
776
+ ['div.pgroup',
777
+ ['p', 'this is normal line.']]
778
+ )
838
779
  expect(body.element_children[1].selector_and_children)
839
780
  .to eq(
840
- ['dl',
841
- ['dt', '1st'],['dd', ['div.pgroup', ['p', 'this is the first definition']]],
842
- ['dt', '2nd'],['dd', ['div.pgroup', ['p', 'blah :blah.']]],
843
- ['dt', '3rd'],['dd', ['div.pgroup', ['p', 'this term is the last.']]]
844
- ])
781
+ ['dl',
782
+ ['dt', '1st'], ['dd', ['div.pgroup', ['p', 'this is the first definition']]],
783
+ ['dt', '2nd'], ['dd', ['div.pgroup', ['p', 'blah :blah.']]],
784
+ ['dt', '3rd'], ['dd', ['div.pgroup', ['p', 'this term is the last.']]]]
785
+ )
845
786
  expect(body.element_children[2].selector_and_children)
846
787
  .to eq(
847
- ['div.pgroup',
848
- ['p', 'the list ends.']
849
- ])
788
+ ['div.pgroup',
789
+ ['p', 'the list ends.']]
790
+ )
850
791
  end
851
792
  it 'escape html in definition list' do
852
793
  text = ";:definition<div>:</div>"
@@ -855,12 +796,12 @@ describe NoraMark::Document do
855
796
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
856
797
  expect(body.element_children[0].selector_and_children)
857
798
  .to eq(
858
- ['dl',
859
- ['dt', 'definition<div>'],['dd', '</div>']
860
- ])
799
+ ['dl',
800
+ ['dt', 'definition<div>'], ['dd', '</div>']]
801
+ )
861
802
  end
862
803
  end
863
-
804
+
864
805
  describe 'metadata' do
865
806
  it 'specify stylesheets' do
866
807
  text = <<EOF
@@ -881,9 +822,10 @@ EOF
881
822
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
882
823
  expect(body.element_children[0].selector_and_children)
883
824
  .to eq(
884
- ['div.pgroup',
885
- ['p',
886
- 'text.']])
825
+ ['div.pgroup',
826
+ ['p',
827
+ 'text.']]
828
+ )
887
829
  end
888
830
 
889
831
  it 'specify title' do
@@ -895,10 +837,10 @@ EOF
895
837
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
896
838
  expect(body.element_children[0].selector_and_children)
897
839
  .to eq(
898
- ['div.pgroup',
899
- ['p',
900
- 'text.']])
901
-
840
+ ['div.pgroup',
841
+ ['p',
842
+ 'text.']]
843
+ )
902
844
  end
903
845
 
904
846
  it 'specify title on each page' do
@@ -912,16 +854,18 @@ EOF
912
854
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
913
855
  expect(body.element_children[0].selector_and_children)
914
856
  .to eq(
915
- ['div.pgroup',
916
- ['p',
917
- '1st page.']])
857
+ ['div.pgroup',
858
+ ['p',
859
+ '1st page.']]
860
+ )
918
861
  # 2nd page
919
862
  head = Nokogiri::XML::Document.parse(converted[1]).root.at_xpath('xmlns:head')
920
863
  expect(head.element_children[0].a).to eq ['title', 'page2']
921
864
  body = Nokogiri::XML::Document.parse(converted[1]).root.at_xpath('xmlns:body')
922
865
  expect(body.element_children[0].selector_and_children)
923
866
  .to eq(
924
- ['h1',"2nd page"])
867
+ ['h1', "2nd page"]
868
+ )
925
869
  end
926
870
 
927
871
  it 'specify stylesheet on each page' do
@@ -956,7 +900,7 @@ EOF
956
900
  expect(head.element_children[1].a).to eq ["link[rel='stylesheet'][type='text/css'][href='default.css']", '']
957
901
  end
958
902
 
959
- it 'specify stylesheet on each page, with default supplied' do
903
+ it 'specify stylesheet on each page, with default supplied' do
960
904
  text = <<EOF
961
905
  ---
962
906
  title: document title 1st
@@ -987,7 +931,6 @@ EOF
987
931
  expect(head.element_children[1].a).to eq ["link[rel='stylesheet'][type='text/css'][href='default.css']", '']
988
932
  end
989
933
 
990
-
991
934
  it 'ignore comments' do
992
935
  text = "// この行はコメントです\nここから、パラグラフがはじまります。\n // これもコメント\n「二行目です。」\n三行目です。\n\n// これもコメント\n\n ここから、次のパラグラフです。\n// 最後のコメントです"
993
936
  noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title')
@@ -997,26 +940,23 @@ EOF
997
940
 
998
941
  expect(body.element_children[0].selector_and_children)
999
942
  .to eq(
1000
- ['div.pgroup',
1001
- ['p', 'ここから、パラグラフがはじまります。'],
1002
- ['p.noindent', '「二行目です。」'],
1003
- ['p', '三行目です。']
1004
- ]
1005
- )
943
+ ['div.pgroup',
944
+ ['p', 'ここから、パラグラフがはじまります。'],
945
+ ['p.noindent', '「二行目です。」'],
946
+ ['p', '三行目です。']]
947
+ )
1006
948
 
1007
949
  expect(body.element_children[1].selector_and_children)
1008
950
  .to eq(
1009
- ['div.pgroup',
1010
- ['p', 'ここから、次のパラグラフです。']]
1011
- )
951
+ ['div.pgroup',
952
+ ['p', 'ここから、次のパラグラフです。']]
953
+ )
1012
954
  end
1013
955
 
1014
956
  it 'handle preprocessor' do
1015
957
  text = "pre-preprocess text"
1016
- noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') do
1017
- |nora|
1018
- nora.preprocessor do
1019
- |t|
958
+ noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') do |nora|
959
+ nora.preprocessor do |t|
1020
960
  t.gsub('pre-preprocess', 'post-process')
1021
961
  end
1022
962
  end
@@ -1024,10 +964,9 @@ EOF
1024
964
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
1025
965
  expect(body.element_children[0].selector_and_children)
1026
966
  .to eq(
1027
- ['div.pgroup',
1028
- ['p', 'post-process text'],
1029
- ]
1030
- )
967
+ ['div.pgroup',
968
+ ['p', 'post-process text'],]
969
+ )
1031
970
  end
1032
971
  end
1033
972
 
@@ -1097,7 +1036,7 @@ EOF
1097
1036
  .to eq(["div.pgroup", ["p", "normal line again."]])
1098
1037
  end
1099
1038
 
1100
- it 'convert preformatted code with language fence format' do
1039
+ it 'convert preformatted code with language fence format' do
1101
1040
  text = <<EOF
1102
1041
  normal line.
1103
1042
  ```ruby
@@ -1172,15 +1111,13 @@ EOF
1172
1111
  .to eq(["div.pgroup", ["p", "normal line."]])
1173
1112
  expect(body.element_children[1].selector_and_children)
1174
1113
  .to eq(
1175
- ["div.pre",
1176
- ["p.caption", "caption ", ["span.the-text", "text"]],
1177
- ["pre", "d {\n this will not converted to div or p or pgroup.\nline_command: this will be not converted too.\n}"]
1178
- ])
1179
-
1180
-
1114
+ ["div.pre",
1115
+ ["p.caption", "caption ", ["span.the-text", "text"]],
1116
+ ["pre", "d {\n this will not converted to div or p or pgroup.\nline_command: this will be not converted too.\n}"]]
1117
+ )
1181
1118
  end
1182
1119
 
1183
- it 'convert preformatted code with language fence format with caption' do
1120
+ it 'convert preformatted code with language fence format with caption' do
1184
1121
  text = <<EOF
1185
1122
  normal line.
1186
1123
  ```ruby(the caption text)
@@ -1196,10 +1133,11 @@ EOF
1196
1133
  .to eq(["div.pgroup", ["p", "normal line."]])
1197
1134
  expect(body.element_children[1].selector_and_children)
1198
1135
  .to eq(
1199
- ["div.pre",
1200
- ["p.caption", "the caption text"],
1201
- ["pre.code-ruby[data-code-language='ruby']",
1202
- ["code", "# ruby code example.\n\"Hello, World\".split(',').map(&:strip).map(&:to_sym) # => [:Hello, :World]"]]])
1136
+ ["div.pre",
1137
+ ["p.caption", "the caption text"],
1138
+ ["pre.code-ruby[data-code-language='ruby']",
1139
+ ["code", "# ruby code example.\n\"Hello, World\".split(',').map(&:strip).map(&:to_sym) # => [:Hello, :World]"]]]
1140
+ )
1203
1141
  expect(body.element_children[2].selector_and_children)
1204
1142
  .to eq(["div.pgroup", ["p", "normal line again."]])
1205
1143
  end
@@ -1220,9 +1158,10 @@ EOF
1220
1158
  .to eq(["div.pgroup", ["p", "normal line."]])
1221
1159
  expect(body.element_children[1].selector_and_children)
1222
1160
  .to eq(
1223
- ["table",
1224
- ["tr",
1225
- ["td", 'you can write anything here.']]])
1161
+ ["table",
1162
+ ["tr",
1163
+ ["td", 'you can write anything here.']]]
1164
+ )
1226
1165
  expect(body.element_children[2].selector_and_children)
1227
1166
  .to eq(["div.pgroup", ["p", "normal line again."]])
1228
1167
  end
@@ -1237,11 +1176,11 @@ EOF
1237
1176
  expect(body.element_children.size).to eq 1
1238
1177
  expect(body.element_children[0].selector_and_children)
1239
1178
  .to eq(
1240
- ['section',
1241
- ['h1', 'タイトル です。'],
1242
- ['div.pgroup',
1243
- ['p', 'これは、セクションの中です。']]]
1244
- )
1179
+ ['section',
1180
+ ['h1', 'タイトル です。'],
1181
+ ['div.pgroup',
1182
+ ['p', 'これは、セクションの中です。']]]
1183
+ )
1245
1184
  end
1246
1185
 
1247
1186
  it 'should convert markdown style heading : without header' do
@@ -1252,12 +1191,12 @@ EOF
1252
1191
  expect(body.element_children.size).to eq 1
1253
1192
  expect(body.element_children[0].selector_and_children)
1254
1193
  .to eq(
1255
- ['section',
1256
- ['div.pgroup',
1257
- ['p', 'これは、セクションの中です。']]]
1258
- )
1194
+ ['section',
1195
+ ['div.pgroup',
1196
+ ['p', 'これは、セクションの中です。']]]
1197
+ )
1259
1198
  end
1260
-
1199
+
1261
1200
  it 'should convert markdown style heading with empty body' do
1262
1201
  text = "# タイトルです。\n* 中身です。\n\n## 次のタイトルです。これから書きます。\n\n## ここもこれから。"
1263
1202
  noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title')
@@ -1265,13 +1204,14 @@ EOF
1265
1204
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
1266
1205
  expect(body.element_children[0].selector_and_children)
1267
1206
  .to eq(
1268
- ['section',
1269
- ['h1', 'タイトルです。'],
1270
- ['ul', ['li', '中身です。']],
1271
- ['section',
1272
- ['h2', '次のタイトルです。これから書きます。']],
1273
- ['section',
1274
- ['h2', 'ここもこれから。']]])
1207
+ ['section',
1208
+ ['h1', 'タイトルです。'],
1209
+ ['ul', ['li', '中身です。']],
1210
+ ['section',
1211
+ ['h2', '次のタイトルです。これから書きます。']],
1212
+ ['section',
1213
+ ['h2', 'ここもこれから。']]]
1214
+ )
1275
1215
  end
1276
1216
  it 'should markdown style heading interrupted by other headed section' do
1277
1217
  text = "# タイトルです。\r\nこれは、セクションの中です。\n # また次のセクションです。\n次のセクションの中です。"
@@ -1281,17 +1221,18 @@ EOF
1281
1221
  expect(body.element_children.size).to eq 2
1282
1222
  expect(body.element_children[0].selector_and_children)
1283
1223
  .to eq(
1284
- ['section',
1285
- ['h1', 'タイトルです。'],
1286
- ['div.pgroup',
1287
- ['p', 'これは、セクションの中です。']]])
1224
+ ['section',
1225
+ ['h1', 'タイトルです。'],
1226
+ ['div.pgroup',
1227
+ ['p', 'これは、セクションの中です。']]]
1228
+ )
1288
1229
  expect(body.element_children[1].selector_and_children)
1289
1230
  .to eq(
1290
- ['section',
1291
- ['h1', 'また次のセクションです。'],
1292
- ['div.pgroup',
1293
- ['p', '次のセクションの中です。']]]
1294
- )
1231
+ ['section',
1232
+ ['h1', 'また次のセクションです。'],
1233
+ ['div.pgroup',
1234
+ ['p', '次のセクションの中です。']]]
1235
+ )
1295
1236
  end
1296
1237
  it 'should markdown style heading not interrupted by other explicit section' do
1297
1238
  text = "# タイトルです。\r\nこれは、セクションの中です。\n section {\n h2: また次のセクションです。\n入れ子になります。\n}\nこのように。"
@@ -1301,17 +1242,17 @@ EOF
1301
1242
  expect(body.element_children.size).to eq 1
1302
1243
  expect(body.element_children[0].selector_and_children)
1303
1244
  .to eq(
1304
- ['section',
1305
- ['h1', 'タイトルです。'],
1306
- ['div.pgroup',
1307
- ['p', 'これは、セクションの中です。']],
1308
- ['section',
1309
- ['h2', 'また次のセクションです。'],
1310
- ['div.pgroup',
1311
- ['p', '入れ子になります。']]],
1312
- ['div.pgroup',
1313
- ['p', 'このように。']]]
1314
- )
1245
+ ['section',
1246
+ ['h1', 'タイトルです。'],
1247
+ ['div.pgroup',
1248
+ ['p', 'これは、セクションの中です。']],
1249
+ ['section',
1250
+ ['h2', 'また次のセクションです。'],
1251
+ ['div.pgroup',
1252
+ ['p', '入れ子になります。']]],
1253
+ ['div.pgroup',
1254
+ ['p', 'このように。']]]
1255
+ )
1315
1256
  end
1316
1257
  it 'should markdown style heading not interrupted by other explicit section' do
1317
1258
  text = "# タイトルです。\r\nこれは、セクションの中です。\n ## また次のセクションです。{\n 入れ子になります。\n# 中にもかけます。\nさらにネストされます。\n}\nこのように。"
@@ -1321,21 +1262,21 @@ EOF
1321
1262
  expect(body.element_children.size).to eq 1
1322
1263
  expect(body.element_children[0].selector_and_children)
1323
1264
  .to eq(
1324
- ['section',
1325
- ['h1', 'タイトルです。'],
1326
- ['div.pgroup',
1327
- ['p', 'これは、セクションの中です。']],
1328
- ['section',
1329
- ['h2', 'また次のセクションです。'],
1330
- ['div.pgroup',
1331
- ['p', '入れ子になります。']],
1332
- ['section',
1333
- ['h1', '中にもかけます。'],
1334
- ['div.pgroup',
1335
- ['p', 'さらにネストされます。']]]],
1336
- ['div.pgroup',
1337
- ['p', 'このように。']]]
1338
- )
1265
+ ['section',
1266
+ ['h1', 'タイトルです。'],
1267
+ ['div.pgroup',
1268
+ ['p', 'これは、セクションの中です。']],
1269
+ ['section',
1270
+ ['h2', 'また次のセクションです。'],
1271
+ ['div.pgroup',
1272
+ ['p', '入れ子になります。']],
1273
+ ['section',
1274
+ ['h1', '中にもかけます。'],
1275
+ ['div.pgroup',
1276
+ ['p', 'さらにネストされます。']]]],
1277
+ ['div.pgroup',
1278
+ ['p', 'このように。']]]
1279
+ )
1339
1280
  end
1340
1281
 
1341
1282
  it 'should markdown style explicit heading correctly nested' do
@@ -1346,17 +1287,17 @@ EOF
1346
1287
  expect(body.element_children.size).to eq 1
1347
1288
  expect(body.element_children[0].selector_and_children)
1348
1289
  .to eq(
1349
- ['section',
1350
- ['h1', 'head one'],
1351
- ['div.pgroup',
1352
- ['p', 'in the top level section.']],
1353
- ['section',
1354
- ['h2', 'second level section.'],
1355
- ['div.pgroup',
1356
- ['p', 'in the second level.']]],
1357
- ['div.pgroup',
1358
- ['p', 'top level again.']]]
1359
- )
1290
+ ['section',
1291
+ ['h1', 'head one'],
1292
+ ['div.pgroup',
1293
+ ['p', 'in the top level section.']],
1294
+ ['section',
1295
+ ['h2', 'second level section.'],
1296
+ ['div.pgroup',
1297
+ ['p', 'in the second level.']]],
1298
+ ['div.pgroup',
1299
+ ['p', 'top level again.']]]
1300
+ )
1360
1301
  end
1361
1302
 
1362
1303
  it 'should markdown style heading not interrupted by smaller section' do
@@ -1367,45 +1308,49 @@ EOF
1367
1308
  expect(body.element_children.size).to eq 2
1368
1309
  expect(body.element_children[0].selector_and_children)
1369
1310
  .to eq(
1370
- ['section',
1371
- ['h1', 'タイトルです。'],
1372
- ['div.pgroup',
1373
- ['p', 'これは、セクションの中です。']],
1374
- ['section',
1375
- ['h2', 'また次のセクションです。'],
1376
- ['div.pgroup',
1377
- ['p', '入れ子になります。']],
1378
- ['section',
1379
- ['h3', 'さらに中のセクション'],
1380
- ['div.pgroup',
1381
- ['p', 'さらに入れ子になっているはず。']]]]] )
1311
+ ['section',
1312
+ ['h1', 'タイトルです。'],
1313
+ ['div.pgroup',
1314
+ ['p', 'これは、セクションの中です。']],
1315
+ ['section',
1316
+ ['h2', 'また次のセクションです。'],
1317
+ ['div.pgroup',
1318
+ ['p', '入れ子になります。']],
1319
+ ['section',
1320
+ ['h3', 'さらに中のセクション'],
1321
+ ['div.pgroup',
1322
+ ['p', 'さらに入れ子になっているはず。']]]]]
1323
+ )
1382
1324
  expect(body.element_children[1].selector_and_children)
1383
1325
  .to eq(
1384
- ['section',
1385
- ['h1', 'ここで次のセクションです。'],
1386
- ['div.pgroup',
1387
- ['p', '脱出しているはずです。']]])
1388
-
1326
+ ['section',
1327
+ ['h1', 'ここで次のセクションです。'],
1328
+ ['div.pgroup',
1329
+ ['p', '脱出しているはずです。']]]
1330
+ )
1389
1331
  end
1390
1332
  end
1391
1333
  describe 'nonpaged mode' do
1392
1334
  it 'should create single html' do
1393
1335
  text = "some text\nnewpage:\nnext page"
1394
- noramark = NoraMark::Document.parse(text, lang: 'ja', title:'the document title')
1336
+ noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the document title')
1395
1337
  converted = noramark.render_parameter(nonpaged: true).html
1396
1338
  expect(converted.size).to eq 1
1397
1339
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
1398
1340
  expect(body.element_children[0].selector_and_children)
1399
1341
  .to eq(
1400
- ['div.pgroup',
1401
- ['p', 'some text']])
1342
+ ['div.pgroup',
1343
+ ['p', 'some text']]
1344
+ )
1402
1345
  expect(body.element_children[1].selector_and_children)
1403
1346
  .to eq(
1404
- ['hr.page-break'])
1347
+ ['hr.page-break']
1348
+ )
1405
1349
  expect(body.element_children[2].selector_and_children)
1406
1350
  .to eq(
1407
- ['div.pgroup',
1408
- ['p', 'next page']])
1351
+ ['div.pgroup',
1352
+ ['p', 'next page']]
1353
+ )
1409
1354
  end
1410
1355
  end
1411
1356
  describe 'create file' do
@@ -1419,18 +1364,17 @@ EOF
1419
1364
  end
1420
1365
  it 'should create named file' do
1421
1366
  text = "some text\nnewpage:\nnext page"
1422
- noramark = NoraMark::Document.parse(text, lang: 'ja', title:'the document title', document_name: 'nora-test-file', sequence_format: '%03d' )
1367
+ noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the document title', document_name: 'nora-test-file', sequence_format: '%03d')
1423
1368
  noramark.html.write_as_files(directory: @basedir)
1424
1369
  files = Dir.glob(File.join(@basedir, '*.xhtml')).map { |file| File.basename(file) }
1425
1370
  expect(files).to include 'nora-test-file_001.xhtml'
1426
1371
  expect(files).to include 'nora-test-file_002.xhtml'
1427
1372
  end
1428
-
1429
1373
  end
1430
1374
  describe 'parse and create manual' do
1431
1375
  before {
1432
1376
  @here = File.dirname(__FILE__)
1433
- @basedir = File.join(File.dirname(__FILE__), 'created_files')
1377
+ @basedir = File.join(File.dirname(__FILE__), 'created_files')
1434
1378
  @exampledir = File.join(@here, '..', 'example')
1435
1379
  }
1436
1380
  after { Dir.glob(File.join(@basedir, '*.xhtml')) { |file| File.delete file } }
@@ -1441,17 +1385,15 @@ EOF
1441
1385
  schema = File.join(@here, 'epub30-schemas/epub-xhtml-30.rnc')
1442
1386
  original_file = File.join(@exampledir, 'noramark-reference-ja_00001.xhtml')
1443
1387
  file_to_validate = File.join(@basedir, 'noramark-reference-ja_00001.xhtml')
1444
- File.open(original_file) do
1445
- |original|
1388
+ File.open(original_file) do |original|
1446
1389
  nokogiri_doc = Nokogiri::XML::Document.parse(original)
1447
1390
  set = nokogiri_doc.xpath('//xmlns:pre[@data-code-language]')
1448
1391
  set.remove_attr('data-code-language')
1449
- File.open(file_to_validate, 'w+') do
1450
- |to_validate|
1392
+ File.open(file_to_validate, 'w+') do |to_validate|
1451
1393
  to_validate << nokogiri_doc.to_s
1452
1394
  end
1453
1395
  end
1454
- @stdout = capture(:stdout) do
1396
+ @stdout = capture(:stdout) do
1455
1397
  puts %x(java -jar #{jar} -c #{schema} #{file_to_validate})
1456
1398
  end
1457
1399
  expect(@stdout.strip).to eq ""
@@ -1459,7 +1401,7 @@ EOF
1459
1401
  end
1460
1402
  describe 'table of contents' do
1461
1403
  before do
1462
- @basedir = File.join(File.dirname(__FILE__), 'created_files')
1404
+ @basedir = File.join(File.dirname(__FILE__), 'created_files')
1463
1405
  @text = <<EOF
1464
1406
  ---
1465
1407
  lang: ja
@@ -1492,27 +1434,25 @@ EOF
1492
1434
  toc = @noramark.html.toc
1493
1435
  expect(toc.size).to eq 3
1494
1436
  expect(toc[0])
1495
- .to eq({link: "nora-with-toc_00001.xhtml#heading_index_1", level: 1, text: "chapter 1"})
1437
+ .to eq({ link: "nora-with-toc_00001.xhtml#heading_index_1", level: 1, text: "chapter 1" })
1496
1438
  expect(toc[1])
1497
- .to eq({link: "nora-with-toc_00001.xhtml#heading_index_2", level: 2, text: "section 1-1"})
1439
+ .to eq({ link: "nora-with-toc_00001.xhtml#heading_index_2", level: 2, text: "section 1-1" })
1498
1440
  expect(toc[2])
1499
- .to eq({link: "nora-with-toc_00002.xhtml#heading_index_3", level: 6, text: "some column"})
1441
+ .to eq({ link: "nora-with-toc_00002.xhtml#heading_index_3", level: 6, text: "some column" })
1500
1442
  end
1501
1443
  it 'should generate and write tocs' do
1502
1444
  @noramark.html.write_toc_as_file(directory: @basedir)
1503
1445
  expect(File.exist?(File.join(@basedir, 'nora-with-toc.yaml')))
1504
- File.open(File.join(@basedir, 'nora-with-toc.yaml')) do
1505
- |file|
1446
+ File.open(File.join(@basedir, 'nora-with-toc.yaml')) do |file|
1506
1447
  toc = YAML.load(file.read)
1507
1448
  expect(toc[0])
1508
- .to eq({link: "nora-with-toc_00001.xhtml#heading_index_1", level: 1, text: "chapter 1"})
1449
+ .to eq({ link: "nora-with-toc_00001.xhtml#heading_index_1", level: 1, text: "chapter 1" })
1509
1450
  expect(toc[1])
1510
- .to eq({link: "nora-with-toc_00001.xhtml#heading_index_2", level: 2, text: "section 1-1"})
1451
+ .to eq({ link: "nora-with-toc_00001.xhtml#heading_index_2", level: 2, text: "section 1-1" })
1511
1452
  expect(toc[2])
1512
- .to eq({link: "nora-with-toc_00002.xhtml#heading_index_3", level: 6, text: "some column"})
1453
+ .to eq({ link: "nora-with-toc_00002.xhtml#heading_index_3", level: 6, text: "some column" })
1513
1454
  end
1514
1455
  end
1515
-
1516
1456
  end
1517
1457
  it 'should raise error' do
1518
1458
  text = "d {\n block is\nd {\n nested but\nd {\n not terminated }"
@@ -1527,9 +1467,9 @@ EOF
1527
1467
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
1528
1468
  expect(body.element_children[0].selector_and_children)
1529
1469
  .to eq(
1530
- ['p', 'this text includes ',
1531
- ["video[src='video.mp4'][poster='poster.jpg']", 'alternate message']]
1532
- )
1470
+ ['p', 'this text includes ',
1471
+ ["video[src='video.mp4'][poster='poster.jpg']", 'alternate message']]
1472
+ )
1533
1473
  end
1534
1474
  it 'should render video with autoplay and controls' do
1535
1475
  text = "this text includes [video(video.mp4, autoplay, controls)[poster: poster.jpg]]"
@@ -1538,9 +1478,9 @@ EOF
1538
1478
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
1539
1479
  expect(body.element_children[0].selector_and_children)
1540
1480
  .to eq(
1541
- ['p', 'this text includes ',
1542
- ["video[src='video.mp4'][poster='poster.jpg'][autoplay='autoplay'][controls='controls']", '']]
1543
- )
1481
+ ['p', 'this text includes ',
1482
+ ["video[src='video.mp4'][poster='poster.jpg'][autoplay='autoplay'][controls='controls']", '']]
1483
+ )
1544
1484
  end
1545
1485
  end
1546
1486
  describe 'audio' do
@@ -1551,9 +1491,9 @@ EOF
1551
1491
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
1552
1492
  expect(body.element_children[0].selector_and_children)
1553
1493
  .to eq(
1554
- ['p', 'this text includes ',
1555
- ["audio[src='audio.mp3'][volume='0.2']", 'alternate message']]
1556
- )
1494
+ ['p', 'this text includes ',
1495
+ ["audio[src='audio.mp3'][volume='0.2']", 'alternate message']]
1496
+ )
1557
1497
  end
1558
1498
  it 'should render audio with autoplay and controls' do
1559
1499
  text = "this text includes [audio(audio.mp3, autoplay, controls)]"
@@ -1562,9 +1502,9 @@ EOF
1562
1502
  body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
1563
1503
  expect(body.element_children[0].selector_and_children)
1564
1504
  .to eq(
1565
- ['p', 'this text includes ',
1566
- ["audio[src='audio.mp3'][autoplay='autoplay'][controls='controls']", '']]
1567
- )
1505
+ ['p', 'this text includes ',
1506
+ ["audio[src='audio.mp3'][autoplay='autoplay'][controls='controls']", '']]
1507
+ )
1568
1508
  end
1569
1509
  end
1570
1510
  describe 'Frontmatter MetaData' do
@@ -1576,7 +1516,7 @@ namespace: { epub: "http://www.idpf.org/2007/ops" }
1576
1516
  text
1577
1517
  EOF
1578
1518
  converted = NoraMark::Document.parse(text)
1579
- xhtml = Nokogiri::XML::Document.parse(converted.html[0])
1519
+ xhtml = Nokogiri::XML::Document.parse(converted.html[0])
1580
1520
  expect(xhtml.root.namespaces['xmlns:epub'])
1581
1521
  .to eq 'http://www.idpf.org/2007/ops'
1582
1522
  end
@@ -1597,4 +1537,3 @@ EOF
1597
1537
  end
1598
1538
  end
1599
1539
  end
1600
-