wikitext 1.5.1 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/parser.c +59 -18
- data/ext/wikitext_ragel.c +42 -39
- data/lib/wikitext/version.rb +1 -1
- data/rails/init.rb +8 -4
- data/spec/autolinking_spec.rb +24 -12
- data/spec/external_link_spec.rb +6 -3
- data/spec/regressions_spec.rb +72 -0
- metadata +2 -2
data/ext/parser.c
CHANGED
@@ -31,6 +31,7 @@ typedef struct
|
|
31
31
|
VALUE link_target; // short term "memory" for parsing links
|
32
32
|
VALUE link_text; // short term "memory" for parsing links
|
33
33
|
VALUE external_link_class; // CSS class applied to external links
|
34
|
+
VALUE mailto_class; // CSS class applied to email (mailto) links
|
34
35
|
VALUE img_prefix; // path prepended when emitting img tags
|
35
36
|
ary_t *scope; // stack for tracking scope
|
36
37
|
ary_t *line; // stack for tracking scope as implied by current line
|
@@ -220,12 +221,20 @@ VALUE _Wikitext_downcase(VALUE string)
|
|
220
221
|
return string;
|
221
222
|
}
|
222
223
|
|
223
|
-
VALUE _Wikitext_hyperlink(VALUE link_prefix, VALUE link_target, VALUE link_text, VALUE link_class)
|
224
|
+
VALUE _Wikitext_hyperlink(parser_t *parser, VALUE link_prefix, VALUE link_target, VALUE link_text, VALUE link_class)
|
224
225
|
{
|
225
226
|
VALUE string = rb_str_new(a_start, sizeof(a_start) - 1); // <a href="
|
226
227
|
if (!NIL_P(link_prefix))
|
227
228
|
rb_str_append(string, link_prefix);
|
228
229
|
rb_str_append(string, link_target);
|
230
|
+
|
231
|
+
/* special handling for mailto URIs */
|
232
|
+
const char *mailto = "mailto:";
|
233
|
+
if (NIL_P(link_prefix) &&
|
234
|
+
RSTRING_LEN(link_target) >= (long)sizeof(mailto) &&
|
235
|
+
strncmp(mailto, RSTRING_PTR(link_target), sizeof(mailto)) == 0)
|
236
|
+
link_class = parser->mailto_class; // use mailto_class from parser
|
237
|
+
|
229
238
|
if (link_class != Qnil)
|
230
239
|
{
|
231
240
|
rb_str_cat(string, a_class, sizeof(a_class) - 1); // " class="
|
@@ -457,6 +466,12 @@ void _Wikitext_pop_from_stack_up_to(parser_t *parser, VALUE target, int item, VA
|
|
457
466
|
} while (continue_looping);
|
458
467
|
}
|
459
468
|
|
469
|
+
void _Wikitext_pop_all_from_stack(parser_t *parser, VALUE target)
|
470
|
+
{
|
471
|
+
while (!NO_ITEM(ary_entry(parser->scope, -1)))
|
472
|
+
_Wikitext_pop_from_stack(parser, target);
|
473
|
+
}
|
474
|
+
|
460
475
|
void _Wikitext_start_para_if_necessary(parser_t *parser)
|
461
476
|
{
|
462
477
|
if (!NIL_P(parser->capture)) // we don't do anything if in capturing mode
|
@@ -864,7 +879,7 @@ void _Wikitext_rollback_failed_external_link(parser_t *parser)
|
|
864
879
|
if (!NIL_P(parser->link_target))
|
865
880
|
{
|
866
881
|
if (parser->autolink == Qtrue)
|
867
|
-
parser->link_target = _Wikitext_hyperlink(Qnil, parser->link_target, parser->link_target, parser->external_link_class);
|
882
|
+
parser->link_target = _Wikitext_hyperlink(parser, Qnil, parser->link_target, parser->link_target, parser->external_link_class);
|
868
883
|
rb_str_append(parser->output, parser->link_target);
|
869
884
|
if (scope_includes_space)
|
870
885
|
{
|
@@ -989,6 +1004,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
|
|
989
1004
|
parser->link_target = Qnil;
|
990
1005
|
parser->link_text = Qnil;
|
991
1006
|
parser->external_link_class = link_class;
|
1007
|
+
parser->mailto_class = mailto_class;
|
992
1008
|
parser->img_prefix = rb_iv_get(self, "@img_prefix");
|
993
1009
|
parser->scope = ary_new();
|
994
1010
|
GC_WRAP_ARY(parser->scope, scope_gc);
|
@@ -1119,11 +1135,23 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
|
|
1119
1135
|
}
|
1120
1136
|
else if (IN(BLOCKQUOTE))
|
1121
1137
|
{
|
1122
|
-
//
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1138
|
+
if (token->column_start == 1) // only allowed in first column
|
1139
|
+
{
|
1140
|
+
_Wikitext_rollback_failed_link(parser); // if any
|
1141
|
+
_Wikitext_rollback_failed_external_link(parser); // if any
|
1142
|
+
_Wikitext_pop_all_from_stack(parser, Qnil);
|
1143
|
+
_Wikitext_indent(parser);
|
1144
|
+
rb_str_cat(parser->output, pre_start, sizeof(pre_start) - 1);
|
1145
|
+
ary_push(parser->scope, PRE_START);
|
1146
|
+
ary_push(parser->line, PRE_START);
|
1147
|
+
}
|
1148
|
+
else // PRE_START illegal here
|
1149
|
+
{
|
1150
|
+
i = NIL_P(parser->capture) ? parser->output : parser->capture;
|
1151
|
+
_Wikitext_pop_excess_elements(parser);
|
1152
|
+
_Wikitext_start_para_if_necessary(parser);
|
1153
|
+
rb_str_cat(i, escaped_pre_start, sizeof(escaped_pre_start) - 1);
|
1154
|
+
}
|
1127
1155
|
}
|
1128
1156
|
else
|
1129
1157
|
{
|
@@ -1230,11 +1258,24 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
|
|
1230
1258
|
}
|
1231
1259
|
else if (IN(BLOCKQUOTE))
|
1232
1260
|
{
|
1233
|
-
//
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1261
|
+
if (token->column_start == 1) // only allowed in first column
|
1262
|
+
{
|
1263
|
+
_Wikitext_rollback_failed_link(parser); // if any
|
1264
|
+
_Wikitext_rollback_failed_external_link(parser); // if any
|
1265
|
+
_Wikitext_pop_all_from_stack(parser, Qnil);
|
1266
|
+
_Wikitext_indent(parser);
|
1267
|
+
rb_str_cat(parser->output, blockquote_start, sizeof(blockquote_start) - 1);
|
1268
|
+
rb_str_cat(parser->output, parser->line_ending->ptr, parser->line_ending->len);
|
1269
|
+
ary_push(parser->scope, BLOCKQUOTE_START);
|
1270
|
+
ary_push(parser->line, BLOCKQUOTE_START);
|
1271
|
+
}
|
1272
|
+
else // BLOCKQUOTE_START illegal here
|
1273
|
+
{
|
1274
|
+
i = NIL_P(parser->capture) ? parser->output : parser->capture;
|
1275
|
+
_Wikitext_pop_excess_elements(parser);
|
1276
|
+
_Wikitext_start_para_if_necessary(parser);
|
1277
|
+
rb_str_cat(i, escaped_blockquote_start, sizeof(escaped_blockquote_start) - 1);
|
1278
|
+
}
|
1238
1279
|
}
|
1239
1280
|
else
|
1240
1281
|
{
|
@@ -1884,7 +1925,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
|
|
1884
1925
|
_Wikitext_start_para_if_necessary(parser);
|
1885
1926
|
i = TOKEN_TEXT(token);
|
1886
1927
|
if (parser->autolink == Qtrue)
|
1887
|
-
i = _Wikitext_hyperlink(rb_str_new2("mailto:"), i, i, mailto_class);
|
1928
|
+
i = _Wikitext_hyperlink(parser, rb_str_new2("mailto:"), i, i, mailto_class);
|
1888
1929
|
rb_str_append(parser->output, i);
|
1889
1930
|
}
|
1890
1931
|
break;
|
@@ -1900,7 +1941,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
|
|
1900
1941
|
_Wikitext_rollback_failed_link(parser);
|
1901
1942
|
i = TOKEN_TEXT(token);
|
1902
1943
|
if (parser->autolink == Qtrue)
|
1903
|
-
i = _Wikitext_hyperlink(Qnil, i, i, parser->external_link_class); // link target, link text
|
1944
|
+
i = _Wikitext_hyperlink(parser, Qnil, i, i, parser->external_link_class); // link target, link text
|
1904
1945
|
rb_str_append(parser->output, i);
|
1905
1946
|
}
|
1906
1947
|
else if (IN(EXT_LINK_START))
|
@@ -1926,7 +1967,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
|
|
1926
1967
|
_Wikitext_start_para_if_necessary(parser);
|
1927
1968
|
rb_str_cat(parser->output, ext_link_start, sizeof(ext_link_start) - 1);
|
1928
1969
|
if (parser->autolink == Qtrue)
|
1929
|
-
i = _Wikitext_hyperlink(Qnil, i, i, parser->external_link_class); // link target, link text
|
1970
|
+
i = _Wikitext_hyperlink(parser, Qnil, i, i, parser->external_link_class); // link target, link text
|
1930
1971
|
rb_str_append(parser->output, i);
|
1931
1972
|
}
|
1932
1973
|
}
|
@@ -1947,7 +1988,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
|
|
1947
1988
|
_Wikitext_start_para_if_necessary(parser);
|
1948
1989
|
i = TOKEN_TEXT(token);
|
1949
1990
|
if (parser->autolink == Qtrue)
|
1950
|
-
i = _Wikitext_hyperlink(Qnil, i, i, parser->external_link_class); // link target, link text
|
1991
|
+
i = _Wikitext_hyperlink(parser, Qnil, i, i, parser->external_link_class); // link target, link text
|
1951
1992
|
rb_str_append(parser->output, i);
|
1952
1993
|
}
|
1953
1994
|
break;
|
@@ -2125,7 +2166,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
|
|
2125
2166
|
_Wikitext_parser_encode_link_target(parser);
|
2126
2167
|
_Wikitext_pop_from_stack_up_to(parser, i, LINK_START, Qtrue);
|
2127
2168
|
parser->capture = Qnil;
|
2128
|
-
i = _Wikitext_hyperlink(prefix, parser->link_target, parser->link_text, Qnil);
|
2169
|
+
i = _Wikitext_hyperlink(parser, prefix, parser->link_target, parser->link_text, Qnil);
|
2129
2170
|
rb_str_append(parser->output, i);
|
2130
2171
|
parser->link_target = Qnil;
|
2131
2172
|
parser->link_text = Qnil;
|
@@ -2209,7 +2250,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
|
|
2209
2250
|
j = IN(PATH) ? Qnil : parser->external_link_class;
|
2210
2251
|
_Wikitext_pop_from_stack_up_to(parser, i, EXT_LINK_START, Qtrue);
|
2211
2252
|
parser->capture = Qnil;
|
2212
|
-
i = _Wikitext_hyperlink(Qnil, parser->link_target, parser->link_text, j);
|
2253
|
+
i = _Wikitext_hyperlink(parser, Qnil, parser->link_target, parser->link_text, j);
|
2213
2254
|
rb_str_append(parser->output, i);
|
2214
2255
|
}
|
2215
2256
|
parser->link_target = Qnil;
|
data/ext/wikitext_ragel.c
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
#line 1 "wikitext_ragel.rl"
|
2
3
|
// Copyright 2008-2009 Wincent Colaiuta
|
3
4
|
// This program is free software: you can redistribute it and/or modify
|
@@ -31,13 +32,14 @@
|
|
31
32
|
#define NEXT_CHAR() (*(p + 1))
|
32
33
|
|
33
34
|
|
34
|
-
#line
|
35
|
+
#line 36 "wikitext_ragel.c"
|
35
36
|
static const int wikitext_start = 94;
|
36
37
|
static const int wikitext_first_final = 94;
|
37
38
|
static const int wikitext_error = 0;
|
38
39
|
|
39
40
|
static const int wikitext_en_main = 94;
|
40
41
|
|
42
|
+
|
41
43
|
#line 468 "wikitext_ragel.rl"
|
42
44
|
|
43
45
|
|
@@ -81,16 +83,17 @@ void next_token(token_t *out, token_t *last_token, char *p, char *pe)
|
|
81
83
|
char *te; // token end (scanner)
|
82
84
|
int act; // identity of last patterned matched (scanner)
|
83
85
|
|
84
|
-
#line
|
86
|
+
#line 87 "wikitext_ragel.c"
|
85
87
|
{
|
86
88
|
cs = wikitext_start;
|
87
89
|
ts = 0;
|
88
90
|
te = 0;
|
89
91
|
act = 0;
|
90
92
|
}
|
93
|
+
|
91
94
|
#line 510 "wikitext_ragel.rl"
|
92
95
|
|
93
|
-
#line
|
96
|
+
#line 97 "wikitext_ragel.c"
|
94
97
|
{
|
95
98
|
if ( p == pe )
|
96
99
|
goto _test_eof;
|
@@ -213,7 +216,6 @@ tr23:
|
|
213
216
|
{p++; cs = 94; goto _out;}
|
214
217
|
}
|
215
218
|
break;
|
216
|
-
default: break;
|
217
219
|
}
|
218
220
|
}
|
219
221
|
goto st94;
|
@@ -665,7 +667,7 @@ st94:
|
|
665
667
|
case 94:
|
666
668
|
#line 1 "wikitext_ragel.rl"
|
667
669
|
{ts = p;}
|
668
|
-
#line
|
670
|
+
#line 671 "wikitext_ragel.c"
|
669
671
|
switch( (*p) ) {
|
670
672
|
case 10: goto tr111;
|
671
673
|
case 13: goto tr112;
|
@@ -786,7 +788,7 @@ st95:
|
|
786
788
|
if ( ++p == pe )
|
787
789
|
goto _test_eof95;
|
788
790
|
case 95:
|
789
|
-
#line
|
791
|
+
#line 792 "wikitext_ragel.c"
|
790
792
|
if ( (*p) == 10 )
|
791
793
|
goto tr139;
|
792
794
|
goto tr138;
|
@@ -800,7 +802,7 @@ st96:
|
|
800
802
|
if ( ++p == pe )
|
801
803
|
goto _test_eof96;
|
802
804
|
case 96:
|
803
|
-
#line
|
805
|
+
#line 806 "wikitext_ragel.c"
|
804
806
|
if ( (*p) == 32 )
|
805
807
|
goto st96;
|
806
808
|
goto tr140;
|
@@ -846,7 +848,7 @@ st99:
|
|
846
848
|
if ( ++p == pe )
|
847
849
|
goto _test_eof99;
|
848
850
|
case 99:
|
849
|
-
#line
|
851
|
+
#line 852 "wikitext_ragel.c"
|
850
852
|
switch( (*p) ) {
|
851
853
|
case 35: goto st7;
|
852
854
|
case 97: goto st13;
|
@@ -1083,7 +1085,7 @@ st104:
|
|
1083
1085
|
if ( ++p == pe )
|
1084
1086
|
goto _test_eof104;
|
1085
1087
|
case 104:
|
1086
|
-
#line
|
1088
|
+
#line 1089 "wikitext_ragel.c"
|
1087
1089
|
switch( (*p) ) {
|
1088
1090
|
case 43: goto st98;
|
1089
1091
|
case 45: goto tr121;
|
@@ -1192,7 +1194,7 @@ st105:
|
|
1192
1194
|
if ( ++p == pe )
|
1193
1195
|
goto _test_eof105;
|
1194
1196
|
case 105:
|
1195
|
-
#line
|
1197
|
+
#line 1198 "wikitext_ragel.c"
|
1196
1198
|
if ( (*p) == 46 )
|
1197
1199
|
goto st23;
|
1198
1200
|
if ( (*p) < 65 ) {
|
@@ -1214,7 +1216,7 @@ st106:
|
|
1214
1216
|
if ( ++p == pe )
|
1215
1217
|
goto _test_eof106;
|
1216
1218
|
case 106:
|
1217
|
-
#line
|
1219
|
+
#line 1220 "wikitext_ragel.c"
|
1218
1220
|
if ( (*p) == 46 )
|
1219
1221
|
goto st23;
|
1220
1222
|
if ( (*p) < 65 ) {
|
@@ -1236,7 +1238,7 @@ st107:
|
|
1236
1238
|
if ( ++p == pe )
|
1237
1239
|
goto _test_eof107;
|
1238
1240
|
case 107:
|
1239
|
-
#line
|
1241
|
+
#line 1242 "wikitext_ragel.c"
|
1240
1242
|
if ( (*p) == 46 )
|
1241
1243
|
goto st23;
|
1242
1244
|
if ( (*p) < 65 ) {
|
@@ -1258,7 +1260,7 @@ st108:
|
|
1258
1260
|
if ( ++p == pe )
|
1259
1261
|
goto _test_eof108;
|
1260
1262
|
case 108:
|
1261
|
-
#line
|
1263
|
+
#line 1264 "wikitext_ragel.c"
|
1262
1264
|
if ( (*p) == 46 )
|
1263
1265
|
goto st23;
|
1264
1266
|
if ( (*p) < 65 ) {
|
@@ -1280,7 +1282,7 @@ st109:
|
|
1280
1282
|
if ( ++p == pe )
|
1281
1283
|
goto _test_eof109;
|
1282
1284
|
case 109:
|
1283
|
-
#line
|
1285
|
+
#line 1286 "wikitext_ragel.c"
|
1284
1286
|
switch( (*p) ) {
|
1285
1287
|
case 43: goto st98;
|
1286
1288
|
case 45: goto st98;
|
@@ -1314,7 +1316,7 @@ st110:
|
|
1314
1316
|
if ( ++p == pe )
|
1315
1317
|
goto _test_eof110;
|
1316
1318
|
case 110:
|
1317
|
-
#line
|
1319
|
+
#line 1320 "wikitext_ragel.c"
|
1318
1320
|
switch( (*p) ) {
|
1319
1321
|
case 33: goto st97;
|
1320
1322
|
case 44: goto st97;
|
@@ -1436,7 +1438,7 @@ st115:
|
|
1436
1438
|
if ( ++p == pe )
|
1437
1439
|
goto _test_eof115;
|
1438
1440
|
case 115:
|
1439
|
-
#line
|
1441
|
+
#line 1442 "wikitext_ragel.c"
|
1440
1442
|
switch( (*p) ) {
|
1441
1443
|
case 64: goto st21;
|
1442
1444
|
case 95: goto st20;
|
@@ -1461,7 +1463,7 @@ st116:
|
|
1461
1463
|
if ( ++p == pe )
|
1462
1464
|
goto _test_eof116;
|
1463
1465
|
case 116:
|
1464
|
-
#line
|
1466
|
+
#line 1467 "wikitext_ragel.c"
|
1465
1467
|
switch( (*p) ) {
|
1466
1468
|
case 47: goto st25;
|
1467
1469
|
case 66: goto st55;
|
@@ -2005,7 +2007,7 @@ st117:
|
|
2005
2007
|
if ( ++p == pe )
|
2006
2008
|
goto _test_eof117;
|
2007
2009
|
case 117:
|
2008
|
-
#line
|
2010
|
+
#line 2011 "wikitext_ragel.c"
|
2009
2011
|
switch( (*p) ) {
|
2010
2012
|
case 32: goto st118;
|
2011
2013
|
case 61: goto tr126;
|
@@ -2028,7 +2030,7 @@ st119:
|
|
2028
2030
|
if ( ++p == pe )
|
2029
2031
|
goto _test_eof119;
|
2030
2032
|
case 119:
|
2031
|
-
#line
|
2033
|
+
#line 2034 "wikitext_ragel.c"
|
2032
2034
|
if ( (*p) == 32 )
|
2033
2035
|
goto tr174;
|
2034
2036
|
goto tr173;
|
@@ -2042,7 +2044,7 @@ st120:
|
|
2042
2044
|
if ( ++p == pe )
|
2043
2045
|
goto _test_eof120;
|
2044
2046
|
case 120:
|
2045
|
-
#line
|
2047
|
+
#line 2048 "wikitext_ragel.c"
|
2046
2048
|
switch( (*p) ) {
|
2047
2049
|
case 64: goto st21;
|
2048
2050
|
case 84: goto tr175;
|
@@ -2071,7 +2073,7 @@ st121:
|
|
2071
2073
|
if ( ++p == pe )
|
2072
2074
|
goto _test_eof121;
|
2073
2075
|
case 121:
|
2074
|
-
#line
|
2076
|
+
#line 2077 "wikitext_ragel.c"
|
2075
2077
|
switch( (*p) ) {
|
2076
2078
|
case 64: goto st21;
|
2077
2079
|
case 80: goto tr176;
|
@@ -2100,7 +2102,7 @@ st122:
|
|
2100
2102
|
if ( ++p == pe )
|
2101
2103
|
goto _test_eof122;
|
2102
2104
|
case 122:
|
2103
|
-
#line
|
2105
|
+
#line 2106 "wikitext_ragel.c"
|
2104
2106
|
switch( (*p) ) {
|
2105
2107
|
case 58: goto st84;
|
2106
2108
|
case 64: goto st21;
|
@@ -2165,7 +2167,7 @@ st123:
|
|
2165
2167
|
if ( ++p == pe )
|
2166
2168
|
goto _test_eof123;
|
2167
2169
|
case 123:
|
2168
|
-
#line
|
2170
|
+
#line 2171 "wikitext_ragel.c"
|
2169
2171
|
switch( (*p) ) {
|
2170
2172
|
case 33: goto st87;
|
2171
2173
|
case 41: goto st87;
|
@@ -2224,7 +2226,7 @@ st124:
|
|
2224
2226
|
if ( ++p == pe )
|
2225
2227
|
goto _test_eof124;
|
2226
2228
|
case 124:
|
2227
|
-
#line
|
2229
|
+
#line 2230 "wikitext_ragel.c"
|
2228
2230
|
switch( (*p) ) {
|
2229
2231
|
case 64: goto st21;
|
2230
2232
|
case 84: goto tr179;
|
@@ -2253,7 +2255,7 @@ st125:
|
|
2253
2255
|
if ( ++p == pe )
|
2254
2256
|
goto _test_eof125;
|
2255
2257
|
case 125:
|
2256
|
-
#line
|
2258
|
+
#line 2259 "wikitext_ragel.c"
|
2257
2259
|
switch( (*p) ) {
|
2258
2260
|
case 64: goto st21;
|
2259
2261
|
case 84: goto tr180;
|
@@ -2282,7 +2284,7 @@ st126:
|
|
2282
2284
|
if ( ++p == pe )
|
2283
2285
|
goto _test_eof126;
|
2284
2286
|
case 126:
|
2285
|
-
#line
|
2287
|
+
#line 2288 "wikitext_ragel.c"
|
2286
2288
|
switch( (*p) ) {
|
2287
2289
|
case 64: goto st21;
|
2288
2290
|
case 80: goto tr181;
|
@@ -2311,7 +2313,7 @@ st127:
|
|
2311
2313
|
if ( ++p == pe )
|
2312
2314
|
goto _test_eof127;
|
2313
2315
|
case 127:
|
2314
|
-
#line
|
2316
|
+
#line 2317 "wikitext_ragel.c"
|
2315
2317
|
switch( (*p) ) {
|
2316
2318
|
case 58: goto st84;
|
2317
2319
|
case 64: goto st21;
|
@@ -2341,7 +2343,7 @@ st128:
|
|
2341
2343
|
if ( ++p == pe )
|
2342
2344
|
goto _test_eof128;
|
2343
2345
|
case 128:
|
2344
|
-
#line
|
2346
|
+
#line 2347 "wikitext_ragel.c"
|
2345
2347
|
switch( (*p) ) {
|
2346
2348
|
case 64: goto st21;
|
2347
2349
|
case 65: goto tr182;
|
@@ -2370,7 +2372,7 @@ st129:
|
|
2370
2372
|
if ( ++p == pe )
|
2371
2373
|
goto _test_eof129;
|
2372
2374
|
case 129:
|
2373
|
-
#line
|
2375
|
+
#line 2376 "wikitext_ragel.c"
|
2374
2376
|
switch( (*p) ) {
|
2375
2377
|
case 64: goto st21;
|
2376
2378
|
case 73: goto tr183;
|
@@ -2399,7 +2401,7 @@ st130:
|
|
2399
2401
|
if ( ++p == pe )
|
2400
2402
|
goto _test_eof130;
|
2401
2403
|
case 130:
|
2402
|
-
#line
|
2404
|
+
#line 2405 "wikitext_ragel.c"
|
2403
2405
|
switch( (*p) ) {
|
2404
2406
|
case 64: goto st21;
|
2405
2407
|
case 76: goto tr184;
|
@@ -2428,7 +2430,7 @@ st131:
|
|
2428
2430
|
if ( ++p == pe )
|
2429
2431
|
goto _test_eof131;
|
2430
2432
|
case 131:
|
2431
|
-
#line
|
2433
|
+
#line 2434 "wikitext_ragel.c"
|
2432
2434
|
switch( (*p) ) {
|
2433
2435
|
case 64: goto st21;
|
2434
2436
|
case 84: goto tr185;
|
@@ -2457,7 +2459,7 @@ st132:
|
|
2457
2459
|
if ( ++p == pe )
|
2458
2460
|
goto _test_eof132;
|
2459
2461
|
case 132:
|
2460
|
-
#line
|
2462
|
+
#line 2463 "wikitext_ragel.c"
|
2461
2463
|
switch( (*p) ) {
|
2462
2464
|
case 64: goto st21;
|
2463
2465
|
case 79: goto tr186;
|
@@ -2486,7 +2488,7 @@ st133:
|
|
2486
2488
|
if ( ++p == pe )
|
2487
2489
|
goto _test_eof133;
|
2488
2490
|
case 133:
|
2489
|
-
#line
|
2491
|
+
#line 2492 "wikitext_ragel.c"
|
2490
2492
|
switch( (*p) ) {
|
2491
2493
|
case 58: goto st88;
|
2492
2494
|
case 64: goto st21;
|
@@ -2608,7 +2610,7 @@ st134:
|
|
2608
2610
|
if ( ++p == pe )
|
2609
2611
|
goto _test_eof134;
|
2610
2612
|
case 134:
|
2611
|
-
#line
|
2613
|
+
#line 2614 "wikitext_ragel.c"
|
2612
2614
|
if ( (*p) == 46 )
|
2613
2615
|
goto st92;
|
2614
2616
|
if ( (*p) < 65 ) {
|
@@ -2630,7 +2632,7 @@ st135:
|
|
2630
2632
|
if ( ++p == pe )
|
2631
2633
|
goto _test_eof135;
|
2632
2634
|
case 135:
|
2633
|
-
#line
|
2635
|
+
#line 2636 "wikitext_ragel.c"
|
2634
2636
|
if ( (*p) == 46 )
|
2635
2637
|
goto st92;
|
2636
2638
|
if ( (*p) < 65 ) {
|
@@ -2652,7 +2654,7 @@ st136:
|
|
2652
2654
|
if ( ++p == pe )
|
2653
2655
|
goto _test_eof136;
|
2654
2656
|
case 136:
|
2655
|
-
#line
|
2657
|
+
#line 2658 "wikitext_ragel.c"
|
2656
2658
|
if ( (*p) == 46 )
|
2657
2659
|
goto st92;
|
2658
2660
|
if ( (*p) < 65 ) {
|
@@ -2674,7 +2676,7 @@ st137:
|
|
2674
2676
|
if ( ++p == pe )
|
2675
2677
|
goto _test_eof137;
|
2676
2678
|
case 137:
|
2677
|
-
#line
|
2679
|
+
#line 2680 "wikitext_ragel.c"
|
2678
2680
|
if ( (*p) == 46 )
|
2679
2681
|
goto st92;
|
2680
2682
|
if ( (*p) < 65 ) {
|
@@ -2696,7 +2698,7 @@ st138:
|
|
2696
2698
|
if ( ++p == pe )
|
2697
2699
|
goto _test_eof138;
|
2698
2700
|
case 138:
|
2699
|
-
#line
|
2701
|
+
#line 2702 "wikitext_ragel.c"
|
2700
2702
|
switch( (*p) ) {
|
2701
2703
|
case 64: goto st21;
|
2702
2704
|
case 86: goto tr191;
|
@@ -2725,7 +2727,7 @@ st139:
|
|
2725
2727
|
if ( ++p == pe )
|
2726
2728
|
goto _test_eof139;
|
2727
2729
|
case 139:
|
2728
|
-
#line
|
2730
|
+
#line 2731 "wikitext_ragel.c"
|
2729
2731
|
switch( (*p) ) {
|
2730
2732
|
case 64: goto st21;
|
2731
2733
|
case 78: goto tr176;
|
@@ -3062,6 +3064,7 @@ case 143:
|
|
3062
3064
|
|
3063
3065
|
_out: {}
|
3064
3066
|
}
|
3067
|
+
|
3065
3068
|
#line 511 "wikitext_ragel.rl"
|
3066
3069
|
if (cs == wikitext_error)
|
3067
3070
|
rb_raise(eWikitextParserError, "failed before finding a token");
|
data/lib/wikitext/version.rb
CHANGED
data/rails/init.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright 2008 Wincent Colaiuta
|
1
|
+
# Copyright 2008-2009 Wincent Colaiuta
|
2
2
|
# This program is free software: you can redistribute it and/or modify
|
3
3
|
# it under the terms of the GNU General Public License as published by
|
4
4
|
# the Free Software Foundation, either version 3 of the License, or
|
@@ -12,6 +12,10 @@
|
|
12
12
|
# You should have received a copy of the GNU General Public License
|
13
13
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
# Avoid Rails bug #2266 by not requiring during "rake gems:build"
|
16
|
+
# See: https://rails.lighthouseapp.com/projects/8994/tickets/2266
|
17
|
+
unless $gems_build_rake_task
|
18
|
+
require 'wikitext/nil_class'
|
19
|
+
require 'wikitext/string'
|
20
|
+
require 'wikitext/rails'
|
21
|
+
end
|
data/spec/autolinking_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# Copyright 2007-
|
2
|
+
# Copyright 2007-2009 Wincent Colaiuta
|
3
3
|
# This program is free software: you can redistribute it and/or modify
|
4
4
|
# it under the terms of the GNU General Public License as published by
|
5
5
|
# the Free Software Foundation, either version 3 of the License, or
|
@@ -43,7 +43,7 @@ describe Wikitext::Parser, 'autolinking' do
|
|
43
43
|
|
44
44
|
it 'should convert mailto URIs into hyperlinks' do
|
45
45
|
uri = 'mailto:user@example.com'
|
46
|
-
@parser.parse(uri).should == %Q{<p><a href="mailto:user@example.com" class="
|
46
|
+
@parser.parse(uri).should == %Q{<p><a href="mailto:user@example.com" class="mailto">mailto:user@example.com</a></p>\n}
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'should convert SVN URIs into hyperlinks' do
|
@@ -81,18 +81,30 @@ describe Wikitext::Parser, 'autolinking' do
|
|
81
81
|
@parser.parse(uri).should == %Q{<p><a href="mailto:user@example.com" class="mailto">user@example.com</a></p>\n}
|
82
82
|
end
|
83
83
|
|
84
|
-
it 'should apply the mailto CSS class if set' do
|
84
|
+
it 'should apply the mailto CSS class if set (raw address)' do
|
85
85
|
uri = 'user@example.com'
|
86
86
|
@parser.mailto_class = 'foo'
|
87
87
|
@parser.parse(uri).should == %Q{<p><a href="mailto:user@example.com" class="foo">user@example.com</a></p>\n}
|
88
88
|
end
|
89
89
|
|
90
|
-
it 'should apply
|
90
|
+
it 'should apply the mailto CSS class if set (mailto URI)' do
|
91
|
+
uri = 'mailto:user@example.com'
|
92
|
+
@parser.mailto_class = 'foo'
|
93
|
+
@parser.parse(uri).should == %Q{<p><a href="mailto:user@example.com" class="foo">mailto:user@example.com</a></p>\n}
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should apply no CSS if the mailto class is set to nil (raw address)' do
|
91
97
|
uri = 'user@example.com'
|
92
98
|
@parser.mailto_class = nil
|
93
99
|
@parser.parse(uri).should == %Q{<p><a href="mailto:user@example.com">user@example.com</a></p>\n}
|
94
100
|
end
|
95
101
|
|
102
|
+
it 'should apply no CSS if the mailto class is set to nil (mailto URI)' do
|
103
|
+
uri = 'mailto:user@example.com'
|
104
|
+
@parser.mailto_class = nil
|
105
|
+
@parser.parse(uri).should == %Q{<p><a href="mailto:user@example.com">mailto:user@example.com</a></p>\n}
|
106
|
+
end
|
107
|
+
|
96
108
|
it 'should pass through emails unchanged inside <nowiki></nowiki> spans' do
|
97
109
|
@parser.parse("<nowiki>user@example.com</nowiki>").should == "<p>user@example.com</p>\n" # was a crasher
|
98
110
|
end
|
@@ -476,37 +488,37 @@ describe Wikitext::Parser, 'autolinking' do
|
|
476
488
|
describe 'after "mailto:" URIs' do
|
477
489
|
it 'should terminate if followed by a period' do
|
478
490
|
input = 'Try mailto:user@example.com.'
|
479
|
-
expected = %Q{<p>Try <a href="mailto:user@example.com" class="
|
491
|
+
expected = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">mailto:user@example.com</a>.</p>\n}
|
480
492
|
@parser.parse(input).should == expected
|
481
493
|
end
|
482
494
|
|
483
495
|
it 'should not terminate on periods that occur within the URI' do
|
484
496
|
input = 'Try mailto:user.name@example.com.'
|
485
|
-
expected = %Q{<p>Try <a href="mailto:user.name@example.com" class="
|
497
|
+
expected = %Q{<p>Try <a href="mailto:user.name@example.com" class="mailto">mailto:user.name@example.com</a>.</p>\n}
|
486
498
|
@parser.parse(input).should == expected
|
487
499
|
end
|
488
500
|
|
489
501
|
it 'should terminate if followed by a colon' do
|
490
502
|
input = 'Try mailto:user@example.com:'
|
491
|
-
expected = %Q{<p>Try <a href="mailto:user@example.com" class="
|
503
|
+
expected = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">mailto:user@example.com</a>:</p>\n}
|
492
504
|
@parser.parse(input).should == expected
|
493
505
|
end
|
494
506
|
|
495
507
|
it 'should terminate if followed by a comma' do
|
496
508
|
input = 'Try mailto:user@example.com,'
|
497
|
-
expected = %Q{<p>Try <a href="mailto:user@example.com" class="
|
509
|
+
expected = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">mailto:user@example.com</a>,</p>\n}
|
498
510
|
@parser.parse(input).should == expected
|
499
511
|
end
|
500
512
|
|
501
513
|
it 'should terminate if followed by an exclamation mark' do
|
502
514
|
input = 'Try mailto:user@example.com!'
|
503
|
-
expected = %Q{<p>Try <a href="mailto:user@example.com" class="
|
515
|
+
expected = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">mailto:user@example.com</a>!</p>\n}
|
504
516
|
@parser.parse(input).should == expected
|
505
517
|
end
|
506
518
|
|
507
519
|
it 'should terminate if followed by a question mark' do
|
508
520
|
input = 'Try mailto:user@example.com?'
|
509
|
-
expected = %Q{<p>Try <a href="mailto:user@example.com" class="
|
521
|
+
expected = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">mailto:user@example.com</a>?</p>\n}
|
510
522
|
@parser.parse(input).should == expected
|
511
523
|
end
|
512
524
|
|
@@ -520,13 +532,13 @@ describe Wikitext::Parser, 'autolinking' do
|
|
520
532
|
|
521
533
|
it 'should terminate if followed by a semi-colon' do
|
522
534
|
input = 'Try mailto:user@example.com;'
|
523
|
-
expected = %Q{<p>Try <a href="mailto:user@example.com" class="
|
535
|
+
expected = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">mailto:user@example.com</a>;</p>\n}
|
524
536
|
@parser.parse(input).should == expected
|
525
537
|
end
|
526
538
|
|
527
539
|
it 'should terminate if followed by a right parenthesis' do
|
528
540
|
input = '(Try mailto:user@example.com)'
|
529
|
-
expected = %Q{<p>(Try <a href="mailto:user@example.com" class="
|
541
|
+
expected = %Q{<p>(Try <a href="mailto:user@example.com" class="mailto">mailto:user@example.com</a>)</p>\n}
|
530
542
|
@parser.parse(input).should == expected
|
531
543
|
end
|
532
544
|
end
|
data/spec/external_link_spec.rb
CHANGED
@@ -43,12 +43,15 @@ describe Wikitext::Parser, 'external links' do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'should format valid external mailto links' do
|
46
|
-
|
47
|
-
# this is because we're matching this as a (generic) URI rather than an email address
|
48
|
-
expected = %Q{<p><a href="mailto:user@example.com" class="external">john</a></p>\n}
|
46
|
+
expected = %Q{<p><a href="mailto:user@example.com" class="mailto">john</a></p>\n}
|
49
47
|
@parser.parse('[mailto:user@example.com john]').should == expected
|
50
48
|
end
|
51
49
|
|
50
|
+
it 'should not treat raw email addresses as valid link targets' do
|
51
|
+
expected = %Q{<p>[<a href="mailto:user@example.com" class="mailto">user@example.com</a> john]</p>\n}
|
52
|
+
@parser.parse('[user@example.com john]').should == expected
|
53
|
+
end
|
54
|
+
|
52
55
|
it 'should format absolute path links' do
|
53
56
|
expected = %Q{<p><a href="/foo/bar">fb</a></p>\n} # note no "external" class
|
54
57
|
@parser.parse('[/foo/bar fb]').should == expected
|
data/spec/regressions_spec.rb
CHANGED
@@ -763,4 +763,76 @@ describe Wikitext::Parser, 'regressions' do
|
|
763
763
|
END
|
764
764
|
@parser.parse(input).should == expected
|
765
765
|
end
|
766
|
+
|
767
|
+
# https://wincent.com/issues/818
|
768
|
+
it 'should handle BLOCKQUOTE_START blocks which follow BLOCKQUOTE shorthand' do
|
769
|
+
input = dedent <<-END
|
770
|
+
> foo
|
771
|
+
<blockquote>bar</blockquote>
|
772
|
+
END
|
773
|
+
expected = dedent <<-END
|
774
|
+
<blockquote>
|
775
|
+
<p>foo</p>
|
776
|
+
</blockquote>
|
777
|
+
<blockquote>
|
778
|
+
<p>bar</p>
|
779
|
+
</blockquote>
|
780
|
+
END
|
781
|
+
@parser.parse(input).should == expected
|
782
|
+
end
|
783
|
+
|
784
|
+
# https://wincent.com/issues/818
|
785
|
+
it 'should handle PRE_START blocks which follow BLOCKQUOTE shorthand' do
|
786
|
+
input = dedent <<-END
|
787
|
+
> foo
|
788
|
+
<pre>bar</pre>
|
789
|
+
END
|
790
|
+
expected = dedent <<-END
|
791
|
+
<blockquote>
|
792
|
+
<p>foo</p>
|
793
|
+
</blockquote>
|
794
|
+
<pre>bar</pre>
|
795
|
+
END
|
796
|
+
@parser.parse(input).should == expected
|
797
|
+
end
|
798
|
+
|
799
|
+
# https://wincent.com/issues/818
|
800
|
+
it 'should handle BLOCKQUOTE_START blocks which follow nested BLOCKQUOTE shorthand' do
|
801
|
+
input = dedent <<-END
|
802
|
+
>>> foo
|
803
|
+
<blockquote>bar</blockquote>
|
804
|
+
END
|
805
|
+
expected = dedent <<-END
|
806
|
+
<blockquote>
|
807
|
+
<blockquote>
|
808
|
+
<blockquote>
|
809
|
+
<p>foo</p>
|
810
|
+
</blockquote>
|
811
|
+
</blockquote>
|
812
|
+
</blockquote>
|
813
|
+
<blockquote>
|
814
|
+
<p>bar</p>
|
815
|
+
</blockquote>
|
816
|
+
END
|
817
|
+
@parser.parse(input).should == expected
|
818
|
+
end
|
819
|
+
|
820
|
+
# https://wincent.com/issues/818
|
821
|
+
it 'should handle PRE_START blocks which follow nested BLOCKQUOTE shorthand' do
|
822
|
+
input = dedent <<-END
|
823
|
+
>>> foo
|
824
|
+
<pre>bar</pre>
|
825
|
+
END
|
826
|
+
expected = dedent <<-END
|
827
|
+
<blockquote>
|
828
|
+
<blockquote>
|
829
|
+
<blockquote>
|
830
|
+
<p>foo</p>
|
831
|
+
</blockquote>
|
832
|
+
</blockquote>
|
833
|
+
</blockquote>
|
834
|
+
<pre>bar</pre>
|
835
|
+
END
|
836
|
+
@parser.parse(input).should == expected
|
837
|
+
end
|
766
838
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wikitext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wincent Colaiuta
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-27 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|