dtext_rb 1.0.11 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c0394fa7735d77983bdabe2a211b5c9310dd2a0
4
- data.tar.gz: f6ed16c0f2557c1434ef3d26c5f14bfe4e9322db
3
+ metadata.gz: c6dc8726968b6ed437ba690472b77761d8d9d1e3
4
+ data.tar.gz: e0ef0b7f8183e18ca1406f116796a5e59c35ac64
5
5
  SHA512:
6
- metadata.gz: b2e3723b0b424a589cddcb85088eda4e81fef22ce23929fb5c0d00129234dd78907bcaff10474e6a3133982027144fbd970736d4894a9fe191ef3a6e8c171776
7
- data.tar.gz: d396322de8b644d1865713726a0bb77fd9fb1f6582b56442e7dddc0225f4681bfd5e856315a591c933e41701fedbc85b8c42991e8941ecfa0b67131cdcb734e4
6
+ metadata.gz: 2b4b8c8f1cbf0819209b63e338425d0fea927ead929396536f9f44b15ed90eecae9182eab32bef172dcb5fb2b0d7342cda7b66b598fe781f89a9340b415df18e
7
+ data.tar.gz: 57807906d40b4f86ea8c57ea9fa61d039a45b6659e97ca69a7bc58314daa5a0cd2f552319fe49e6bb62c95c61396e8e93da54cc42d344cd9151d2975790404de
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.11
1
+ 1.0.12
data/dtext_rb.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: dtext_rb 1.0.11 ruby lib
5
+ # stub: dtext_rb 1.0.12 ruby lib
6
6
  # stub: ext/dtext/extconf.rb
7
7
 
8
8
  Gem::Specification.new do |s|
9
9
  s.name = "dtext_rb"
10
- s.version = "1.0.11"
10
+ s.version = "1.0.12"
11
11
 
12
12
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
13
13
  s.require_paths = ["lib"]
14
14
  s.authors = ["r888888888"]
15
- s.date = "2016-09-02"
15
+ s.date = "2016-09-08"
16
16
  s.description = "Compield DText parser"
17
17
  s.email = "r888888888@gmail.com"
18
18
  s.extensions = ["ext/dtext/extconf.rb"]
data/ext/dtext/dtext.c CHANGED
@@ -28,6 +28,7 @@ typedef struct StateMachine {
28
28
  const char * b2;
29
29
  bool f_inline;
30
30
  bool f_strip;
31
+ bool f_mentions;
31
32
  bool list_mode;
32
33
  bool header_mode;
33
34
  GString * output;
@@ -71,11 +72,11 @@ static const int BLOCK_H5 = 27;
71
72
  static const int BLOCK_H6 = 28;
72
73
 
73
74
 
74
- #line 1038 "ext/dtext/dtext.rl"
75
+ #line 1047 "ext/dtext/dtext.rl"
75
76
 
76
77
 
77
78
 
78
- #line 79 "ext/dtext/dtext.c"
79
+ #line 80 "ext/dtext/dtext.c"
79
80
  static const unsigned char _dtext_to_state_actions[] = {
80
81
  0, 0, 0, 0, 0, 0, 0, 0,
81
82
  0, 0, 0, 0, 0, 0, 0, 0,
@@ -174,7 +175,7 @@ static const int dtext_en_list = 308;
174
175
  static const int dtext_en_main = 249;
175
176
 
176
177
 
177
- #line 1041 "ext/dtext/dtext.rl"
178
+ #line 1050 "ext/dtext/dtext.rl"
178
179
 
179
180
  static inline void underscore_string(char * str, size_t len) {
180
181
  for (size_t i=0; i<len; ++i) {
@@ -475,6 +476,7 @@ static void init_machine(StateMachine * sm, const char * src, size_t len) {
475
476
  sm->b2 = NULL;
476
477
  sm->f_inline = false;
477
478
  sm->f_strip = false;
479
+ sm->f_mentions = true;
478
480
  sm->stack = g_array_sized_new(FALSE, TRUE, sizeof(int), 16);
479
481
  sm->dstack = g_queue_new();
480
482
  sm->list_nest = 0;
@@ -492,7 +494,7 @@ static void free_machine(StateMachine * sm) {
492
494
  g_free(sm);
493
495
  }
494
496
 
495
- static StateMachine * parse_helper(const char * src, size_t len, bool f_strip, bool f_inline) {
497
+ static StateMachine * parse_helper(const char * src, size_t len, bool f_strip, bool f_inline, bool f_mentions) {
496
498
  StateMachine * sm = NULL;
497
499
  StateMachine * link_content_sm = NULL;
498
500
 
@@ -500,9 +502,10 @@ static StateMachine * parse_helper(const char * src, size_t len, bool f_strip, b
500
502
  init_machine(sm, src, len);
501
503
  sm->f_strip = f_strip;
502
504
  sm->f_inline = f_inline;
505
+ sm->f_mentions = f_mentions;
503
506
 
504
507
 
505
- #line 506 "ext/dtext/dtext.c"
508
+ #line 509 "ext/dtext/dtext.c"
506
509
  {
507
510
  sm->cs = dtext_start;
508
511
  ( sm->top) = 0;
@@ -511,9 +514,9 @@ static StateMachine * parse_helper(const char * src, size_t len, bool f_strip, b
511
514
  ( sm->act) = 0;
512
515
  }
513
516
 
514
- #line 1368 "ext/dtext/dtext.rl"
517
+ #line 1379 "ext/dtext/dtext.rl"
515
518
 
516
- #line 517 "ext/dtext/dtext.c"
519
+ #line 520 "ext/dtext/dtext.c"
517
520
  {
518
521
  if ( ( sm->p) == ( sm->pe) )
519
522
  goto _test_eof;
@@ -523,7 +526,7 @@ _resume:
523
526
  #line 1 "NONE"
524
527
  {( sm->ts) = ( sm->p);}
525
528
  break;
526
- #line 527 "ext/dtext/dtext.c"
529
+ #line 530 "ext/dtext/dtext.c"
527
530
  }
528
531
 
529
532
  switch ( sm->cs ) {
@@ -2742,25 +2745,25 @@ case 248:
2742
2745
  tr297: sm->cs = 313; goto f3;
2743
2746
 
2744
2747
  f7:
2745
- #line 97 "ext/dtext/dtext.rl"
2748
+ #line 98 "ext/dtext/dtext.rl"
2746
2749
  {
2747
2750
  sm->a1 = sm->p;
2748
2751
  }
2749
2752
  goto _again;
2750
2753
  f4:
2751
- #line 101 "ext/dtext/dtext.rl"
2754
+ #line 102 "ext/dtext/dtext.rl"
2752
2755
  {
2753
2756
  sm->a2 = sm->p;
2754
2757
  }
2755
2758
  goto _again;
2756
2759
  f3:
2757
- #line 105 "ext/dtext/dtext.rl"
2760
+ #line 106 "ext/dtext/dtext.rl"
2758
2761
  {
2759
2762
  sm->b1 = sm->p;
2760
2763
  }
2761
2764
  goto _again;
2762
2765
  f5:
2763
- #line 109 "ext/dtext/dtext.rl"
2766
+ #line 110 "ext/dtext/dtext.rl"
2764
2767
  {
2765
2768
  sm->b2 = sm->p;
2766
2769
  }
@@ -2770,7 +2773,7 @@ f61:
2770
2773
  {( sm->te) = ( sm->p)+1;}
2771
2774
  goto _again;
2772
2775
  f38:
2773
- #line 262 "ext/dtext/dtext.rl"
2776
+ #line 263 "ext/dtext/dtext.rl"
2774
2777
  {( sm->te) = ( sm->p)+1;{
2775
2778
  append(sm, true, "<a rel=\"nofollow\" href=\"/posts?tags=");
2776
2779
  append_segment_uri_escaped(sm, sm->a1, sm->a2 - 1);
@@ -2780,7 +2783,7 @@ f38:
2780
2783
  }}
2781
2784
  goto _again;
2782
2785
  f36:
2783
- #line 270 "ext/dtext/dtext.rl"
2786
+ #line 271 "ext/dtext/dtext.rl"
2784
2787
  {( sm->te) = ( sm->p)+1;{
2785
2788
  GString * segment = g_string_new_len(sm->a1, sm->a2 - sm->a1);
2786
2789
  GString * lowercase_segment = NULL;
@@ -2803,7 +2806,7 @@ f36:
2803
2806
  }}
2804
2807
  goto _again;
2805
2808
  f37:
2806
- #line 291 "ext/dtext/dtext.rl"
2809
+ #line 292 "ext/dtext/dtext.rl"
2807
2810
  {( sm->te) = ( sm->p)+1;{
2808
2811
  GString * segment = g_string_new_len(sm->a1, sm->a2 - sm->a1);
2809
2812
  GString * lowercase_segment = NULL;
@@ -2826,14 +2829,14 @@ f37:
2826
2829
  }}
2827
2830
  goto _again;
2828
2831
  f27:
2829
- #line 408 "ext/dtext/dtext.rl"
2832
+ #line 416 "ext/dtext/dtext.rl"
2830
2833
  {( sm->te) = ( sm->p)+1;{
2831
2834
  dstack_push(sm, &INLINE_B);
2832
2835
  append(sm, true, "<strong>");
2833
2836
  }}
2834
2837
  goto _again;
2835
2838
  f18:
2836
- #line 413 "ext/dtext/dtext.rl"
2839
+ #line 421 "ext/dtext/dtext.rl"
2837
2840
  {( sm->te) = ( sm->p)+1;{
2838
2841
  if (dstack_check(sm, INLINE_B)) {
2839
2842
  dstack_pop(sm);
@@ -2844,14 +2847,14 @@ f18:
2844
2847
  }}
2845
2848
  goto _again;
2846
2849
  f29:
2847
- #line 422 "ext/dtext/dtext.rl"
2850
+ #line 430 "ext/dtext/dtext.rl"
2848
2851
  {( sm->te) = ( sm->p)+1;{
2849
2852
  dstack_push(sm, &INLINE_I);
2850
2853
  append(sm, true, "<em>");
2851
2854
  }}
2852
2855
  goto _again;
2853
2856
  f20:
2854
- #line 427 "ext/dtext/dtext.rl"
2857
+ #line 435 "ext/dtext/dtext.rl"
2855
2858
  {( sm->te) = ( sm->p)+1;{
2856
2859
  if (dstack_check(sm, INLINE_I)) {
2857
2860
  dstack_pop(sm);
@@ -2862,14 +2865,14 @@ f20:
2862
2865
  }}
2863
2866
  goto _again;
2864
2867
  f32:
2865
- #line 436 "ext/dtext/dtext.rl"
2868
+ #line 444 "ext/dtext/dtext.rl"
2866
2869
  {( sm->te) = ( sm->p)+1;{
2867
2870
  dstack_push(sm, &INLINE_S);
2868
2871
  append(sm, true, "<s>");
2869
2872
  }}
2870
2873
  goto _again;
2871
2874
  f21:
2872
- #line 441 "ext/dtext/dtext.rl"
2875
+ #line 449 "ext/dtext/dtext.rl"
2873
2876
  {( sm->te) = ( sm->p)+1;{
2874
2877
  if (dstack_check(sm, INLINE_S)) {
2875
2878
  dstack_pop(sm);
@@ -2880,14 +2883,14 @@ f21:
2880
2883
  }}
2881
2884
  goto _again;
2882
2885
  f35:
2883
- #line 450 "ext/dtext/dtext.rl"
2886
+ #line 458 "ext/dtext/dtext.rl"
2884
2887
  {( sm->te) = ( sm->p)+1;{
2885
2888
  dstack_push(sm, &INLINE_U);
2886
2889
  append(sm, true, "<u>");
2887
2890
  }}
2888
2891
  goto _again;
2889
2892
  f26:
2890
- #line 455 "ext/dtext/dtext.rl"
2893
+ #line 463 "ext/dtext/dtext.rl"
2891
2894
  {( sm->te) = ( sm->p)+1;{
2892
2895
  if (dstack_check(sm, INLINE_U)) {
2893
2896
  dstack_pop(sm);
@@ -2898,14 +2901,14 @@ f26:
2898
2901
  }}
2899
2902
  goto _again;
2900
2903
  f34:
2901
- #line 464 "ext/dtext/dtext.rl"
2904
+ #line 472 "ext/dtext/dtext.rl"
2902
2905
  {( sm->te) = ( sm->p)+1;{
2903
2906
  dstack_push(sm, &INLINE_TN);
2904
2907
  append(sm, true, "<span class=\"tn\">");
2905
2908
  }}
2906
2909
  goto _again;
2907
2910
  f25:
2908
- #line 469 "ext/dtext/dtext.rl"
2911
+ #line 477 "ext/dtext/dtext.rl"
2909
2912
  {( sm->te) = ( sm->p)+1;{
2910
2913
  dstack_close_before_block(sm);
2911
2914
 
@@ -2921,7 +2924,7 @@ f25:
2921
2924
  }}
2922
2925
  goto _again;
2923
2926
  f31:
2924
- #line 497 "ext/dtext/dtext.rl"
2927
+ #line 505 "ext/dtext/dtext.rl"
2925
2928
  {( sm->te) = ( sm->p)+1;{
2926
2929
  g_debug("inline [quote]");
2927
2930
  dstack_close_before_block(sm);
@@ -2930,7 +2933,7 @@ f31:
2930
2933
  }}
2931
2934
  goto _again;
2932
2935
  f33:
2933
- #line 520 "ext/dtext/dtext.rl"
2936
+ #line 528 "ext/dtext/dtext.rl"
2934
2937
  {( sm->te) = ( sm->p)+1;{
2935
2938
  g_debug("inline [spoiler]");
2936
2939
  g_debug(" push <span>");
@@ -2939,7 +2942,7 @@ f33:
2939
2942
  }}
2940
2943
  goto _again;
2941
2944
  f22:
2942
- #line 527 "ext/dtext/dtext.rl"
2945
+ #line 535 "ext/dtext/dtext.rl"
2943
2946
  {( sm->te) = ( sm->p)+1;{
2944
2947
  g_debug("inline [/spoiler]");
2945
2948
  dstack_close_before_block(sm);
@@ -2962,7 +2965,7 @@ f22:
2962
2965
  }}
2963
2966
  goto _again;
2964
2967
  f28:
2965
- #line 548 "ext/dtext/dtext.rl"
2968
+ #line 556 "ext/dtext/dtext.rl"
2966
2969
  {( sm->te) = ( sm->p)+1;{
2967
2970
  g_debug("inline [expand]");
2968
2971
  dstack_rewind(sm);
@@ -2971,7 +2974,7 @@ f28:
2971
2974
  }}
2972
2975
  goto _again;
2973
2976
  f19:
2974
- #line 555 "ext/dtext/dtext.rl"
2977
+ #line 563 "ext/dtext/dtext.rl"
2975
2978
  {( sm->te) = ( sm->p)+1;{
2976
2979
  dstack_close_before_block(sm);
2977
2980
 
@@ -2985,7 +2988,7 @@ f19:
2985
2988
  }}
2986
2989
  goto _again;
2987
2990
  f30:
2988
- #line 567 "ext/dtext/dtext.rl"
2991
+ #line 575 "ext/dtext/dtext.rl"
2989
2992
  {( sm->te) = ( sm->p)+1;{
2990
2993
  dstack_push(sm, &INLINE_NODTEXT);
2991
2994
  {
@@ -3003,7 +3006,7 @@ f30:
3003
3006
  }}
3004
3007
  goto _again;
3005
3008
  f24:
3006
- #line 572 "ext/dtext/dtext.rl"
3009
+ #line 580 "ext/dtext/dtext.rl"
3007
3010
  {( sm->te) = ( sm->p)+1;{
3008
3011
  if (dstack_check(sm, BLOCK_TH)) {
3009
3012
  dstack_pop(sm);
@@ -3015,7 +3018,7 @@ f24:
3015
3018
  }}
3016
3019
  goto _again;
3017
3020
  f23:
3018
- #line 582 "ext/dtext/dtext.rl"
3021
+ #line 590 "ext/dtext/dtext.rl"
3019
3022
  {( sm->te) = ( sm->p)+1;{
3020
3023
  if (dstack_check(sm, BLOCK_TD)) {
3021
3024
  dstack_pop(sm);
@@ -3027,7 +3030,7 @@ f23:
3027
3030
  }}
3028
3031
  goto _again;
3029
3032
  f73:
3030
- #line 592 "ext/dtext/dtext.rl"
3033
+ #line 600 "ext/dtext/dtext.rl"
3031
3034
  {( sm->te) = ( sm->p)+1;{
3032
3035
  g_debug("inline 0");
3033
3036
  g_debug(" return");
@@ -3037,14 +3040,14 @@ f73:
3037
3040
  }}
3038
3041
  goto _again;
3039
3042
  f72:
3040
- #line 628 "ext/dtext/dtext.rl"
3043
+ #line 636 "ext/dtext/dtext.rl"
3041
3044
  {( sm->te) = ( sm->p)+1;{
3042
3045
  g_debug("inline char: %c", (*( sm->p)));
3043
3046
  append_c_html_escaped(sm, (*( sm->p)));
3044
3047
  }}
3045
3048
  goto _again;
3046
3049
  f99:
3047
- #line 343 "ext/dtext/dtext.rl"
3050
+ #line 344 "ext/dtext/dtext.rl"
3048
3051
  {( sm->te) = ( sm->p);( sm->p)--;{
3049
3052
  if (is_boundary_c((*( sm->p)))) {
3050
3053
  sm->b = true;
@@ -3066,7 +3069,7 @@ f99:
3066
3069
  }}
3067
3070
  goto _again;
3068
3071
  f89:
3069
- #line 485 "ext/dtext/dtext.rl"
3072
+ #line 493 "ext/dtext/dtext.rl"
3070
3073
  {( sm->te) = ( sm->p);( sm->p)--;{
3071
3074
  dstack_rewind(sm);
3072
3075
  {( sm->p) = (( sm->a1 - 1))-1;}
@@ -3074,7 +3077,7 @@ f89:
3074
3077
  }}
3075
3078
  goto _again;
3076
3079
  f88:
3077
- #line 491 "ext/dtext/dtext.rl"
3080
+ #line 499 "ext/dtext/dtext.rl"
3078
3081
  {( sm->te) = ( sm->p);( sm->p)--;{
3079
3082
  dstack_rewind(sm);
3080
3083
  {( sm->p) = (( sm->a1 - 1))-1;}
@@ -3082,7 +3085,7 @@ f88:
3082
3085
  }}
3083
3086
  goto _again;
3084
3087
  f98:
3085
- #line 504 "ext/dtext/dtext.rl"
3088
+ #line 512 "ext/dtext/dtext.rl"
3086
3089
  {( sm->te) = ( sm->p);( sm->p)--;{
3087
3090
  g_debug("inline [/quote]");
3088
3091
  dstack_close_before_block(sm);
@@ -3100,7 +3103,7 @@ f98:
3100
3103
  }}
3101
3104
  goto _again;
3102
3105
  f76:
3103
- #line 600 "ext/dtext/dtext.rl"
3106
+ #line 608 "ext/dtext/dtext.rl"
3104
3107
  {( sm->te) = ( sm->p);( sm->p)--;{
3105
3108
  g_debug("inline newline2");
3106
3109
  g_debug(" return");
@@ -3114,7 +3117,7 @@ f76:
3114
3117
  }}
3115
3118
  goto _again;
3116
3119
  f75:
3117
- #line 612 "ext/dtext/dtext.rl"
3120
+ #line 620 "ext/dtext/dtext.rl"
3118
3121
  {( sm->te) = ( sm->p);( sm->p)--;{
3119
3122
  g_debug("inline newline");
3120
3123
 
@@ -3128,20 +3131,20 @@ f75:
3128
3131
  }}
3129
3132
  goto _again;
3130
3133
  f78:
3131
- #line 624 "ext/dtext/dtext.rl"
3134
+ #line 632 "ext/dtext/dtext.rl"
3132
3135
  {( sm->te) = ( sm->p);( sm->p)--;{
3133
3136
  append_c(sm, ' ');
3134
3137
  }}
3135
3138
  goto _again;
3136
3139
  f79:
3137
- #line 628 "ext/dtext/dtext.rl"
3140
+ #line 636 "ext/dtext/dtext.rl"
3138
3141
  {( sm->te) = ( sm->p);( sm->p)--;{
3139
3142
  g_debug("inline char: %c", (*( sm->p)));
3140
3143
  append_c_html_escaped(sm, (*( sm->p)));
3141
3144
  }}
3142
3145
  goto _again;
3143
3146
  f17:
3144
- #line 173 "ext/dtext/dtext.rl"
3147
+ #line 174 "ext/dtext/dtext.rl"
3145
3148
  {{( sm->p) = ((( sm->te)))-1;}{
3146
3149
  append(sm, true, "<a href=\"/forum_topics/");
3147
3150
  append_segment(sm, true, sm->a1, sm->a2 - 1);
@@ -3152,7 +3155,7 @@ f17:
3152
3155
  }}
3153
3156
  goto _again;
3154
3157
  f16:
3155
- #line 240 "ext/dtext/dtext.rl"
3158
+ #line 241 "ext/dtext/dtext.rl"
3156
3159
  {{( sm->p) = ((( sm->te)))-1;}{
3157
3160
  append(sm, true, "<a href=\"http://www.pixiv.net/member_illust.php?mode=medium&illust_id=");
3158
3161
  append_segment(sm, true, sm->a1, sm->a2 - 1);
@@ -3163,7 +3166,7 @@ f16:
3163
3166
  }}
3164
3167
  goto _again;
3165
3168
  f12:
3166
- #line 612 "ext/dtext/dtext.rl"
3169
+ #line 620 "ext/dtext/dtext.rl"
3167
3170
  {{( sm->p) = ((( sm->te)))-1;}{
3168
3171
  g_debug("inline newline");
3169
3172
 
@@ -3177,7 +3180,7 @@ f12:
3177
3180
  }}
3178
3181
  goto _again;
3179
3182
  f13:
3180
- #line 628 "ext/dtext/dtext.rl"
3183
+ #line 636 "ext/dtext/dtext.rl"
3181
3184
  {{( sm->p) = ((( sm->te)))-1;}{
3182
3185
  g_debug("inline char: %c", (*( sm->p)));
3183
3186
  append_c_html_escaped(sm, (*( sm->p)));
@@ -3193,23 +3196,30 @@ f10:
3193
3196
  break;
3194
3197
  case 19:
3195
3198
  {{( sm->p) = ((( sm->te)))-1;}
3196
- if (is_boundary_c((*( sm->p)))) {
3197
- sm->b = true;
3198
- sm->d = 2;
3199
+ if (!sm->f_mentions || (sm->a1 > sm->pb && sm->a1 - 1 > sm->pb && sm->a1[-2] != ' ' && sm->a1[-2] != '\r' && sm->a1[-2] != '\n')) {
3200
+ // handle emails
3201
+ append_c(sm, '@');
3202
+ append_segment_html_escaped(sm, sm->a1, sm->a2 - 1);
3203
+
3199
3204
  } else {
3200
- sm->b = false;
3201
- sm->d = 1;
3202
- }
3205
+ if (is_boundary_c((*( sm->p)))) {
3206
+ sm->b = true;
3207
+ sm->d = 2;
3208
+ } else {
3209
+ sm->b = false;
3210
+ sm->d = 1;
3211
+ }
3203
3212
 
3204
- append(sm, true, "<a rel=\"nofollow\" href=\"/users?name=");
3205
- append_segment_uri_escaped(sm, sm->a1, sm->a2 - sm->d);
3206
- append(sm, true, "\">");
3207
- append_c(sm, '@');
3208
- append_segment_html_escaped(sm, sm->a1, sm->a2 - sm->d);
3209
- append(sm, true, "</a>");
3213
+ append(sm, true, "<a rel=\"nofollow\" href=\"/users?name=");
3214
+ append_segment_uri_escaped(sm, sm->a1, sm->a2 - sm->d);
3215
+ append(sm, true, "\">");
3216
+ append_c(sm, '@');
3217
+ append_segment_html_escaped(sm, sm->a1, sm->a2 - sm->d);
3218
+ append(sm, true, "</a>");
3210
3219
 
3211
- if (sm->b) {
3212
- append_c_html_escaped(sm, (*( sm->p)));
3220
+ if (sm->b) {
3221
+ append_c_html_escaped(sm, (*( sm->p)));
3222
+ }
3213
3223
  }
3214
3224
  }
3215
3225
  break;
@@ -3243,7 +3253,7 @@ f10:
3243
3253
  }
3244
3254
  goto _again;
3245
3255
  f40:
3246
- #line 635 "ext/dtext/dtext.rl"
3256
+ #line 643 "ext/dtext/dtext.rl"
3247
3257
  {( sm->te) = ( sm->p)+1;{
3248
3258
  if (dstack_check(sm, BLOCK_CODE)) {
3249
3259
  dstack_rewind(sm);
@@ -3254,32 +3264,32 @@ f40:
3254
3264
  }}
3255
3265
  goto _again;
3256
3266
  f101:
3257
- #line 644 "ext/dtext/dtext.rl"
3267
+ #line 652 "ext/dtext/dtext.rl"
3258
3268
  {( sm->te) = ( sm->p)+1;{
3259
3269
  ( sm->p)--;
3260
3270
  { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;}
3261
3271
  }}
3262
3272
  goto _again;
3263
3273
  f100:
3264
- #line 649 "ext/dtext/dtext.rl"
3274
+ #line 657 "ext/dtext/dtext.rl"
3265
3275
  {( sm->te) = ( sm->p)+1;{
3266
3276
  append_c_html_escaped(sm, (*( sm->p)));
3267
3277
  }}
3268
3278
  goto _again;
3269
3279
  f102:
3270
- #line 649 "ext/dtext/dtext.rl"
3280
+ #line 657 "ext/dtext/dtext.rl"
3271
3281
  {( sm->te) = ( sm->p);( sm->p)--;{
3272
3282
  append_c_html_escaped(sm, (*( sm->p)));
3273
3283
  }}
3274
3284
  goto _again;
3275
3285
  f39:
3276
- #line 649 "ext/dtext/dtext.rl"
3286
+ #line 657 "ext/dtext/dtext.rl"
3277
3287
  {{( sm->p) = ((( sm->te)))-1;}{
3278
3288
  append_c_html_escaped(sm, (*( sm->p)));
3279
3289
  }}
3280
3290
  goto _again;
3281
3291
  f42:
3282
- #line 655 "ext/dtext/dtext.rl"
3292
+ #line 663 "ext/dtext/dtext.rl"
3283
3293
  {( sm->te) = ( sm->p)+1;{
3284
3294
  if (dstack_check(sm, BLOCK_NODTEXT)) {
3285
3295
  dstack_pop(sm);
@@ -3294,39 +3304,39 @@ f42:
3294
3304
  }}
3295
3305
  goto _again;
3296
3306
  f104:
3297
- #line 668 "ext/dtext/dtext.rl"
3307
+ #line 676 "ext/dtext/dtext.rl"
3298
3308
  {( sm->te) = ( sm->p)+1;{
3299
3309
  ( sm->p)--;
3300
3310
  { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;}
3301
3311
  }}
3302
3312
  goto _again;
3303
3313
  f103:
3304
- #line 673 "ext/dtext/dtext.rl"
3314
+ #line 681 "ext/dtext/dtext.rl"
3305
3315
  {( sm->te) = ( sm->p)+1;{
3306
3316
  append_c_html_escaped(sm, (*( sm->p)));
3307
3317
  }}
3308
3318
  goto _again;
3309
3319
  f105:
3310
- #line 673 "ext/dtext/dtext.rl"
3320
+ #line 681 "ext/dtext/dtext.rl"
3311
3321
  {( sm->te) = ( sm->p);( sm->p)--;{
3312
3322
  append_c_html_escaped(sm, (*( sm->p)));
3313
3323
  }}
3314
3324
  goto _again;
3315
3325
  f41:
3316
- #line 673 "ext/dtext/dtext.rl"
3326
+ #line 681 "ext/dtext/dtext.rl"
3317
3327
  {{( sm->p) = ((( sm->te)))-1;}{
3318
3328
  append_c_html_escaped(sm, (*( sm->p)));
3319
3329
  }}
3320
3330
  goto _again;
3321
3331
  f51:
3322
- #line 679 "ext/dtext/dtext.rl"
3332
+ #line 687 "ext/dtext/dtext.rl"
3323
3333
  {( sm->te) = ( sm->p)+1;{
3324
3334
  dstack_push(sm, &BLOCK_THEAD);
3325
3335
  append_block(sm, "<thead>");
3326
3336
  }}
3327
3337
  goto _again;
3328
3338
  f46:
3329
- #line 684 "ext/dtext/dtext.rl"
3339
+ #line 692 "ext/dtext/dtext.rl"
3330
3340
  {( sm->te) = ( sm->p)+1;{
3331
3341
  if (dstack_check(sm, BLOCK_THEAD)) {
3332
3342
  dstack_pop(sm);
@@ -3337,14 +3347,14 @@ f46:
3337
3347
  }}
3338
3348
  goto _again;
3339
3349
  f48:
3340
- #line 693 "ext/dtext/dtext.rl"
3350
+ #line 701 "ext/dtext/dtext.rl"
3341
3351
  {( sm->te) = ( sm->p)+1;{
3342
3352
  dstack_push(sm, &BLOCK_TBODY);
3343
3353
  append_block(sm, "<tbody>");
3344
3354
  }}
3345
3355
  goto _again;
3346
3356
  f45:
3347
- #line 698 "ext/dtext/dtext.rl"
3357
+ #line 706 "ext/dtext/dtext.rl"
3348
3358
  {( sm->te) = ( sm->p)+1;{
3349
3359
  if (dstack_check(sm, BLOCK_TBODY)) {
3350
3360
  dstack_pop(sm);
@@ -3355,7 +3365,7 @@ f45:
3355
3365
  }}
3356
3366
  goto _again;
3357
3367
  f50:
3358
- #line 707 "ext/dtext/dtext.rl"
3368
+ #line 715 "ext/dtext/dtext.rl"
3359
3369
  {( sm->te) = ( sm->p)+1;{
3360
3370
  dstack_push(sm, &BLOCK_TH);
3361
3371
  append_block(sm, "<th>");
@@ -3374,14 +3384,14 @@ f50:
3374
3384
  }}
3375
3385
  goto _again;
3376
3386
  f52:
3377
- #line 713 "ext/dtext/dtext.rl"
3387
+ #line 721 "ext/dtext/dtext.rl"
3378
3388
  {( sm->te) = ( sm->p)+1;{
3379
3389
  dstack_push(sm, &BLOCK_TR);
3380
3390
  append_block(sm, "<tr>");
3381
3391
  }}
3382
3392
  goto _again;
3383
3393
  f47:
3384
- #line 718 "ext/dtext/dtext.rl"
3394
+ #line 726 "ext/dtext/dtext.rl"
3385
3395
  {( sm->te) = ( sm->p)+1;{
3386
3396
  if (dstack_check(sm, BLOCK_TR)) {
3387
3397
  dstack_pop(sm);
@@ -3392,7 +3402,7 @@ f47:
3392
3402
  }}
3393
3403
  goto _again;
3394
3404
  f49:
3395
- #line 727 "ext/dtext/dtext.rl"
3405
+ #line 735 "ext/dtext/dtext.rl"
3396
3406
  {( sm->te) = ( sm->p)+1;{
3397
3407
  dstack_push(sm, &BLOCK_TD);
3398
3408
  append_block(sm, "<td>");
@@ -3411,7 +3421,7 @@ f49:
3411
3421
  }}
3412
3422
  goto _again;
3413
3423
  f44:
3414
- #line 733 "ext/dtext/dtext.rl"
3424
+ #line 741 "ext/dtext/dtext.rl"
3415
3425
  {( sm->te) = ( sm->p)+1;{
3416
3426
  if (dstack_check(sm, BLOCK_TABLE)) {
3417
3427
  dstack_pop(sm);
@@ -3423,26 +3433,26 @@ f44:
3423
3433
  }}
3424
3434
  goto _again;
3425
3435
  f107:
3426
- #line 743 "ext/dtext/dtext.rl"
3436
+ #line 751 "ext/dtext/dtext.rl"
3427
3437
  {( sm->te) = ( sm->p)+1;{
3428
3438
  ( sm->p)--;
3429
3439
  { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;}
3430
3440
  }}
3431
3441
  goto _again;
3432
3442
  f106:
3433
- #line 748 "ext/dtext/dtext.rl"
3443
+ #line 756 "ext/dtext/dtext.rl"
3434
3444
  {( sm->te) = ( sm->p)+1;}
3435
3445
  goto _again;
3436
3446
  f108:
3437
- #line 748 "ext/dtext/dtext.rl"
3447
+ #line 756 "ext/dtext/dtext.rl"
3438
3448
  {( sm->te) = ( sm->p);( sm->p)--;}
3439
3449
  goto _again;
3440
3450
  f43:
3441
- #line 748 "ext/dtext/dtext.rl"
3451
+ #line 756 "ext/dtext/dtext.rl"
3442
3452
  {{( sm->p) = ((( sm->te)))-1;}}
3443
3453
  goto _again;
3444
3454
  f110:
3445
- #line 791 "ext/dtext/dtext.rl"
3455
+ #line 799 "ext/dtext/dtext.rl"
3446
3456
  {( sm->te) = ( sm->p)+1;{
3447
3457
  dstack_close_list(sm);
3448
3458
  {( sm->p) = (( sm->ts))-1;}
@@ -3450,7 +3460,7 @@ f110:
3450
3460
  }}
3451
3461
  goto _again;
3452
3462
  f109:
3453
- #line 799 "ext/dtext/dtext.rl"
3463
+ #line 807 "ext/dtext/dtext.rl"
3454
3464
  {( sm->te) = ( sm->p)+1;{
3455
3465
  dstack_rewind(sm);
3456
3466
  ( sm->p)--;
@@ -3458,7 +3468,7 @@ f109:
3458
3468
  }}
3459
3469
  goto _again;
3460
3470
  f112:
3461
- #line 799 "ext/dtext/dtext.rl"
3471
+ #line 807 "ext/dtext/dtext.rl"
3462
3472
  {( sm->te) = ( sm->p);( sm->p)--;{
3463
3473
  dstack_rewind(sm);
3464
3474
  ( sm->p)--;
@@ -3466,7 +3476,7 @@ f112:
3466
3476
  }}
3467
3477
  goto _again;
3468
3478
  f55:
3469
- #line 799 "ext/dtext/dtext.rl"
3479
+ #line 807 "ext/dtext/dtext.rl"
3470
3480
  {{( sm->p) = ((( sm->te)))-1;}{
3471
3481
  dstack_rewind(sm);
3472
3482
  ( sm->p)--;
@@ -3490,7 +3500,7 @@ f53:
3490
3500
  }
3491
3501
  goto _again;
3492
3502
  f6:
3493
- #line 930 "ext/dtext/dtext.rl"
3503
+ #line 939 "ext/dtext/dtext.rl"
3494
3504
  {( sm->te) = ( sm->p)+1;{
3495
3505
  g_debug("block [/spoiler]");
3496
3506
  dstack_close_before_block(sm);
@@ -3501,7 +3511,7 @@ f6:
3501
3511
  }}
3502
3512
  goto _again;
3503
3513
  f8:
3504
- #line 977 "ext/dtext/dtext.rl"
3514
+ #line 986 "ext/dtext/dtext.rl"
3505
3515
  {( sm->te) = ( sm->p)+1;{
3506
3516
  dstack_close_before_block(sm);
3507
3517
  dstack_push(sm, &BLOCK_TABLE);
@@ -3521,7 +3531,7 @@ f8:
3521
3531
  }}
3522
3532
  goto _again;
3523
3533
  f9:
3524
- #line 984 "ext/dtext/dtext.rl"
3534
+ #line 993 "ext/dtext/dtext.rl"
3525
3535
  {( sm->te) = ( sm->p)+1;{
3526
3536
  dstack_push(sm, &BLOCK_TN);
3527
3537
  append_block(sm, "<p class=\"tn\">");
@@ -3540,7 +3550,7 @@ f9:
3540
3550
  }}
3541
3551
  goto _again;
3542
3552
  f59:
3543
- #line 1000 "ext/dtext/dtext.rl"
3553
+ #line 1009 "ext/dtext/dtext.rl"
3544
3554
  {( sm->te) = ( sm->p)+1;{
3545
3555
  g_debug("block 0");
3546
3556
  g_debug(" close dstack");
@@ -3548,7 +3558,7 @@ f59:
3548
3558
  }}
3549
3559
  goto _again;
3550
3560
  f58:
3551
- #line 1023 "ext/dtext/dtext.rl"
3561
+ #line 1032 "ext/dtext/dtext.rl"
3552
3562
  {( sm->te) = ( sm->p)+1;{
3553
3563
  g_debug("block char: %c", (*( sm->p)));
3554
3564
  ( sm->p)--;
@@ -3575,10 +3585,11 @@ f58:
3575
3585
  }}
3576
3586
  goto _again;
3577
3587
  f64:
3578
- #line 807 "ext/dtext/dtext.rl"
3588
+ #line 815 "ext/dtext/dtext.rl"
3579
3589
  {( sm->te) = ( sm->p);( sm->p)--;{
3580
3590
  char header = *sm->a1;
3581
3591
  GString * id_name = g_string_new_len(sm->b1, sm->b2 - sm->b1);
3592
+ id_name = g_string_prepend(id_name, "dtext-");
3582
3593
 
3583
3594
  if (sm->f_inline) {
3584
3595
  header = '6';
@@ -3648,7 +3659,7 @@ f64:
3648
3659
  }}
3649
3660
  goto _again;
3650
3661
  f65:
3651
- #line 867 "ext/dtext/dtext.rl"
3662
+ #line 876 "ext/dtext/dtext.rl"
3652
3663
  {( sm->te) = ( sm->p);( sm->p)--;{
3653
3664
  char header = *sm->a1;
3654
3665
 
@@ -3706,7 +3717,7 @@ f65:
3706
3717
  }}
3707
3718
  goto _again;
3708
3719
  f70:
3709
- #line 912 "ext/dtext/dtext.rl"
3720
+ #line 921 "ext/dtext/dtext.rl"
3710
3721
  {( sm->te) = ( sm->p);( sm->p)--;{
3711
3722
  g_debug("block [quote]");
3712
3723
  g_debug(" push quote");
@@ -3717,7 +3728,7 @@ f70:
3717
3728
  }}
3718
3729
  goto _again;
3719
3730
  f71:
3720
- #line 921 "ext/dtext/dtext.rl"
3731
+ #line 930 "ext/dtext/dtext.rl"
3721
3732
  {( sm->te) = ( sm->p);( sm->p)--;{
3722
3733
  g_debug("block [spoiler]");
3723
3734
  g_debug(" push spoiler");
@@ -3728,7 +3739,7 @@ f71:
3728
3739
  }}
3729
3740
  goto _again;
3730
3741
  f66:
3731
- #line 939 "ext/dtext/dtext.rl"
3742
+ #line 948 "ext/dtext/dtext.rl"
3732
3743
  {( sm->te) = ( sm->p);( sm->p)--;{
3733
3744
  g_debug("block [code]");
3734
3745
  dstack_close_before_block(sm);
@@ -3749,7 +3760,7 @@ f66:
3749
3760
  }}
3750
3761
  goto _again;
3751
3762
  f68:
3752
- #line 947 "ext/dtext/dtext.rl"
3763
+ #line 956 "ext/dtext/dtext.rl"
3753
3764
  {( sm->te) = ( sm->p);( sm->p)--;{
3754
3765
  g_debug("block [expand]");
3755
3766
  dstack_close_before_block(sm);
@@ -3760,7 +3771,7 @@ f68:
3760
3771
  }}
3761
3772
  goto _again;
3762
3773
  f67:
3763
- #line 956 "ext/dtext/dtext.rl"
3774
+ #line 965 "ext/dtext/dtext.rl"
3764
3775
  {( sm->te) = ( sm->p);( sm->p)--;{
3765
3776
  g_debug("block [expand=]");
3766
3777
  dstack_close_before_block(sm);
@@ -3774,7 +3785,7 @@ f67:
3774
3785
  }}
3775
3786
  goto _again;
3776
3787
  f69:
3777
- #line 968 "ext/dtext/dtext.rl"
3788
+ #line 977 "ext/dtext/dtext.rl"
3778
3789
  {( sm->te) = ( sm->p);( sm->p)--;{
3779
3790
  g_debug("block [nodtext]");
3780
3791
  dstack_close_before_block(sm);
@@ -3796,7 +3807,7 @@ f69:
3796
3807
  }}
3797
3808
  goto _again;
3798
3809
  f62:
3799
- #line 1023 "ext/dtext/dtext.rl"
3810
+ #line 1032 "ext/dtext/dtext.rl"
3800
3811
  {( sm->te) = ( sm->p);( sm->p)--;{
3801
3812
  g_debug("block char: %c", (*( sm->p)));
3802
3813
  ( sm->p)--;
@@ -3823,7 +3834,7 @@ f62:
3823
3834
  }}
3824
3835
  goto _again;
3825
3836
  f2:
3826
- #line 1023 "ext/dtext/dtext.rl"
3837
+ #line 1032 "ext/dtext/dtext.rl"
3827
3838
  {{( sm->p) = ((( sm->te)))-1;}{
3828
3839
  g_debug("block char: %c", (*( sm->p)));
3829
3840
  ( sm->p)--;
@@ -3875,11 +3886,11 @@ f0:
3875
3886
  }
3876
3887
  goto _again;
3877
3888
  f94:
3878
- #line 101 "ext/dtext/dtext.rl"
3889
+ #line 102 "ext/dtext/dtext.rl"
3879
3890
  {
3880
3891
  sm->a2 = sm->p;
3881
3892
  }
3882
- #line 155 "ext/dtext/dtext.rl"
3893
+ #line 156 "ext/dtext/dtext.rl"
3883
3894
  {( sm->te) = ( sm->p);( sm->p)--;{
3884
3895
  append(sm, true, "<a href=\"/posts/");
3885
3896
  append_segment(sm, true, sm->a1, sm->a2 - 1);
@@ -3890,11 +3901,11 @@ f94:
3890
3901
  }}
3891
3902
  goto _again;
3892
3903
  f87:
3893
- #line 101 "ext/dtext/dtext.rl"
3904
+ #line 102 "ext/dtext/dtext.rl"
3894
3905
  {
3895
3906
  sm->a2 = sm->p;
3896
3907
  }
3897
- #line 164 "ext/dtext/dtext.rl"
3908
+ #line 165 "ext/dtext/dtext.rl"
3898
3909
  {( sm->te) = ( sm->p);( sm->p)--;{
3899
3910
  append(sm, true, "<a href=\"/forum_posts/");
3900
3911
  append_segment(sm, true, sm->a1, sm->a2 - 1);
@@ -3905,11 +3916,11 @@ f87:
3905
3916
  }}
3906
3917
  goto _again;
3907
3918
  f95:
3908
- #line 101 "ext/dtext/dtext.rl"
3919
+ #line 102 "ext/dtext/dtext.rl"
3909
3920
  {
3910
3921
  sm->a2 = sm->p;
3911
3922
  }
3912
- #line 173 "ext/dtext/dtext.rl"
3923
+ #line 174 "ext/dtext/dtext.rl"
3913
3924
  {( sm->te) = ( sm->p);( sm->p)--;{
3914
3925
  append(sm, true, "<a href=\"/forum_topics/");
3915
3926
  append_segment(sm, true, sm->a1, sm->a2 - 1);
@@ -3920,11 +3931,11 @@ f95:
3920
3931
  }}
3921
3932
  goto _again;
3922
3933
  f86:
3923
- #line 101 "ext/dtext/dtext.rl"
3934
+ #line 102 "ext/dtext/dtext.rl"
3924
3935
  {
3925
3936
  sm->a2 = sm->p;
3926
3937
  }
3927
- #line 195 "ext/dtext/dtext.rl"
3938
+ #line 196 "ext/dtext/dtext.rl"
3928
3939
  {( sm->te) = ( sm->p);( sm->p)--;{
3929
3940
  append(sm, true, "<a href=\"/comments/");
3930
3941
  append_segment(sm, true, sm->a1, sm->a2 - 1);
@@ -3935,11 +3946,11 @@ f86:
3935
3946
  }}
3936
3947
  goto _again;
3937
3948
  f93:
3938
- #line 101 "ext/dtext/dtext.rl"
3949
+ #line 102 "ext/dtext/dtext.rl"
3939
3950
  {
3940
3951
  sm->a2 = sm->p;
3941
3952
  }
3942
- #line 204 "ext/dtext/dtext.rl"
3953
+ #line 205 "ext/dtext/dtext.rl"
3943
3954
  {( sm->te) = ( sm->p);( sm->p)--;{
3944
3955
  append(sm, true, "<a href=\"/pools/");
3945
3956
  append_segment(sm, true, sm->a1, sm->a2 - 1);
@@ -3950,11 +3961,11 @@ f93:
3950
3961
  }}
3951
3962
  goto _again;
3952
3963
  f97:
3953
- #line 101 "ext/dtext/dtext.rl"
3964
+ #line 102 "ext/dtext/dtext.rl"
3954
3965
  {
3955
3966
  sm->a2 = sm->p;
3956
3967
  }
3957
- #line 213 "ext/dtext/dtext.rl"
3968
+ #line 214 "ext/dtext/dtext.rl"
3958
3969
  {( sm->te) = ( sm->p);( sm->p)--;{
3959
3970
  append(sm, true, "<a href=\"/users/");
3960
3971
  append_segment(sm, true, sm->a1, sm->a2 - 1);
@@ -3965,11 +3976,11 @@ f97:
3965
3976
  }}
3966
3977
  goto _again;
3967
3978
  f85:
3968
- #line 101 "ext/dtext/dtext.rl"
3979
+ #line 102 "ext/dtext/dtext.rl"
3969
3980
  {
3970
3981
  sm->a2 = sm->p;
3971
3982
  }
3972
- #line 222 "ext/dtext/dtext.rl"
3983
+ #line 223 "ext/dtext/dtext.rl"
3973
3984
  {( sm->te) = ( sm->p);( sm->p)--;{
3974
3985
  append(sm, true, "<a href=\"/artists/");
3975
3986
  append_segment(sm, true, sm->a1, sm->a2 - 1);
@@ -3980,11 +3991,11 @@ f85:
3980
3991
  }}
3981
3992
  goto _again;
3982
3993
  f90:
3983
- #line 101 "ext/dtext/dtext.rl"
3994
+ #line 102 "ext/dtext/dtext.rl"
3984
3995
  {
3985
3996
  sm->a2 = sm->p;
3986
3997
  }
3987
- #line 231 "ext/dtext/dtext.rl"
3998
+ #line 232 "ext/dtext/dtext.rl"
3988
3999
  {( sm->te) = ( sm->p);( sm->p)--;{
3989
4000
  append(sm, true, "<a href=\"https://github.com/r888888888/danbooru/issues/");
3990
4001
  append_segment(sm, true, sm->a1, sm->a2 - 1);
@@ -3995,11 +4006,11 @@ f90:
3995
4006
  }}
3996
4007
  goto _again;
3997
4008
  f91:
3998
- #line 101 "ext/dtext/dtext.rl"
4009
+ #line 102 "ext/dtext/dtext.rl"
3999
4010
  {
4000
4011
  sm->a2 = sm->p;
4001
4012
  }
4002
- #line 240 "ext/dtext/dtext.rl"
4013
+ #line 241 "ext/dtext/dtext.rl"
4003
4014
  {( sm->te) = ( sm->p);( sm->p)--;{
4004
4015
  append(sm, true, "<a href=\"http://www.pixiv.net/member_illust.php?mode=medium&illust_id=");
4005
4016
  append_segment(sm, true, sm->a1, sm->a2 - 1);
@@ -4010,34 +4021,41 @@ f91:
4010
4021
  }}
4011
4022
  goto _again;
4012
4023
  f81:
4013
- #line 101 "ext/dtext/dtext.rl"
4024
+ #line 102 "ext/dtext/dtext.rl"
4014
4025
  {
4015
4026
  sm->a2 = sm->p;
4016
4027
  }
4017
- #line 368 "ext/dtext/dtext.rl"
4028
+ #line 369 "ext/dtext/dtext.rl"
4018
4029
  {( sm->te) = ( sm->p);( sm->p)--;{
4019
- if (is_boundary_c((*( sm->p)))) {
4020
- sm->b = true;
4021
- sm->d = 2;
4030
+ if (!sm->f_mentions || (sm->a1 > sm->pb && sm->a1 - 1 > sm->pb && sm->a1[-2] != ' ' && sm->a1[-2] != '\r' && sm->a1[-2] != '\n')) {
4031
+ // handle emails
4032
+ append_c(sm, '@');
4033
+ append_segment_html_escaped(sm, sm->a1, sm->a2 - 1);
4034
+
4022
4035
  } else {
4023
- sm->b = false;
4024
- sm->d = 1;
4025
- }
4036
+ if (is_boundary_c((*( sm->p)))) {
4037
+ sm->b = true;
4038
+ sm->d = 2;
4039
+ } else {
4040
+ sm->b = false;
4041
+ sm->d = 1;
4042
+ }
4026
4043
 
4027
- append(sm, true, "<a rel=\"nofollow\" href=\"/users?name=");
4028
- append_segment_uri_escaped(sm, sm->a1, sm->a2 - sm->d);
4029
- append(sm, true, "\">");
4030
- append_c(sm, '@');
4031
- append_segment_html_escaped(sm, sm->a1, sm->a2 - sm->d);
4032
- append(sm, true, "</a>");
4044
+ append(sm, true, "<a rel=\"nofollow\" href=\"/users?name=");
4045
+ append_segment_uri_escaped(sm, sm->a1, sm->a2 - sm->d);
4046
+ append(sm, true, "\">");
4047
+ append_c(sm, '@');
4048
+ append_segment_html_escaped(sm, sm->a1, sm->a2 - sm->d);
4049
+ append(sm, true, "</a>");
4033
4050
 
4034
- if (sm->b) {
4035
- append_c_html_escaped(sm, (*( sm->p)));
4051
+ if (sm->b) {
4052
+ append_c_html_escaped(sm, (*( sm->p)));
4053
+ }
4036
4054
  }
4037
4055
  }}
4038
4056
  goto _again;
4039
4057
  f84:
4040
- #line 101 "ext/dtext/dtext.rl"
4058
+ #line 102 "ext/dtext/dtext.rl"
4041
4059
  {
4042
4060
  sm->a2 = sm->p;
4043
4061
  }
@@ -4050,23 +4068,30 @@ f84:
4050
4068
  break;
4051
4069
  case 19:
4052
4070
  {{( sm->p) = ((( sm->te)))-1;}
4053
- if (is_boundary_c((*( sm->p)))) {
4054
- sm->b = true;
4055
- sm->d = 2;
4071
+ if (!sm->f_mentions || (sm->a1 > sm->pb && sm->a1 - 1 > sm->pb && sm->a1[-2] != ' ' && sm->a1[-2] != '\r' && sm->a1[-2] != '\n')) {
4072
+ // handle emails
4073
+ append_c(sm, '@');
4074
+ append_segment_html_escaped(sm, sm->a1, sm->a2 - 1);
4075
+
4056
4076
  } else {
4057
- sm->b = false;
4058
- sm->d = 1;
4059
- }
4077
+ if (is_boundary_c((*( sm->p)))) {
4078
+ sm->b = true;
4079
+ sm->d = 2;
4080
+ } else {
4081
+ sm->b = false;
4082
+ sm->d = 1;
4083
+ }
4060
4084
 
4061
- append(sm, true, "<a rel=\"nofollow\" href=\"/users?name=");
4062
- append_segment_uri_escaped(sm, sm->a1, sm->a2 - sm->d);
4063
- append(sm, true, "\">");
4064
- append_c(sm, '@');
4065
- append_segment_html_escaped(sm, sm->a1, sm->a2 - sm->d);
4066
- append(sm, true, "</a>");
4085
+ append(sm, true, "<a rel=\"nofollow\" href=\"/users?name=");
4086
+ append_segment_uri_escaped(sm, sm->a1, sm->a2 - sm->d);
4087
+ append(sm, true, "\">");
4088
+ append_c(sm, '@');
4089
+ append_segment_html_escaped(sm, sm->a1, sm->a2 - sm->d);
4090
+ append(sm, true, "</a>");
4067
4091
 
4068
- if (sm->b) {
4069
- append_c_html_escaped(sm, (*( sm->p)));
4092
+ if (sm->b) {
4093
+ append_c_html_escaped(sm, (*( sm->p)));
4094
+ }
4070
4095
  }
4071
4096
  }
4072
4097
  break;
@@ -4100,11 +4125,11 @@ f84:
4100
4125
  }
4101
4126
  goto _again;
4102
4127
  f14:
4103
- #line 109 "ext/dtext/dtext.rl"
4128
+ #line 110 "ext/dtext/dtext.rl"
4104
4129
  {
4105
4130
  sm->b2 = sm->p;
4106
4131
  }
4107
- #line 335 "ext/dtext/dtext.rl"
4132
+ #line 336 "ext/dtext/dtext.rl"
4108
4133
  {( sm->te) = ( sm->p)+1;{
4109
4134
  append(sm, true, "<a href=\"");
4110
4135
  append_segment_html_escaped(sm, sm->b1, sm->b2 - 1);
@@ -4114,11 +4139,11 @@ f14:
4114
4139
  }}
4115
4140
  goto _again;
4116
4141
  f96:
4117
- #line 109 "ext/dtext/dtext.rl"
4142
+ #line 110 "ext/dtext/dtext.rl"
4118
4143
  {
4119
4144
  sm->b2 = sm->p;
4120
4145
  }
4121
- #line 182 "ext/dtext/dtext.rl"
4146
+ #line 183 "ext/dtext/dtext.rl"
4122
4147
  {( sm->te) = ( sm->p);( sm->p)--;{
4123
4148
  append(sm, true, "<a href=\"/forum_topics/");
4124
4149
  append_segment(sm, true, sm->a1, sm->a2 - 1);
@@ -4133,11 +4158,11 @@ f96:
4133
4158
  }}
4134
4159
  goto _again;
4135
4160
  f92:
4136
- #line 109 "ext/dtext/dtext.rl"
4161
+ #line 110 "ext/dtext/dtext.rl"
4137
4162
  {
4138
4163
  sm->b2 = sm->p;
4139
4164
  }
4140
- #line 249 "ext/dtext/dtext.rl"
4165
+ #line 250 "ext/dtext/dtext.rl"
4141
4166
  {( sm->te) = ( sm->p);( sm->p)--;{
4142
4167
  append(sm, true, "<a href=\"http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=");
4143
4168
  append_segment(sm, true, sm->a1, sm->a2 - 1);
@@ -4152,11 +4177,11 @@ f92:
4152
4177
  }}
4153
4178
  goto _again;
4154
4179
  f80:
4155
- #line 109 "ext/dtext/dtext.rl"
4180
+ #line 110 "ext/dtext/dtext.rl"
4156
4181
  {
4157
4182
  sm->b2 = sm->p;
4158
4183
  }
4159
- #line 312 "ext/dtext/dtext.rl"
4184
+ #line 313 "ext/dtext/dtext.rl"
4160
4185
  {( sm->te) = ( sm->p);( sm->p)--;{
4161
4186
  if (is_boundary_c((*( sm->p)))) {
4162
4187
  sm->d = 2;
@@ -4169,7 +4194,7 @@ f80:
4169
4194
  append(sm, true, "<a href=\"");
4170
4195
  append_segment_html_escaped(sm, sm->b1, sm->b2 - sm->d);
4171
4196
  append(sm, true, "\">");
4172
- link_content_sm = parse_helper(sm->a1, sm->a2 - sm->a1, false, true);
4197
+ link_content_sm = parse_helper(sm->a1, sm->a2 - sm->a1, false, true, false);
4173
4198
  append(sm, true, link_content_sm->output->str);
4174
4199
  free_machine(link_content_sm);
4175
4200
  link_content_sm = NULL;
@@ -4181,11 +4206,11 @@ f80:
4181
4206
  }}
4182
4207
  goto _again;
4183
4208
  f77:
4184
- #line 109 "ext/dtext/dtext.rl"
4209
+ #line 110 "ext/dtext/dtext.rl"
4185
4210
  {
4186
4211
  sm->b2 = sm->p;
4187
4212
  }
4188
- #line 389 "ext/dtext/dtext.rl"
4213
+ #line 397 "ext/dtext/dtext.rl"
4189
4214
  {( sm->te) = ( sm->p);( sm->p)--;{
4190
4215
  g_debug("inline list");
4191
4216
 
@@ -4206,11 +4231,11 @@ f77:
4206
4231
  }}
4207
4232
  goto _again;
4208
4233
  f113:
4209
- #line 109 "ext/dtext/dtext.rl"
4234
+ #line 110 "ext/dtext/dtext.rl"
4210
4235
  {
4211
4236
  sm->b2 = sm->p;
4212
4237
  }
4213
- #line 752 "ext/dtext/dtext.rl"
4238
+ #line 760 "ext/dtext/dtext.rl"
4214
4239
  {( sm->te) = ( sm->p);( sm->p)--;{
4215
4240
  int prev_nest = sm->list_nest;
4216
4241
  append_closing_p_if(sm);
@@ -4261,11 +4286,11 @@ f113:
4261
4286
  }}
4262
4287
  goto _again;
4263
4288
  f63:
4264
- #line 109 "ext/dtext/dtext.rl"
4289
+ #line 110 "ext/dtext/dtext.rl"
4265
4290
  {
4266
4291
  sm->b2 = sm->p;
4267
4292
  }
4268
- #line 990 "ext/dtext/dtext.rl"
4293
+ #line 999 "ext/dtext/dtext.rl"
4269
4294
  {( sm->te) = ( sm->p);( sm->p)--;{
4270
4295
  g_debug("block list");
4271
4296
  g_debug(" call list");
@@ -4290,7 +4315,7 @@ f63:
4290
4315
  f15:
4291
4316
  #line 1 "NONE"
4292
4317
  {( sm->te) = ( sm->p)+1;}
4293
- #line 97 "ext/dtext/dtext.rl"
4318
+ #line 98 "ext/dtext/dtext.rl"
4294
4319
  {
4295
4320
  sm->a1 = sm->p;
4296
4321
  }
@@ -4298,49 +4323,49 @@ f15:
4298
4323
  f83:
4299
4324
  #line 1 "NONE"
4300
4325
  {( sm->te) = ( sm->p)+1;}
4301
- #line 364 "ext/dtext/dtext.rl"
4326
+ #line 365 "ext/dtext/dtext.rl"
4302
4327
  {( sm->act) = 18;}
4303
4328
  goto _again;
4304
4329
  f82:
4305
4330
  #line 1 "NONE"
4306
4331
  {( sm->te) = ( sm->p)+1;}
4307
- #line 368 "ext/dtext/dtext.rl"
4332
+ #line 369 "ext/dtext/dtext.rl"
4308
4333
  {( sm->act) = 19;}
4309
4334
  goto _again;
4310
4335
  f11:
4311
4336
  #line 1 "NONE"
4312
4337
  {( sm->te) = ( sm->p)+1;}
4313
- #line 600 "ext/dtext/dtext.rl"
4338
+ #line 608 "ext/dtext/dtext.rl"
4314
4339
  {( sm->act) = 43;}
4315
4340
  goto _again;
4316
4341
  f74:
4317
4342
  #line 1 "NONE"
4318
4343
  {( sm->te) = ( sm->p)+1;}
4319
- #line 612 "ext/dtext/dtext.rl"
4344
+ #line 620 "ext/dtext/dtext.rl"
4320
4345
  {( sm->act) = 44;}
4321
4346
  goto _again;
4322
4347
  f54:
4323
4348
  #line 1 "NONE"
4324
4349
  {( sm->te) = ( sm->p)+1;}
4325
- #line 791 "ext/dtext/dtext.rl"
4350
+ #line 799 "ext/dtext/dtext.rl"
4326
4351
  {( sm->act) = 65;}
4327
4352
  goto _again;
4328
4353
  f111:
4329
4354
  #line 1 "NONE"
4330
4355
  {( sm->te) = ( sm->p)+1;}
4331
- #line 797 "ext/dtext/dtext.rl"
4356
+ #line 805 "ext/dtext/dtext.rl"
4332
4357
  {( sm->act) = 66;}
4333
4358
  goto _again;
4334
4359
  f1:
4335
4360
  #line 1 "NONE"
4336
4361
  {( sm->te) = ( sm->p)+1;}
4337
- #line 1006 "ext/dtext/dtext.rl"
4362
+ #line 1015 "ext/dtext/dtext.rl"
4338
4363
  {( sm->act) = 81;}
4339
4364
  goto _again;
4340
4365
  f60:
4341
4366
  #line 1 "NONE"
4342
4367
  {( sm->te) = ( sm->p)+1;}
4343
- #line 1019 "ext/dtext/dtext.rl"
4368
+ #line 1028 "ext/dtext/dtext.rl"
4344
4369
  {( sm->act) = 82;}
4345
4370
  goto _again;
4346
4371
 
@@ -4350,7 +4375,7 @@ _again:
4350
4375
  #line 1 "NONE"
4351
4376
  {( sm->ts) = 0;}
4352
4377
  break;
4353
- #line 4354 "ext/dtext/dtext.c"
4378
+ #line 4379 "ext/dtext/dtext.c"
4354
4379
  }
4355
4380
 
4356
4381
  if ( ++( sm->p) != ( sm->pe) )
@@ -4672,7 +4697,7 @@ _again:
4672
4697
 
4673
4698
  }
4674
4699
 
4675
- #line 1369 "ext/dtext/dtext.rl"
4700
+ #line 1380 "ext/dtext/dtext.rl"
4676
4701
 
4677
4702
  dstack_close(sm);
4678
4703
 
@@ -4685,11 +4710,13 @@ static VALUE parse(int argc, VALUE * argv, VALUE self) {
4685
4710
  VALUE options;
4686
4711
  VALUE opt_inline;
4687
4712
  VALUE opt_strip;
4713
+ VALUE opt_mentions;
4688
4714
  VALUE ret;
4689
4715
  rb_encoding * encoding = NULL;
4690
4716
  StateMachine * sm = NULL;
4691
4717
  bool f_strip = false;
4692
4718
  bool f_inline = false;
4719
+ bool f_mentions = true;
4693
4720
 
4694
4721
  g_debug("start\n");
4695
4722
 
@@ -4719,10 +4746,15 @@ static VALUE parse(int argc, VALUE * argv, VALUE self) {
4719
4746
  if (RTEST(opt_inline)) {
4720
4747
  f_inline = true;
4721
4748
  }
4749
+
4750
+ opt_mentions = rb_hash_aref(options, ID2SYM(rb_intern("disable_mentions")));
4751
+ if (RTEST(opt_mentions)) {
4752
+ f_mentions = false;
4753
+ }
4722
4754
  }
4723
4755
  }
4724
4756
 
4725
- sm = parse_helper(RSTRING_PTR(input0), RSTRING_LEN(input0), f_strip, f_inline);
4757
+ sm = parse_helper(RSTRING_PTR(input0), RSTRING_LEN(input0), f_strip, f_inline, f_mentions);
4726
4758
 
4727
4759
  encoding = rb_enc_find("utf-8");
4728
4760
  ret = rb_enc_str_new(sm->output->str, sm->output->len, encoding);