dtext_rb 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/ext/dtext/dtext.rl CHANGED
@@ -143,21 +143,11 @@ pixiv_id = 'pixiv #'i digit+ >mark_a1 %mark_a2;
143
143
  pixiv_paged_id = 'pixiv #'i digit+ >mark_a1 %mark_a2 '/p' digit+ >mark_b1 %mark_b2;
144
144
 
145
145
  ws = ' ' | '\t';
146
- header = 'h' [123456] >mark_a1 %mark_a2 '.' ws*;
147
- aliased_expand = '[expand=' (nonbracket+ >mark_a1 %mark_a2) ']';
146
+ header = 'h'i [123456] >mark_a1 %mark_a2 '.' ws*;
147
+ aliased_expand = '[expand='i (nonbracket+ >mark_a1 %mark_a2) ']';
148
148
 
149
149
  list_item = '*'+ >mark_a1 %mark_a2 ws+ nonnewline+ >mark_b1 %mark_b2;
150
150
 
151
- textile_link_desc := |*
152
- '":' (internal_url | url);
153
- *|;
154
-
155
- textile_link := |*
156
- '"';
157
-
158
- any;
159
- *|;
160
-
161
151
  inline := |*
162
152
  post_id => {
163
153
  append(sm, true, "<a href=\"/posts/");
@@ -409,12 +399,12 @@ inline := |*
409
399
  fnext list;
410
400
  };
411
401
 
412
- '[b]' => {
402
+ '[b]'i => {
413
403
  dstack_push(sm, &INLINE_B);
414
404
  append(sm, true, "<strong>");
415
405
  };
416
406
 
417
- '[/b]' => {
407
+ '[/b]'i => {
418
408
  if (dstack_check(sm, INLINE_B)) {
419
409
  dstack_pop(sm);
420
410
  append(sm, true, "</strong>");
@@ -423,12 +413,12 @@ inline := |*
423
413
  }
424
414
  };
425
415
 
426
- '[i]' => {
416
+ '[i]'i => {
427
417
  dstack_push(sm, &INLINE_I);
428
418
  append(sm, true, "<em>");
429
419
  };
430
420
 
431
- '[/i]' => {
421
+ '[/i]'i => {
432
422
  if (dstack_check(sm, INLINE_I)) {
433
423
  dstack_pop(sm);
434
424
  append(sm, true, "</em>");
@@ -437,12 +427,12 @@ inline := |*
437
427
  }
438
428
  };
439
429
 
440
- '[s]' => {
430
+ '[s]'i => {
441
431
  dstack_push(sm, &INLINE_S);
442
432
  append(sm, true, "<s>");
443
433
  };
444
434
 
445
- '[/s]' => {
435
+ '[/s]'i => {
446
436
  if (dstack_check(sm, INLINE_S)) {
447
437
  dstack_pop(sm);
448
438
  append(sm, true, "</s>");
@@ -451,12 +441,12 @@ inline := |*
451
441
  }
452
442
  };
453
443
 
454
- '[u]' => {
444
+ '[u]'i => {
455
445
  dstack_push(sm, &INLINE_U);
456
446
  append(sm, true, "<u>");
457
447
  };
458
448
 
459
- '[/u]' => {
449
+ '[/u]'i => {
460
450
  if (dstack_check(sm, INLINE_U)) {
461
451
  dstack_pop(sm);
462
452
  append(sm, true, "</u>");
@@ -465,12 +455,12 @@ inline := |*
465
455
  }
466
456
  };
467
457
 
468
- '[tn]' => {
458
+ '[tn]'i => {
469
459
  dstack_push(sm, &INLINE_TN);
470
460
  append(sm, true, "<span class=\"tn\">");
471
461
  };
472
462
 
473
- '[/tn]' => {
463
+ '[/tn]'i => {
474
464
  dstack_close_before_block(sm);
475
465
 
476
466
  if (dstack_check(sm, BLOCK_TN)) {
@@ -492,14 +482,14 @@ inline := |*
492
482
  fret;
493
483
  };
494
484
 
495
- '[quote]' => {
485
+ '[quote]'i => {
496
486
  g_debug("inline [quote]");
497
487
  dstack_close_before_block(sm);
498
488
  fexec sm->ts;
499
489
  fret;
500
490
  };
501
491
 
502
- '[/quote]' space* => {
492
+ '[/quote]'i space* => {
503
493
  g_debug("inline [/quote]");
504
494
  dstack_close_before_block(sm);
505
495
 
@@ -515,14 +505,14 @@ inline := |*
515
505
  }
516
506
  };
517
507
 
518
- '[spoiler]' => {
508
+ '[spoiler]'i => {
519
509
  g_debug("inline [spoiler]");
520
510
  g_debug(" push <span>");
521
511
  dstack_push(sm, &INLINE_SPOILER);
522
512
  append(sm, true, "<span class=\"spoiler\">");
523
513
  };
524
514
 
525
- '[/spoiler]' => {
515
+ '[/spoiler]'i => {
526
516
  g_debug("inline [/spoiler]");
527
517
  dstack_close_before_block(sm);
528
518
 
@@ -543,14 +533,14 @@ inline := |*
543
533
  }
544
534
  };
545
535
 
546
- '[expand]' => {
536
+ '[expand]'i => {
547
537
  g_debug("inline [expand]");
548
538
  dstack_rewind(sm);
549
539
  fexec(sm->p - 7);
550
540
  fret;
551
541
  };
552
542
 
553
- '[/expand]' => {
543
+ '[/expand]'i => {
554
544
  dstack_close_before_block(sm);
555
545
 
556
546
  if (dstack_check(sm, BLOCK_EXPAND)) {
@@ -562,12 +552,12 @@ inline := |*
562
552
  }
563
553
  };
564
554
 
565
- '[nodtext]' => {
555
+ '[nodtext]'i => {
566
556
  dstack_push(sm, &INLINE_NODTEXT);
567
557
  fcall nodtext;
568
558
  };
569
559
 
570
- '[/th]' => {
560
+ '[/th]'i => {
571
561
  if (dstack_check(sm, BLOCK_TH)) {
572
562
  dstack_pop(sm);
573
563
  append_block(sm, "</th>");
@@ -577,7 +567,7 @@ inline := |*
577
567
  }
578
568
  };
579
569
 
580
- '[/td]' => {
570
+ '[/td]'i => {
581
571
  if (dstack_check(sm, BLOCK_TD)) {
582
572
  dstack_pop(sm);
583
573
  append_block(sm, "</td>");
@@ -630,7 +620,7 @@ inline := |*
630
620
  *|;
631
621
 
632
622
  code := |*
633
- '[/code]' => {
623
+ '[/code]'i => {
634
624
  if (dstack_check(sm, BLOCK_CODE)) {
635
625
  dstack_rewind(sm);
636
626
  } else {
@@ -650,7 +640,7 @@ code := |*
650
640
  *|;
651
641
 
652
642
  nodtext := |*
653
- '[/nodtext]' => {
643
+ '[/nodtext]'i => {
654
644
  if (dstack_check(sm, BLOCK_NODTEXT)) {
655
645
  dstack_pop(sm);
656
646
  append_block(sm, "</p>");
@@ -674,12 +664,12 @@ nodtext := |*
674
664
  *|;
675
665
 
676
666
  table := |*
677
- '[thead]' => {
667
+ '[thead]'i => {
678
668
  dstack_push(sm, &BLOCK_THEAD);
679
669
  append_block(sm, "<thead>");
680
670
  };
681
671
 
682
- '[/thead]' => {
672
+ '[/thead]'i => {
683
673
  if (dstack_check(sm, BLOCK_THEAD)) {
684
674
  dstack_pop(sm);
685
675
  append_block(sm, "</thead>");
@@ -688,12 +678,12 @@ table := |*
688
678
  }
689
679
  };
690
680
 
691
- '[tbody]' => {
681
+ '[tbody]'i => {
692
682
  dstack_push(sm, &BLOCK_TBODY);
693
683
  append_block(sm, "<tbody>");
694
684
  };
695
685
 
696
- '[/tbody]' => {
686
+ '[/tbody]'i => {
697
687
  if (dstack_check(sm, BLOCK_TBODY)) {
698
688
  dstack_pop(sm);
699
689
  append_block(sm, "</tbody>");
@@ -702,18 +692,18 @@ table := |*
702
692
  }
703
693
  };
704
694
 
705
- '[th]' => {
695
+ '[th]'i => {
706
696
  dstack_push(sm, &BLOCK_TH);
707
697
  append_block(sm, "<th>");
708
698
  fcall inline;
709
699
  };
710
700
 
711
- '[tr]' => {
701
+ '[tr]'i => {
712
702
  dstack_push(sm, &BLOCK_TR);
713
703
  append_block(sm, "<tr>");
714
704
  };
715
705
 
716
- '[/tr]' => {
706
+ '[/tr]'i => {
717
707
  if (dstack_check(sm, BLOCK_TR)) {
718
708
  dstack_pop(sm);
719
709
  append_block(sm, "</tr>");
@@ -722,13 +712,13 @@ table := |*
722
712
  }
723
713
  };
724
714
 
725
- '[td]' => {
715
+ '[td]'i => {
726
716
  dstack_push(sm, &BLOCK_TD);
727
717
  append_block(sm, "<td>");
728
718
  fcall inline;
729
719
  };
730
720
 
731
- '[/table]' => {
721
+ '[/table]'i => {
732
722
  if (dstack_check(sm, BLOCK_TABLE)) {
733
723
  dstack_pop(sm);
734
724
  append_block(sm, "</table>");
@@ -847,7 +837,7 @@ main := |*
847
837
  fcall inline;
848
838
  };
849
839
 
850
- '[quote]' space* => {
840
+ '[quote]'i space* => {
851
841
  g_debug("block [quote]");
852
842
  g_debug(" push quote");
853
843
  g_debug(" print <blockquote>");
@@ -856,7 +846,7 @@ main := |*
856
846
  append_block(sm, "<blockquote>");
857
847
  };
858
848
 
859
- '[spoiler]' space* => {
849
+ '[spoiler]'i space* => {
860
850
  g_debug("block [spoiler]");
861
851
  g_debug(" push spoiler");
862
852
  g_debug(" print <div>");
@@ -865,7 +855,7 @@ main := |*
865
855
  append_block(sm, "<div class=\"spoiler\">");
866
856
  };
867
857
 
868
- '[/spoiler]' => {
858
+ '[/spoiler]'i => {
869
859
  g_debug("block [/spoiler]");
870
860
  dstack_close_before_block(sm);
871
861
  if (dstack_check(sm, BLOCK_SPOILER)) {
@@ -874,7 +864,7 @@ main := |*
874
864
  }
875
865
  };
876
866
 
877
- '[code]' space* => {
867
+ '[code]'i space* => {
878
868
  g_debug("block [code]");
879
869
  dstack_close_before_block(sm);
880
870
  dstack_push(sm, &BLOCK_CODE);
@@ -882,7 +872,7 @@ main := |*
882
872
  fcall code;
883
873
  };
884
874
 
885
- '[expand]' space* => {
875
+ '[expand]'i space* => {
886
876
  g_debug("block [expand]");
887
877
  dstack_close_before_block(sm);
888
878
  dstack_push(sm, &BLOCK_EXPAND);
@@ -903,7 +893,7 @@ main := |*
903
893
  append_block(sm, "<div class=\"expandable-content\">");
904
894
  };
905
895
 
906
- '[nodtext]' space* => {
896
+ '[nodtext]'i space* => {
907
897
  g_debug("block [nodtext]");
908
898
  dstack_close_before_block(sm);
909
899
  dstack_push(sm, &BLOCK_NODTEXT);
@@ -912,14 +902,14 @@ main := |*
912
902
  fcall nodtext;
913
903
  };
914
904
 
915
- '[table]' => {
905
+ '[table]'i => {
916
906
  dstack_close_before_block(sm);
917
907
  dstack_push(sm, &BLOCK_TABLE);
918
908
  append_block(sm, "<table class=\"striped\">");
919
909
  fcall table;
920
910
  };
921
911
 
922
- '[tn]' => {
912
+ '[tn]'i => {
923
913
  dstack_push(sm, &BLOCK_TN);
924
914
  append_block(sm, "<p class=\"tn\">");
925
915
  fcall inline;
@@ -1309,6 +1299,11 @@ static VALUE parse(int argc, VALUE * argv, VALUE self) {
1309
1299
  }
1310
1300
 
1311
1301
  input = argv[0];
1302
+
1303
+ if (NIL_P(input)) {
1304
+ return Qnil;
1305
+ }
1306
+
1312
1307
  input0 = rb_str_dup(input);
1313
1308
 
1314
1309
  sm = (StateMachine *)g_malloc0(sizeof(StateMachine));
data/test/dtext_test.rb CHANGED
@@ -37,6 +37,10 @@ class DTextTest < Minitest::Test
37
37
  assert_parse("<p>a <a href=\"/wiki_pages/show_or_new?title=spoiler\">spoiler</a> c</p>", "a [[spoiler]] c")
38
38
  end
39
39
 
40
+ def test_wiki_links_nested_b
41
+ assert_parse("<p><strong>[[</strong>tag<strong>]]</strong></p>", "[b][[[/b]tag[b]]][/b]")
42
+ end
43
+
40
44
  def test_spoilers_inline
41
45
  assert_parse("<p>this is <span class=\"spoiler\">an inline spoiler</span>.</p>", "this is [spoiler]an inline spoiler[/spoiler].")
42
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dtext_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - r888888888
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-12 00:00:00.000000000 Z
11
+ date: 2016-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest