pseudohikiparser 0.0.3 → 0.0.4.develop

Sign up to get free protection for your applications and to get access to all the features.
@@ -265,4 +265,89 @@ TEXT
265
265
  assert_equal(expected_text_in_verbose_mode, PlainTextFormat.format(tree, { :verbose_mode => true }).to_s)
266
266
  assert_equal(expected_text, PlainTextFormat.format(tree, { :verbose_mode => false }).to_s)
267
267
  end
268
+
269
+ def test_without_sectioning_node
270
+ text = <<TEXT
271
+ ! Main title
272
+
273
+ !! first title in header
274
+
275
+ paragraph
276
+
277
+ !! second title in header
278
+
279
+ paragraph2
280
+
281
+ !! first subtitle in main part
282
+
283
+ paragraph3
284
+
285
+ paragraph4
286
+
287
+ TEXT
288
+
289
+ expected_text = <<HTML
290
+ Main title
291
+ first title in header
292
+ paragraph
293
+
294
+ second title in header
295
+ paragraph2
296
+
297
+ first subtitle in main part
298
+ paragraph3
299
+
300
+ paragraph4
301
+
302
+ HTML
303
+
304
+ tree = BlockParser.parse(text.lines.to_a)
305
+ assert_equal(expected_text, PlainTextFormat.format(tree, { :verbose_mode => false }).to_s)
306
+ end
307
+
308
+ def test_sectioning_node
309
+ text = <<TEXT
310
+ ! Main title
311
+
312
+ //@begin[header]
313
+ !! first title in header
314
+
315
+ paragraph
316
+
317
+ !! second title in header
318
+
319
+ paragraph2
320
+
321
+ //@end[header]
322
+
323
+ !! first subtitle in main part
324
+
325
+ paragraph3
326
+
327
+ //@begin[#footer]
328
+
329
+ paragraph4
330
+
331
+ //@end[#footer]
332
+
333
+ TEXT
334
+
335
+ expected_text = <<HTML
336
+ Main title
337
+ first title in header
338
+ paragraph
339
+
340
+ second title in header
341
+ paragraph2
342
+
343
+ first subtitle in main part
344
+ paragraph3
345
+
346
+ paragraph4
347
+
348
+ HTML
349
+
350
+ tree = BlockParser.parse(text.lines.to_a)
351
+ assert_equal(expected_text, PlainTextFormat.format(tree, { :verbose_mode => false }).to_s)
352
+ end
268
353
  end
@@ -4,6 +4,7 @@ require 'stringio'
4
4
  require 'shellwords'
5
5
  require 'minitest/autorun'
6
6
  require 'pseudohiki/converter'
7
+ require 'pseudohiki/autolink'
7
8
 
8
9
  def set_argv(command_line_str)
9
10
  ARGV.replace Shellwords.split(command_line_str)
@@ -378,4 +379,85 @@ GFM
378
379
 
379
380
  assert_equal(output, html)
380
381
  end
382
+
383
+ def test_with_wikiname
384
+ current_auto_linker = BlockParser.auto_linker
385
+ set_argv("--with-wikiname wikipage.txt")
386
+ options = OptionManager.new
387
+ options.set_options_from_command_line
388
+
389
+ assert_equal(AutoLink::WikiName, BlockParser.auto_linker.class)
390
+
391
+ BlockParser.auto_linker = current_auto_linker
392
+ end
393
+
394
+ def test_no_automatical_link_in_verbatim
395
+ verbatim_block_text = <<TEXT.each_line.to_a
396
+
397
+ a link in a paragraph http://www.example.org/
398
+
399
+ <<<
400
+ http://www.example.org/
401
+ >>>
402
+ TEXT
403
+
404
+ expected_html = <<HTML
405
+ <?xml version="1.0" encoding="UTF-8"?>
406
+ <!DOCTYPE html>
407
+ <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
408
+ <head>
409
+ <meta charset="UTF-8" />
410
+ <title>wikipage</title>
411
+ <link href="css/with_toc.css" rel="stylesheet" type="text/css" />
412
+ </head>
413
+ <body>
414
+ <p>
415
+ a link in a paragraph <a href="http://www.example.org/">http://www.example.org/</a>
416
+ </p>
417
+ <pre>
418
+ <a href="http://www.example.org/">http://www.example.org/</a>
419
+ </pre>
420
+ </body>
421
+ </html>
422
+ HTML
423
+
424
+ expected_html_without_auto_link = <<HTML
425
+ <?xml version="1.0" encoding="UTF-8"?>
426
+ <!DOCTYPE html>
427
+ <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
428
+ <head>
429
+ <meta charset="UTF-8" />
430
+ <title>wikipage</title>
431
+ <link href="css/with_toc.css" rel="stylesheet" type="text/css" />
432
+ </head>
433
+ <body>
434
+ <p>
435
+ a link in a paragraph http://www.example.org/
436
+ </p>
437
+ <pre>
438
+ http://www.example.org/
439
+ </pre>
440
+ </body>
441
+ </html>
442
+ HTML
443
+
444
+ set_argv("-fh5 -c css/with_toc.css wikipage.txt")
445
+ options = OptionManager.new
446
+ options.set_options_from_command_line
447
+
448
+ composed_html = PageComposer.new(options).compose_html(verbatim_block_text).to_s
449
+ assert_equal(expected_html, composed_html)
450
+
451
+ set_argv("-fh5 -c css/with_toc.css wikipage.txt")
452
+ options = OptionManager.new
453
+ options.set_options_from_command_line
454
+
455
+ current_auto_linker = BlockParser.auto_linker
456
+ BlockParser.auto_linker = AutoLink::Off
457
+ Xhtml5Format.auto_link_in_verbatim = false
458
+ composed_html_without_auto_link = PageComposer.new(options).compose_html(verbatim_block_text).to_s
459
+ assert_equal(expected_html_without_auto_link, composed_html_without_auto_link)
460
+ BlockParser.auto_linker = current_auto_linker
461
+ Xhtml5Format.auto_link_in_verbatim = true
462
+ end
381
463
  end
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'minitest/autorun'
3
3
  require 'pseudohikiparser'
4
+ require 'pseudohiki/autolink'
4
5
 
5
6
  class TC_MarkDownFormat < MiniTest::Unit::TestCase
6
7
  include PseudoHiki
@@ -16,6 +17,8 @@ the first paragraph with ''inline'' ``tags``
16
17
 
17
18
  the second paragraph with ==block== [[inline|#id]] tags
18
19
  TEXT
20
+
21
+ @text_with_wikiname = 'a line with WikiName and a [[normal link|http://www.example.org/]]'
19
22
  end
20
23
 
21
24
  def test_to_html
@@ -139,4 +142,287 @@ HTML
139
142
 
140
143
  assert_equal(expected_html_table, table_with_id)
141
144
  end
145
+
146
+ def test_format_with_wikiname
147
+ expected_html_with_wikiname = <<HTML
148
+ <p>
149
+ a line with <a href="WikiName">WikiName</a> and a <a href="http://www.example.org/">normal link</a></p>
150
+ HTML
151
+
152
+ expected_html_without_wikiname = <<HTML
153
+ <p>
154
+ a line with WikiName and a <a href="http://www.example.org/">normal link</a></p>
155
+ HTML
156
+
157
+ assert_equal(expected_html_with_wikiname,
158
+ Format.format(@text_with_wikiname, :html, nil, AutoLink::WikiName.new))
159
+ assert_equal(expected_html_without_wikiname,
160
+ Format.format(@text_with_wikiname, :html))
161
+
162
+ BlockParser.auto_linker = AutoLink::WikiName.new
163
+
164
+ assert_equal(expected_html_with_wikiname,
165
+ Format.format(@text_with_wikiname, :html))
166
+
167
+ BlockParser.auto_linker = nil
168
+
169
+ assert_equal(expected_html_without_wikiname,
170
+ Format.format(@text_with_wikiname, :html))
171
+ end
172
+
173
+ def test_format_without_auto_link_in_verbatim
174
+ verbatim_text_with_url = <<TEXT
175
+ a verbatim line with http://www.example.org/ and WikiName
176
+ TEXT
177
+
178
+ expected_html_without_auto_link_in_verbatim = <<HTML
179
+ <pre>
180
+ a verbatim line with http://www.example.org/ and WikiName
181
+ </pre>
182
+ HTML
183
+
184
+ assert_equal(expected_html_without_auto_link_in_verbatim,
185
+ Format.format(verbatim_text_with_url, :html, nil, AutoLink::Off))
186
+ end
187
+
188
+ def test_format_with_auto_link_in_verbatim
189
+ verbatim_text_with_url = <<TEXT
190
+ a verbatim line with http://www.example.org/ and WikiName
191
+ TEXT
192
+
193
+ expected_html_with_auto_link_in_verbatim = <<HTML
194
+ <pre>
195
+ a verbatim line with <a href="http://www.example.org/">http://www.example.org/</a> and WikiName
196
+ </pre>
197
+ HTML
198
+
199
+ assert_equal(expected_html_with_auto_link_in_verbatim,
200
+ Format.format(verbatim_text_with_url, :html, nil, AutoLink::URL))
201
+ assert_equal(expected_html_with_auto_link_in_verbatim,
202
+ Format.format(verbatim_text_with_url, :html, nil, nil))
203
+ end
204
+
205
+ def test_to_html_with_wikiname
206
+ wikiname_linker = AutoLink::WikiName.new
207
+
208
+ expected_html_with_wikiname = <<HTML
209
+ <p>
210
+ a line with <a href="WikiName">WikiName</a> and a <a href="http://www.example.org/">normal link</a></p>
211
+ HTML
212
+
213
+ expected_html_without_wikiname = <<HTML
214
+ <p>
215
+ a line with WikiName and a <a href="http://www.example.org/">normal link</a></p>
216
+ HTML
217
+
218
+ assert_equal(expected_html_with_wikiname,
219
+ Format.to_html(@text_with_wikiname, wikiname_linker))
220
+
221
+ assert_equal(expected_html_without_wikiname,
222
+ Format.to_html(@text_with_wikiname))
223
+
224
+ BlockParser.auto_linker = wikiname_linker
225
+
226
+ assert_equal(expected_html_with_wikiname,
227
+ Format.to_html(@text_with_wikiname))
228
+
229
+ BlockParser.auto_linker = nil
230
+
231
+ assert_equal(expected_html_without_wikiname,
232
+ Format.to_html(@text_with_wikiname))
233
+ end
234
+
235
+ def test_to_xhtml_with_wikiname
236
+ wikiname_linker = AutoLink::WikiName.new
237
+
238
+ expected_html_with_wikiname = <<HTML
239
+ <p>
240
+ a line with <a href="WikiName">WikiName</a> and a <a href="http://www.example.org/">normal link</a></p>
241
+ HTML
242
+
243
+ expected_html_without_wikiname = <<HTML
244
+ <p>
245
+ a line with WikiName and a <a href="http://www.example.org/">normal link</a></p>
246
+ HTML
247
+
248
+ assert_equal(expected_html_with_wikiname,
249
+ Format.to_xhtml(@text_with_wikiname, wikiname_linker))
250
+
251
+ assert_equal(expected_html_without_wikiname,
252
+ Format.to_xhtml(@text_with_wikiname))
253
+
254
+ BlockParser.auto_linker = wikiname_linker
255
+
256
+ assert_equal(expected_html_with_wikiname,
257
+ Format.to_xhtml(@text_with_wikiname))
258
+
259
+ BlockParser.auto_linker = nil
260
+
261
+ assert_equal(expected_html_without_wikiname,
262
+ Format.to_xhtml(@text_with_wikiname))
263
+ end
264
+
265
+ def test_to_html5_with_wikiname
266
+ wikiname_linker = AutoLink::WikiName.new
267
+
268
+ expected_html_with_wikiname = <<HTML
269
+ <p>
270
+ a line with <a href="WikiName">WikiName</a> and a <a href="http://www.example.org/">normal link</a></p>
271
+ HTML
272
+
273
+ expected_html_without_wikiname = <<HTML
274
+ <p>
275
+ a line with WikiName and a <a href="http://www.example.org/">normal link</a></p>
276
+ HTML
277
+
278
+ assert_equal(expected_html_with_wikiname,
279
+ Format.to_html5(@text_with_wikiname, wikiname_linker))
280
+
281
+ assert_equal(expected_html_without_wikiname,
282
+ Format.to_html5(@text_with_wikiname))
283
+
284
+ BlockParser.auto_linker = wikiname_linker
285
+
286
+ assert_equal(expected_html_with_wikiname,
287
+ Format.to_html5(@text_with_wikiname))
288
+
289
+ BlockParser.auto_linker = nil
290
+
291
+ assert_equal(expected_html_without_wikiname,
292
+ Format.to_html5(@text_with_wikiname))
293
+ end
294
+
295
+ def test_to_plain_with_wikiname
296
+ wikiname_linker = AutoLink::WikiName.new
297
+
298
+ expected_html_with_wikiname = <<HTML
299
+ a line with WikiName and a normal link
300
+ HTML
301
+
302
+ expected_html_without_wikiname = <<HTML
303
+ a line with WikiName and a normal link
304
+ HTML
305
+
306
+ assert_equal(expected_html_with_wikiname,
307
+ Format.to_plain(@text_with_wikiname, wikiname_linker))
308
+
309
+ assert_equal(expected_html_without_wikiname,
310
+ Format.to_plain(@text_with_wikiname))
311
+
312
+ BlockParser.auto_linker = wikiname_linker
313
+
314
+ assert_equal(expected_html_with_wikiname,
315
+ Format.to_plain(@text_with_wikiname))
316
+
317
+ BlockParser.auto_linker = nil
318
+
319
+ assert_equal(expected_html_without_wikiname,
320
+ Format.to_plain(@text_with_wikiname))
321
+ end
322
+
323
+ def test_to_markdown_with_wikiname
324
+ wikiname_linker = AutoLink::WikiName.new
325
+
326
+ expected_html_with_wikiname = <<HTML
327
+ a line with [WikiName](WikiName) and a [normal link](http://www.example.org/)
328
+ HTML
329
+
330
+ expected_html_without_wikiname = <<HTML
331
+ a line with WikiName and a [normal link](http://www.example.org/)
332
+ HTML
333
+
334
+ assert_equal(expected_html_with_wikiname,
335
+ Format.to_markdown(@text_with_wikiname, wikiname_linker))
336
+
337
+ assert_equal(expected_html_without_wikiname,
338
+ Format.to_markdown(@text_with_wikiname))
339
+
340
+ BlockParser.auto_linker = wikiname_linker
341
+
342
+ assert_equal(expected_html_with_wikiname,
343
+ Format.to_markdown(@text_with_wikiname))
344
+
345
+ BlockParser.auto_linker = nil
346
+
347
+ assert_equal(expected_html_without_wikiname,
348
+ Format.to_markdown(@text_with_wikiname))
349
+ end
350
+
351
+ def test_to_gfm_with_wikiname
352
+ wikiname_linker = AutoLink::WikiName.new
353
+
354
+ expected_html_with_wikiname = <<HTML
355
+ a line with [WikiName](WikiName) and a [normal link](http://www.example.org/)
356
+ HTML
357
+
358
+ expected_html_without_wikiname = <<HTML
359
+ a line with WikiName and a [normal link](http://www.example.org/)
360
+ HTML
361
+
362
+ assert_equal(expected_html_with_wikiname,
363
+ Format.to_gfm(@text_with_wikiname, wikiname_linker))
364
+
365
+ assert_equal(expected_html_without_wikiname,
366
+ Format.to_gfm(@text_with_wikiname))
367
+
368
+ BlockParser.auto_linker = wikiname_linker
369
+
370
+ assert_equal(expected_html_with_wikiname,
371
+ Format.to_gfm(@text_with_wikiname))
372
+
373
+ BlockParser.auto_linker = nil
374
+
375
+ assert_equal(expected_html_without_wikiname,
376
+ Format.to_gfm(@text_with_wikiname))
377
+ end
378
+
379
+ def test_to_html5_without_auto_link
380
+ current_linker = BlockParser.auto_linker
381
+
382
+ link_off_linker = AutoLink::Off
383
+
384
+ text_with_urls = <<TEXT
385
+ a link in a paragraph http://www.example.org/
386
+
387
+ <<<
388
+ http://www.example.org/
389
+ >>>
390
+ TEXT
391
+
392
+ expected_html_with_links = <<HTML
393
+ <p>
394
+ a link in a paragraph <a href="http://www.example.org/">http://www.example.org/</a>
395
+ </p>
396
+ <pre>
397
+ <a href="http://www.example.org/">http://www.example.org/</a>
398
+ </pre>
399
+ HTML
400
+
401
+ expected_html_without_links = <<HTML
402
+ <p>
403
+ a link in a paragraph http://www.example.org/
404
+ </p>
405
+ <pre>
406
+ http://www.example.org/
407
+ </pre>
408
+ HTML
409
+
410
+ assert_equal(expected_html_without_links,
411
+ Format.to_html5(text_with_urls, link_off_linker))
412
+
413
+ assert_equal(expected_html_with_links,
414
+ Format.to_html5(text_with_urls))
415
+
416
+ BlockParser.auto_linker = link_off_linker
417
+
418
+ assert_equal(expected_html_without_links,
419
+ Format.to_html5(text_with_urls))
420
+
421
+ BlockParser.auto_linker = nil
422
+
423
+ assert_equal(expected_html_with_links,
424
+ Format.to_html5(text_with_urls))
425
+
426
+ BlockParser.auto_linker = current_linker
427
+ end
142
428
  end
data/test/test_utils.rb CHANGED
@@ -28,7 +28,7 @@ TEXT
28
28
  tree = PseudoHiki::BlockParser.parse(@input_text)
29
29
  nodes = PseudoHiki::Utils::NodeCollector.select(tree) do |node|
30
30
  node.kind_of?(PseudoHiki::BlockParser::HeadingLeaf) and
31
- node.nominal_level == 2 and
31
+ node.level == 2 and
32
32
  node.node_id
33
33
  end
34
34
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pseudohikiparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4.develop
5
5
  platform: ruby
6
6
  authors:
7
7
  - HASHIMOTO, Naoki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-10 00:00:00.000000000 Z
11
+ date: 2015-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.3.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.31'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.31'
55
69
  description: PseudoHikiParser is a parser of texts written in a Hiki like notation,
56
70
  and coverts them into HTML or other formats.
57
71
  email:
@@ -67,6 +81,7 @@ files:
67
81
  - bin/pseudohiki2html.rb
68
82
  - lib/htmlelement.rb
69
83
  - lib/htmlelement/htmltemplate.rb
84
+ - lib/pseudohiki/autolink.rb
70
85
  - lib/pseudohiki/blockparser.rb
71
86
  - lib/pseudohiki/converter.rb
72
87
  - lib/pseudohiki/htmlformat.rb
@@ -74,10 +89,12 @@ files:
74
89
  - lib/pseudohiki/inlineparser.rb
75
90
  - lib/pseudohiki/markdownformat.rb
76
91
  - lib/pseudohiki/plaintextformat.rb
92
+ - lib/pseudohiki/sinatra_helpers.rb
77
93
  - lib/pseudohiki/treestack.rb
78
94
  - lib/pseudohiki/utils.rb
79
95
  - lib/pseudohiki/version.rb
80
96
  - lib/pseudohikiparser.rb
97
+ - test/test_autolink.rb
81
98
  - test/test_blockparser.rb
82
99
  - test/test_htmlelement.rb
83
100
  - test/test_htmlformat.rb
@@ -106,9 +123,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
123
  version: 1.8.7
107
124
  required_rubygems_version: !ruby/object:Gem::Requirement
108
125
  requirements:
109
- - - ">="
126
+ - - ">"
110
127
  - !ruby/object:Gem::Version
111
- version: '0'
128
+ version: 1.3.1
112
129
  requirements: []
113
130
  rubyforge_project:
114
131
  rubygems_version: 2.2.3
@@ -127,5 +144,6 @@ test_files:
127
144
  - test/test_markdownformat.rb
128
145
  - test/test_htmlformat.rb
129
146
  - test/test_htmlplugin.rb
147
+ - test/test_autolink.rb
130
148
  - test/test_utils.rb
131
149
  - test/test_latexformat.rb