ext/dtext/dtext.c in dtext_rb-1.0.9 vs ext/dtext/dtext.c in dtext_rb-1.0.10

- old
+ new

@@ -34,10 +34,11 @@ GArray * stack; GQueue * dstack; int list_nest; int d; int b; + int quote; } StateMachine; static const size_t MAX_STACK_DEPTH = 512; static const int BLOCK_P = 1; @@ -68,15 +69,15 @@ static const int BLOCK_H4 = 26; static const int BLOCK_H5 = 27; static const int BLOCK_H6 = 28; -#line 966 "ext/dtext/dtext.rl" +#line 970 "ext/dtext/dtext.rl" -#line 78 "ext/dtext/dtext.c" +#line 79 "ext/dtext/dtext.c" static const unsigned char _dtext_to_state_actions[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -169,11 +170,11 @@ static const int dtext_en_table = 300; static const int dtext_en_list = 302; static const int dtext_en_main = 245; -#line 969 "ext/dtext/dtext.rl" +#line 973 "ext/dtext/dtext.rl" static inline void underscore_string(char * str, size_t len) { for (size_t i=0; i<len; ++i) { if (str[i] == ' ') { str[i] = '_'; @@ -276,11 +277,11 @@ g_free(segment); } static inline void append_block(StateMachine * sm, const char * s) { if (sm->f_inline) { - sm->output = g_string_append_c(sm->output, ' '); + // sm->output = g_string_append_c(sm->output, ' '); } else if (sm->f_strip) { // do nothing } else { sm->output = g_string_append(sm->output, s); } @@ -448,22 +449,22 @@ static bool print_machine(StateMachine * sm) { printf("p=%c\n", *sm->p); return true; } -static void init_machine(StateMachine * sm, VALUE input) { +static void init_machine(StateMachine * sm, const char * src, size_t len) { size_t output_length = 0; - sm->p = RSTRING_PTR(input); + sm->p = src; sm->pb = sm->p; - sm->pe = sm->p + RSTRING_LEN(input); + sm->pe = sm->p + len; sm->eof = sm->pe; sm->ts = NULL; sm->te = NULL; sm->cs = 0; sm->act = 0; sm->top = 0; - output_length = RSTRING_LEN(input); + output_length = len; if (output_length < (INT16_MAX / 2)) { output_length *= 2; } sm->output = g_string_sized_new(output_length); sm->a1 = NULL; @@ -477,86 +478,52 @@ sm->list_nest = 0; sm->list_mode = false; sm->header_mode = false; sm->d = 0; sm->b = 0; + sm->quote = 0; } static void free_machine(StateMachine * sm) { g_string_free(sm->output, TRUE); g_array_free(sm->stack, FALSE); g_queue_free(sm->dstack); g_free(sm); } -static VALUE parse(int argc, VALUE * argv, VALUE self) { - VALUE input; - VALUE input0; - VALUE options; - VALUE opt_inline; - VALUE opt_strip; - VALUE ret; - rb_encoding * encoding = NULL; +static StateMachine * parse_helper(const char * src, size_t len, bool f_strip, bool f_inline) { StateMachine * sm = NULL; + StateMachine * link_content_sm = NULL; - g_debug("start\n"); - - if (argc == 0) { - rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)"); - } - - input = argv[0]; - - if (NIL_P(input)) { - return Qnil; - } - - input0 = rb_str_dup(input); - sm = (StateMachine *)g_malloc0(sizeof(StateMachine)); - input0 = rb_str_cat(input0, "\0", 1); - init_machine(sm, input0); + init_machine(sm, src, len); + sm->f_strip = f_strip; + sm->f_inline = f_inline; - if (argc > 1) { - options = argv[1]; - - if (!NIL_P(options)) { - opt_strip = rb_hash_aref(options, ID2SYM(rb_intern("strip"))); - if (RTEST(opt_strip)) { - sm->f_strip = true; - } - - opt_inline = rb_hash_aref(options, ID2SYM(rb_intern("inline"))); - if (RTEST(opt_inline)) { - sm->f_inline = true; - } - } - } - -#line 537 "ext/dtext/dtext.c" +#line 504 "ext/dtext/dtext.c" { sm->cs = dtext_start; ( sm->top) = 0; ( sm->ts) = 0; ( sm->te) = 0; ( sm->act) = 0; } -#line 1330 "ext/dtext/dtext.rl" +#line 1300 "ext/dtext/dtext.rl" -#line 548 "ext/dtext/dtext.c" +#line 515 "ext/dtext/dtext.c" { if ( ( sm->p) == ( sm->pe) ) goto _test_eof; _resume: switch ( _dtext_from_state_actions[ sm->cs] ) { case 58: #line 1 "NONE" {( sm->ts) = ( sm->p);} break; -#line 558 "ext/dtext/dtext.c" +#line 525 "ext/dtext/dtext.c" } switch ( sm->cs ) { case 245: switch( (*( sm->p)) ) { @@ -2709,49 +2676,49 @@ tr425: sm->cs = 306; goto _again; tr288: sm->cs = 306; goto f3; tr289: sm->cs = 307; goto f3; f6: -#line 96 "ext/dtext/dtext.rl" +#line 97 "ext/dtext/dtext.rl" { sm->a1 = sm->p; } goto _again; f4: -#line 100 "ext/dtext/dtext.rl" +#line 101 "ext/dtext/dtext.rl" { sm->a2 = sm->p; } goto _again; f3: -#line 104 "ext/dtext/dtext.rl" +#line 105 "ext/dtext/dtext.rl" { sm->b1 = sm->p; } goto _again; f36: -#line 108 "ext/dtext/dtext.rl" +#line 109 "ext/dtext/dtext.rl" { sm->b2 = sm->p; } goto _again; f61: #line 1 "NONE" {( sm->te) = ( sm->p)+1;} goto _again; f38: -#line 259 "ext/dtext/dtext.rl" +#line 260 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ append(sm, true, "<a rel=\"nofollow\" href=\"/posts?tags="); append_segment_uri_escaped(sm, sm->a1, sm->a2 - 1); append(sm, true, "\">"); append_segment_html_escaped(sm, sm->a1, sm->a2 - 1); append(sm, true, "</a>"); }} goto _again; f35: -#line 267 "ext/dtext/dtext.rl" +#line 268 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ GString * segment = g_string_new_len(sm->a1, sm->a2 - sm->a1); GString * lowercase_segment = NULL; underscore_string(segment->str, segment->len); @@ -2770,11 +2737,11 @@ g_string_free(lowercase_segment, TRUE); g_string_free(segment, TRUE); }} goto _again; f37: -#line 288 "ext/dtext/dtext.rl" +#line 289 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ GString * segment = g_string_new_len(sm->a1, sm->a2 - sm->a1); GString * lowercase_segment = NULL; underscore_string(segment->str, segment->len); @@ -2793,90 +2760,90 @@ g_string_free(lowercase_segment, TRUE); g_string_free(segment, TRUE); }} goto _again; f26: -#line 402 "ext/dtext/dtext.rl" +#line 406 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_push(sm, &INLINE_B); append(sm, true, "<strong>"); }} goto _again; f17: -#line 407 "ext/dtext/dtext.rl" +#line 411 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ if (dstack_check(sm, INLINE_B)) { dstack_pop(sm); append(sm, true, "</strong>"); } else { append(sm, true, "[/b]"); } }} goto _again; f28: -#line 416 "ext/dtext/dtext.rl" +#line 420 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_push(sm, &INLINE_I); append(sm, true, "<em>"); }} goto _again; f19: -#line 421 "ext/dtext/dtext.rl" +#line 425 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ if (dstack_check(sm, INLINE_I)) { dstack_pop(sm); append(sm, true, "</em>"); } else { append(sm, true, "[/i]"); } }} goto _again; f31: -#line 430 "ext/dtext/dtext.rl" +#line 434 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_push(sm, &INLINE_S); append(sm, true, "<s>"); }} goto _again; f20: -#line 435 "ext/dtext/dtext.rl" +#line 439 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ if (dstack_check(sm, INLINE_S)) { dstack_pop(sm); append(sm, true, "</s>"); } else { append(sm, true, "[/s]"); } }} goto _again; f34: -#line 444 "ext/dtext/dtext.rl" +#line 448 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_push(sm, &INLINE_U); append(sm, true, "<u>"); }} goto _again; f25: -#line 449 "ext/dtext/dtext.rl" +#line 453 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ if (dstack_check(sm, INLINE_U)) { dstack_pop(sm); append(sm, true, "</u>"); } else { append(sm, true, "[/u]"); } }} goto _again; f33: -#line 458 "ext/dtext/dtext.rl" +#line 462 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_push(sm, &INLINE_TN); append(sm, true, "<span class=\"tn\">"); }} goto _again; f24: -#line 463 "ext/dtext/dtext.rl" +#line 467 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_close_before_block(sm); if (dstack_check(sm, BLOCK_TN)) { dstack_pop(sm); @@ -2888,29 +2855,29 @@ append_block(sm, "[/tn]"); } }} goto _again; f30: -#line 485 "ext/dtext/dtext.rl" +#line 489 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ g_debug("inline [quote]"); dstack_close_before_block(sm); {( sm->p) = (( sm->ts))-1;} { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} }} goto _again; f32: -#line 508 "ext/dtext/dtext.rl" +#line 512 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ g_debug("inline [spoiler]"); g_debug(" push <span>"); dstack_push(sm, &INLINE_SPOILER); append(sm, true, "<span class=\"spoiler\">"); }} goto _again; f21: -#line 515 "ext/dtext/dtext.rl" +#line 519 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ g_debug("inline [/spoiler]"); dstack_close_before_block(sm); if (dstack_check(sm, INLINE_SPOILER)) { @@ -2929,20 +2896,20 @@ append_block(sm, "[/spoiler]"); } }} goto _again; f27: -#line 536 "ext/dtext/dtext.rl" +#line 540 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ g_debug("inline [expand]"); dstack_rewind(sm); {( sm->p) = (((sm->p - 7)))-1;} { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} }} goto _again; f18: -#line 543 "ext/dtext/dtext.rl" +#line 547 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_close_before_block(sm); if (dstack_check(sm, BLOCK_EXPAND)) { append_block(sm, "</div></div>"); @@ -2952,11 +2919,11 @@ append_block(sm, "[/expand]"); } }} goto _again; f29: -#line 555 "ext/dtext/dtext.rl" +#line 559 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_push(sm, &INLINE_NODTEXT); { size_t len = sm->stack->len; @@ -2970,11 +2937,11 @@ } {( ((int *)sm->stack->data))[( sm->top)++] = sm->cs; sm->cs = 298; goto _again;}} }} goto _again; f23: -#line 560 "ext/dtext/dtext.rl" +#line 564 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ if (dstack_check(sm, BLOCK_TH)) { dstack_pop(sm); append_block(sm, "</th>"); { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} @@ -2982,11 +2949,11 @@ append_block(sm, "[/th]"); } }} goto _again; f22: -#line 570 "ext/dtext/dtext.rl" +#line 574 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ if (dstack_check(sm, BLOCK_TD)) { dstack_pop(sm); append_block(sm, "</td>"); { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} @@ -2994,28 +2961,28 @@ append_block(sm, "[/td]"); } }} goto _again; f72: -#line 580 "ext/dtext/dtext.rl" +#line 584 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ g_debug("inline 0"); g_debug(" return"); ( sm->p)--; { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} }} goto _again; f71: -#line 616 "ext/dtext/dtext.rl" +#line 620 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ g_debug("inline char: %c", (*( sm->p))); append_c_html_escaped(sm, (*( sm->p))); }} goto _again; f97: -#line 337 "ext/dtext/dtext.rl" +#line 341 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ if (is_boundary_c((*( sm->p)))) { sm->b = true; sm->d = 2; } else { @@ -3033,19 +3000,19 @@ append_c_html_escaped(sm, (*( sm->p))); } }} goto _again; f87: -#line 479 "ext/dtext/dtext.rl" +#line 483 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ dstack_rewind(sm); {( sm->p) = (( sm->a1 - 1))-1;} { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} }} goto _again; f96: -#line 492 "ext/dtext/dtext.rl" +#line 496 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ g_debug("inline [/quote]"); dstack_close_before_block(sm); if (dstack_check(sm, BLOCK_LI)) { @@ -3059,11 +3026,11 @@ append_block(sm, "[/quote]"); } }} goto _again; f75: -#line 588 "ext/dtext/dtext.rl" +#line 592 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ g_debug("inline newline2"); g_debug(" return"); if (sm->list_mode) { @@ -3073,11 +3040,11 @@ {( sm->p) = (( sm->ts))-1;} { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} }} goto _again; f74: -#line 600 "ext/dtext/dtext.rl" +#line 604 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ g_debug("inline newline"); if (sm->header_mode) { sm->header_mode = false; @@ -3087,46 +3054,46 @@ append(sm, true, "<br>"); } }} goto _again; f77: -#line 612 "ext/dtext/dtext.rl" +#line 616 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ append_c(sm, ' '); }} goto _again; f78: -#line 616 "ext/dtext/dtext.rl" +#line 620 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ g_debug("inline char: %c", (*( sm->p))); append_c_html_escaped(sm, (*( sm->p))); }} goto _again; f16: -#line 170 "ext/dtext/dtext.rl" +#line 171 "ext/dtext/dtext.rl" {{( sm->p) = ((( sm->te)))-1;}{ append(sm, true, "<a href=\"/forum_topics/"); append_segment(sm, true, sm->a1, sm->a2 - 1); append(sm, true, "\">"); append(sm, false, "topic #"); append_segment(sm, false, sm->a1, sm->a2 - 1); append(sm, true, "</a>"); }} goto _again; f15: -#line 237 "ext/dtext/dtext.rl" +#line 238 "ext/dtext/dtext.rl" {{( sm->p) = ((( sm->te)))-1;}{ append(sm, true, "<a href=\"http://www.pixiv.net/member_illust.php?mode=medium&illust_id="); append_segment(sm, true, sm->a1, sm->a2 - 1); append(sm, true, "\">"); append(sm, false, "pixiv #"); append_segment(sm, false, sm->a1, sm->a2 - 1); append(sm, true, "</a>"); }} goto _again; f11: -#line 600 "ext/dtext/dtext.rl" +#line 604 "ext/dtext/dtext.rl" {{( sm->p) = ((( sm->te)))-1;}{ g_debug("inline newline"); if (sm->header_mode) { sm->header_mode = false; @@ -3136,11 +3103,11 @@ append(sm, true, "<br>"); } }} goto _again; f12: -#line 616 "ext/dtext/dtext.rl" +#line 620 "ext/dtext/dtext.rl" {{( sm->p) = ((( sm->te)))-1;}{ g_debug("inline char: %c", (*( sm->p))); append_c_html_escaped(sm, (*( sm->p))); }} goto _again; @@ -3202,47 +3169,47 @@ break; } } goto _again; f40: -#line 623 "ext/dtext/dtext.rl" +#line 627 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ if (dstack_check(sm, BLOCK_CODE)) { dstack_rewind(sm); } else { append(sm, true, "[/code]"); } { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} }} goto _again; f99: -#line 632 "ext/dtext/dtext.rl" +#line 636 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ ( sm->p)--; { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} }} goto _again; f98: -#line 637 "ext/dtext/dtext.rl" +#line 641 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ append_c_html_escaped(sm, (*( sm->p))); }} goto _again; f100: -#line 637 "ext/dtext/dtext.rl" +#line 641 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ append_c_html_escaped(sm, (*( sm->p))); }} goto _again; f39: -#line 637 "ext/dtext/dtext.rl" +#line 641 "ext/dtext/dtext.rl" {{( sm->p) = ((( sm->te)))-1;}{ append_c_html_escaped(sm, (*( sm->p))); }} goto _again; f42: -#line 643 "ext/dtext/dtext.rl" +#line 647 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ if (dstack_check(sm, BLOCK_NODTEXT)) { dstack_pop(sm); append_block(sm, "</p>"); { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} @@ -3253,72 +3220,72 @@ append(sm, true, "[/nodtext]"); } }} goto _again; f102: -#line 656 "ext/dtext/dtext.rl" +#line 660 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ ( sm->p)--; { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} }} goto _again; f101: -#line 661 "ext/dtext/dtext.rl" +#line 665 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ append_c_html_escaped(sm, (*( sm->p))); }} goto _again; f103: -#line 661 "ext/dtext/dtext.rl" +#line 665 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ append_c_html_escaped(sm, (*( sm->p))); }} goto _again; f41: -#line 661 "ext/dtext/dtext.rl" +#line 665 "ext/dtext/dtext.rl" {{( sm->p) = ((( sm->te)))-1;}{ append_c_html_escaped(sm, (*( sm->p))); }} goto _again; f51: -#line 667 "ext/dtext/dtext.rl" +#line 671 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_push(sm, &BLOCK_THEAD); append_block(sm, "<thead>"); }} goto _again; f46: -#line 672 "ext/dtext/dtext.rl" +#line 676 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ if (dstack_check(sm, BLOCK_THEAD)) { dstack_pop(sm); append_block(sm, "</thead>"); } else { append(sm, true, "[/thead]"); } }} goto _again; f48: -#line 681 "ext/dtext/dtext.rl" +#line 685 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_push(sm, &BLOCK_TBODY); append_block(sm, "<tbody>"); }} goto _again; f45: -#line 686 "ext/dtext/dtext.rl" +#line 690 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ if (dstack_check(sm, BLOCK_TBODY)) { dstack_pop(sm); append_block(sm, "</tbody>"); } else { append(sm, true, "[/tbody]"); } }} goto _again; f50: -#line 695 "ext/dtext/dtext.rl" +#line 699 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_push(sm, &BLOCK_TH); append_block(sm, "<th>"); { size_t len = sm->stack->len; @@ -3333,29 +3300,29 @@ } {( ((int *)sm->stack->data))[( sm->top)++] = sm->cs; sm->cs = 260; goto _again;}} }} goto _again; f52: -#line 701 "ext/dtext/dtext.rl" +#line 705 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_push(sm, &BLOCK_TR); append_block(sm, "<tr>"); }} goto _again; f47: -#line 706 "ext/dtext/dtext.rl" +#line 710 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ if (dstack_check(sm, BLOCK_TR)) { dstack_pop(sm); append_block(sm, "</tr>"); } else { append(sm, true, "[/tr]"); } }} goto _again; f49: -#line 715 "ext/dtext/dtext.rl" +#line 719 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_push(sm, &BLOCK_TD); append_block(sm, "<td>"); { size_t len = sm->stack->len; @@ -3370,11 +3337,11 @@ } {( ((int *)sm->stack->data))[( sm->top)++] = sm->cs; sm->cs = 260; goto _again;}} }} goto _again; f44: -#line 721 "ext/dtext/dtext.rl" +#line 725 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ if (dstack_check(sm, BLOCK_TABLE)) { dstack_pop(sm); append_block(sm, "</table>"); { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} @@ -3382,54 +3349,54 @@ append(sm, true, "[/table]"); } }} goto _again; f105: -#line 731 "ext/dtext/dtext.rl" +#line 735 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ ( sm->p)--; { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} }} goto _again; f104: -#line 736 "ext/dtext/dtext.rl" +#line 740 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;} goto _again; f106: -#line 736 "ext/dtext/dtext.rl" +#line 740 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;} goto _again; f43: -#line 736 "ext/dtext/dtext.rl" +#line 740 "ext/dtext/dtext.rl" {{( sm->p) = ((( sm->te)))-1;}} goto _again; f108: -#line 779 "ext/dtext/dtext.rl" +#line 783 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_close_list(sm); {( sm->p) = (( sm->ts))-1;} { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} }} goto _again; f107: -#line 787 "ext/dtext/dtext.rl" +#line 791 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_rewind(sm); ( sm->p)--; { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} }} goto _again; f110: -#line 787 "ext/dtext/dtext.rl" +#line 791 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ dstack_rewind(sm); ( sm->p)--; { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} }} goto _again; f55: -#line 787 "ext/dtext/dtext.rl" +#line 791 "ext/dtext/dtext.rl" {{( sm->p) = ((( sm->te)))-1;}{ dstack_rewind(sm); ( sm->p)--; { sm->cs = ( ((int *)sm->stack->data))[--( sm->top)];goto _again;} }} @@ -3449,22 +3416,22 @@ break; } } goto _again; f5: -#line 858 "ext/dtext/dtext.rl" +#line 862 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ g_debug("block [/spoiler]"); dstack_close_before_block(sm); if (dstack_check(sm, BLOCK_SPOILER)) { g_debug(" rewind"); dstack_rewind(sm); } }} goto _again; f7: -#line 905 "ext/dtext/dtext.rl" +#line 909 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_close_before_block(sm); dstack_push(sm, &BLOCK_TABLE); append_block(sm, "<table class=\"striped\">"); { @@ -3480,11 +3447,11 @@ } {( ((int *)sm->stack->data))[( sm->top)++] = sm->cs; sm->cs = 300; goto _again;}} }} goto _again; f8: -#line 912 "ext/dtext/dtext.rl" +#line 916 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ dstack_push(sm, &BLOCK_TN); append_block(sm, "<p class=\"tn\">"); { size_t len = sm->stack->len; @@ -3499,19 +3466,19 @@ } {( ((int *)sm->stack->data))[( sm->top)++] = sm->cs; sm->cs = 260; goto _again;}} }} goto _again; f59: -#line 928 "ext/dtext/dtext.rl" +#line 932 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ g_debug("block 0"); g_debug(" close dstack"); dstack_close(sm); }} goto _again; f58: -#line 951 "ext/dtext/dtext.rl" +#line 955 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ g_debug("block char: %c", (*( sm->p))); ( sm->p)--; if (g_queue_is_empty(sm->dstack) || dstack_check(sm, BLOCK_QUOTE) || dstack_check(sm, BLOCK_SPOILER) || dstack_check(sm, BLOCK_EXPAND)) { @@ -3534,11 +3501,11 @@ } {( ((int *)sm->stack->data))[( sm->top)++] = sm->cs; sm->cs = 260; goto _again;}} }} goto _again; f64: -#line 795 "ext/dtext/dtext.rl" +#line 799 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ char header = *sm->a1; if (sm->f_inline) { header = '6'; @@ -3592,33 +3559,33 @@ } {( ((int *)sm->stack->data))[( sm->top)++] = sm->cs; sm->cs = 260; goto _again;}} }} goto _again; f69: -#line 840 "ext/dtext/dtext.rl" +#line 844 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ g_debug("block [quote]"); g_debug(" push quote"); g_debug(" print <blockquote>"); dstack_close_before_block(sm); dstack_push(sm, &BLOCK_QUOTE); append_block(sm, "<blockquote>"); }} goto _again; f70: -#line 849 "ext/dtext/dtext.rl" +#line 853 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ g_debug("block [spoiler]"); g_debug(" push spoiler"); g_debug(" print <div>"); dstack_close_before_block(sm); dstack_push(sm, &BLOCK_SPOILER); append_block(sm, "<div class=\"spoiler\">"); }} goto _again; f65: -#line 867 "ext/dtext/dtext.rl" +#line 871 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ g_debug("block [code]"); dstack_close_before_block(sm); dstack_push(sm, &BLOCK_CODE); append_block(sm, "<pre>"); @@ -3635,22 +3602,22 @@ } {( ((int *)sm->stack->data))[( sm->top)++] = sm->cs; sm->cs = 296; goto _again;}} }} goto _again; f67: -#line 875 "ext/dtext/dtext.rl" +#line 879 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ g_debug("block [expand]"); dstack_close_before_block(sm); dstack_push(sm, &BLOCK_EXPAND); append_block(sm, "<div class=\"expandable\"><div class=\"expandable-header\">"); append_block(sm, "<input type=\"button\" value=\"Show\" class=\"expandable-button\"/></div>"); append_block(sm, "<div class=\"expandable-content\">"); }} goto _again; f66: -#line 884 "ext/dtext/dtext.rl" +#line 888 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ g_debug("block [expand=]"); dstack_close_before_block(sm); dstack_push(sm, &BLOCK_EXPAND); append_block(sm, "<div class=\"expandable\"><div class=\"expandable-header\">"); @@ -3660,11 +3627,11 @@ append_block(sm, "<input type=\"button\" value=\"Show\" class=\"expandable-button\"/></div>"); append_block(sm, "<div class=\"expandable-content\">"); }} goto _again; f68: -#line 896 "ext/dtext/dtext.rl" +#line 900 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ g_debug("block [nodtext]"); dstack_close_before_block(sm); dstack_push(sm, &BLOCK_NODTEXT); dstack_push(sm, &BLOCK_P); @@ -3682,11 +3649,11 @@ } {( ((int *)sm->stack->data))[( sm->top)++] = sm->cs; sm->cs = 298; goto _again;}} }} goto _again; f62: -#line 951 "ext/dtext/dtext.rl" +#line 955 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ g_debug("block char: %c", (*( sm->p))); ( sm->p)--; if (g_queue_is_empty(sm->dstack) || dstack_check(sm, BLOCK_QUOTE) || dstack_check(sm, BLOCK_SPOILER) || dstack_check(sm, BLOCK_EXPAND)) { @@ -3709,11 +3676,11 @@ } {( ((int *)sm->stack->data))[( sm->top)++] = sm->cs; sm->cs = 260; goto _again;}} }} goto _again; f2: -#line 951 "ext/dtext/dtext.rl" +#line 955 "ext/dtext/dtext.rl" {{( sm->p) = ((( sm->te)))-1;}{ g_debug("block char: %c", (*( sm->p))); ( sm->p)--; if (g_queue_is_empty(sm->dstack) || dstack_check(sm, BLOCK_QUOTE) || dstack_check(sm, BLOCK_SPOILER) || dstack_check(sm, BLOCK_EXPAND)) { @@ -3761,150 +3728,150 @@ break; } } goto _again; f92: -#line 100 "ext/dtext/dtext.rl" +#line 101 "ext/dtext/dtext.rl" { sm->a2 = sm->p; } -#line 152 "ext/dtext/dtext.rl" +#line 153 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ append(sm, true, "<a href=\"/posts/"); append_segment(sm, true, sm->a1, sm->a2 - 1); append(sm, true, "\">"); append(sm, false, "post #"); append_segment(sm, false, sm->a1, sm->a2 - 1); append(sm, true, "</a>"); }} goto _again; f86: -#line 100 "ext/dtext/dtext.rl" +#line 101 "ext/dtext/dtext.rl" { sm->a2 = sm->p; } -#line 161 "ext/dtext/dtext.rl" +#line 162 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ append(sm, true, "<a href=\"/forum_posts/"); append_segment(sm, true, sm->a1, sm->a2 - 1); append(sm, true, "\">"); append(sm, false, "forum #"); append_segment(sm, false, sm->a1, sm->a2 - 1); append(sm, true, "</a>"); }} goto _again; f93: -#line 100 "ext/dtext/dtext.rl" +#line 101 "ext/dtext/dtext.rl" { sm->a2 = sm->p; } -#line 170 "ext/dtext/dtext.rl" +#line 171 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ append(sm, true, "<a href=\"/forum_topics/"); append_segment(sm, true, sm->a1, sm->a2 - 1); append(sm, true, "\">"); append(sm, false, "topic #"); append_segment(sm, false, sm->a1, sm->a2 - 1); append(sm, true, "</a>"); }} goto _again; f85: -#line 100 "ext/dtext/dtext.rl" +#line 101 "ext/dtext/dtext.rl" { sm->a2 = sm->p; } -#line 192 "ext/dtext/dtext.rl" +#line 193 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ append(sm, true, "<a href=\"/comments/"); append_segment(sm, true, sm->a1, sm->a2 - 1); append(sm, true, "\">"); append(sm, false, "comment #"); append_segment(sm, false, sm->a1, sm->a2 - 1); append(sm, true, "</a>"); }} goto _again; f91: -#line 100 "ext/dtext/dtext.rl" +#line 101 "ext/dtext/dtext.rl" { sm->a2 = sm->p; } -#line 201 "ext/dtext/dtext.rl" +#line 202 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ append(sm, true, "<a href=\"/pools/"); append_segment(sm, true, sm->a1, sm->a2 - 1); append(sm, true, "\">"); append(sm, false, "pool #"); append_segment(sm, false, sm->a1, sm->a2 - 1); append(sm, true, "</a>"); }} goto _again; f95: -#line 100 "ext/dtext/dtext.rl" +#line 101 "ext/dtext/dtext.rl" { sm->a2 = sm->p; } -#line 210 "ext/dtext/dtext.rl" +#line 211 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ append(sm, true, "<a href=\"/users/"); append_segment(sm, true, sm->a1, sm->a2 - 1); append(sm, true, "\">"); append(sm, false, "user #"); append_segment(sm, false, sm->a1, sm->a2 - 1); append(sm, true, "</a>"); }} goto _again; f84: -#line 100 "ext/dtext/dtext.rl" +#line 101 "ext/dtext/dtext.rl" { sm->a2 = sm->p; } -#line 219 "ext/dtext/dtext.rl" +#line 220 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ append(sm, true, "<a href=\"/artists/"); append_segment(sm, true, sm->a1, sm->a2 - 1); append(sm, true, "\">"); append(sm, false, "artist #"); append_segment(sm, false, sm->a1, sm->a2 - 1); append(sm, true, "</a>"); }} goto _again; f88: -#line 100 "ext/dtext/dtext.rl" +#line 101 "ext/dtext/dtext.rl" { sm->a2 = sm->p; } -#line 228 "ext/dtext/dtext.rl" +#line 229 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ append(sm, true, "<a href=\"https://github.com/r888888888/danbooru/issues/"); append_segment(sm, true, sm->a1, sm->a2 - 1); append(sm, true, "\">"); append(sm, false, "issue #"); append_segment(sm, false, sm->a1, sm->a2 - 1); append(sm, true, "</a>"); }} goto _again; f89: -#line 100 "ext/dtext/dtext.rl" +#line 101 "ext/dtext/dtext.rl" { sm->a2 = sm->p; } -#line 237 "ext/dtext/dtext.rl" +#line 238 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ append(sm, true, "<a href=\"http://www.pixiv.net/member_illust.php?mode=medium&illust_id="); append_segment(sm, true, sm->a1, sm->a2 - 1); append(sm, true, "\">"); append(sm, false, "pixiv #"); append_segment(sm, false, sm->a1, sm->a2 - 1); append(sm, true, "</a>"); }} goto _again; f80: -#line 100 "ext/dtext/dtext.rl" +#line 101 "ext/dtext/dtext.rl" { sm->a2 = sm->p; } -#line 362 "ext/dtext/dtext.rl" +#line 366 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ if (is_boundary_c((*( sm->p)))) { sm->b = true; sm->d = 2; } else { @@ -3923,11 +3890,11 @@ append_c_html_escaped(sm, (*( sm->p))); } }} goto _again; f83: -#line 100 "ext/dtext/dtext.rl" +#line 101 "ext/dtext/dtext.rl" { sm->a2 = sm->p; } #line 1 "NONE" { switch( ( sm->act) ) { @@ -3986,29 +3953,29 @@ break; } } goto _again; f13: -#line 108 "ext/dtext/dtext.rl" +#line 109 "ext/dtext/dtext.rl" { sm->b2 = sm->p; } -#line 329 "ext/dtext/dtext.rl" +#line 333 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p)+1;{ append(sm, true, "<a href=\""); append_segment_html_escaped(sm, sm->b1, sm->b2 - 1); append(sm, true, "\">"); append_segment_html_escaped(sm, sm->a1, sm->a2 - 1); append(sm, true, "</a>"); }} goto _again; f94: -#line 108 "ext/dtext/dtext.rl" +#line 109 "ext/dtext/dtext.rl" { sm->b2 = sm->p; } -#line 179 "ext/dtext/dtext.rl" +#line 180 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ append(sm, true, "<a href=\"/forum_topics/"); append_segment(sm, true, sm->a1, sm->a2 - 1); append(sm, true, "?page="); append_segment(sm, true, sm->b1, sm->b2 - 1); @@ -4019,15 +3986,15 @@ append_segment(sm, false, sm->b1, sm->b2 - 1); append(sm, true, "</a>"); }} goto _again; f90: -#line 108 "ext/dtext/dtext.rl" +#line 109 "ext/dtext/dtext.rl" { sm->b2 = sm->p; } -#line 246 "ext/dtext/dtext.rl" +#line 247 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ append(sm, true, "<a href=\"http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id="); append_segment(sm, true, sm->a1, sm->a2 - 1); append(sm, true, "&page="); append_segment(sm, true, sm->b1, sm->b2 - 1); @@ -4038,15 +4005,15 @@ append_segment(sm, false, sm->b1, sm->b2 - 1); append(sm, true, "</a>"); }} goto _again; f79: -#line 108 "ext/dtext/dtext.rl" +#line 109 "ext/dtext/dtext.rl" { sm->b2 = sm->p; } -#line 309 "ext/dtext/dtext.rl" +#line 310 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ if (is_boundary_c((*( sm->p)))) { sm->d = 2; sm->b = true; } else { @@ -4055,24 +4022,27 @@ } append(sm, true, "<a href=\""); append_segment_html_escaped(sm, sm->b1, sm->b2 - sm->d); append(sm, true, "\">"); - append_segment_html_escaped(sm, sm->a1, sm->a2 - 1); + link_content_sm = parse_helper(sm->a1, sm->a2 - sm->a1, false, true); + append(sm, true, link_content_sm->output->str); + free_machine(link_content_sm); + link_content_sm = NULL; append(sm, true, "</a>"); if (sm->b) { append_c_html_escaped(sm, (*( sm->p))); } }} goto _again; f76: -#line 108 "ext/dtext/dtext.rl" +#line 109 "ext/dtext/dtext.rl" { sm->b2 = sm->p; } -#line 383 "ext/dtext/dtext.rl" +#line 387 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ g_debug("inline list"); if (dstack_check(sm, BLOCK_LI)) { g_debug(" rewind li"); @@ -4089,15 +4059,15 @@ {( sm->p) = (( sm->ts + 1))-1;} sm->cs = 302; }} goto _again; f111: -#line 108 "ext/dtext/dtext.rl" +#line 109 "ext/dtext/dtext.rl" { sm->b2 = sm->p; } -#line 740 "ext/dtext/dtext.rl" +#line 744 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ int prev_nest = sm->list_nest; append_closing_p_if(sm); g_debug("list start"); sm->list_mode = true; @@ -4144,15 +4114,15 @@ } {( ((int *)sm->stack->data))[( sm->top)++] = sm->cs; sm->cs = 260; goto _again;}} }} goto _again; f63: -#line 108 "ext/dtext/dtext.rl" +#line 109 "ext/dtext/dtext.rl" { sm->b2 = sm->p; } -#line 918 "ext/dtext/dtext.rl" +#line 922 "ext/dtext/dtext.rl" {( sm->te) = ( sm->p);( sm->p)--;{ g_debug("block list"); g_debug(" call list"); sm->list_nest = 0; sm->list_mode = true; @@ -4173,71 +4143,71 @@ }} goto _again; f14: #line 1 "NONE" {( sm->te) = ( sm->p)+1;} -#line 96 "ext/dtext/dtext.rl" +#line 97 "ext/dtext/dtext.rl" { sm->a1 = sm->p; } goto _again; f82: #line 1 "NONE" {( sm->te) = ( sm->p)+1;} -#line 358 "ext/dtext/dtext.rl" +#line 362 "ext/dtext/dtext.rl" {( sm->act) = 18;} goto _again; f81: #line 1 "NONE" {( sm->te) = ( sm->p)+1;} -#line 362 "ext/dtext/dtext.rl" +#line 366 "ext/dtext/dtext.rl" {( sm->act) = 19;} goto _again; f10: #line 1 "NONE" {( sm->te) = ( sm->p)+1;} -#line 588 "ext/dtext/dtext.rl" +#line 592 "ext/dtext/dtext.rl" {( sm->act) = 42;} goto _again; f73: #line 1 "NONE" {( sm->te) = ( sm->p)+1;} -#line 600 "ext/dtext/dtext.rl" +#line 604 "ext/dtext/dtext.rl" {( sm->act) = 43;} goto _again; f54: #line 1 "NONE" {( sm->te) = ( sm->p)+1;} -#line 779 "ext/dtext/dtext.rl" +#line 783 "ext/dtext/dtext.rl" {( sm->act) = 64;} goto _again; f109: #line 1 "NONE" {( sm->te) = ( sm->p)+1;} -#line 785 "ext/dtext/dtext.rl" +#line 789 "ext/dtext/dtext.rl" {( sm->act) = 65;} goto _again; f1: #line 1 "NONE" {( sm->te) = ( sm->p)+1;} -#line 934 "ext/dtext/dtext.rl" +#line 938 "ext/dtext/dtext.rl" {( sm->act) = 79;} goto _again; f60: #line 1 "NONE" {( sm->te) = ( sm->p)+1;} -#line 947 "ext/dtext/dtext.rl" +#line 951 "ext/dtext/dtext.rl" {( sm->act) = 80;} goto _again; _again: switch ( _dtext_to_state_actions[ sm->cs] ) { case 57: #line 1 "NONE" {( sm->ts) = 0;} break; -#line 4239 "ext/dtext/dtext.c" +#line 4209 "ext/dtext/dtext.c" } if ( ++( sm->p) != ( sm->pe) ) goto _resume; _test_eof: {} @@ -4549,12 +4519,60 @@ } } } -#line 1331 "ext/dtext/dtext.rl" +#line 1301 "ext/dtext/dtext.rl" dstack_close(sm); + + return sm; +} + +static VALUE parse(int argc, VALUE * argv, VALUE self) { + VALUE input; + VALUE input0; + VALUE options; + VALUE opt_inline; + VALUE opt_strip; + VALUE ret; + rb_encoding * encoding = NULL; + StateMachine * sm = NULL; + bool f_strip = false; + bool f_inline = false; + + g_debug("start\n"); + + if (argc == 0) { + rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)"); + } + + input = argv[0]; + + if (NIL_P(input)) { + return Qnil; + } + + input0 = rb_str_dup(input); + input0 = rb_str_cat(input0, "\0", 1); + + if (argc > 1) { + options = argv[1]; + + if (!NIL_P(options)) { + opt_strip = rb_hash_aref(options, ID2SYM(rb_intern("strip"))); + if (RTEST(opt_strip)) { + f_strip = true; + } + + opt_inline = rb_hash_aref(options, ID2SYM(rb_intern("inline"))); + if (RTEST(opt_inline)) { + f_inline = true; + } + } + } + + sm = parse_helper(RSTRING_PTR(input0), RSTRING_LEN(input0), f_strip, f_inline); encoding = rb_enc_find("utf-8"); ret = rb_enc_str_new(sm->output->str, sm->output->len, encoding); free_machine(sm);