Extend e7f856d to handle nested shorthand
authorWincent Colaiuta <win@wincent.com>
Fri, 27 Mar 2009 12:57:54 +0000 (13:57 +0100)
committerWincent Colaiuta <win@wincent.com>
Fri, 27 Mar 2009 12:57:54 +0000 (13:57 +0100)
The fix in e7f856d handles non-nested ">" BLOCKQUOTE
shorthand. In this commit we extend the fix to also
cope with nested shortand (">>", ">>>" etc).

Signed-off-by: Wincent Colaiuta <win@wincent.com>
ext/parser.c
spec/regressions_spec.rb

index 240f7a4..2a2a40d 100644 (file)
@@ -466,6 +466,12 @@ void _Wikitext_pop_from_stack_up_to(parser_t *parser, VALUE target, int item, VA
     } while (continue_looping);
 }
 
+void _Wikitext_pop_all_from_stack(parser_t *parser, VALUE target)
+{
+    while (!NO_ITEM(ary_entry(parser->scope, -1)))
+        _Wikitext_pop_from_stack(parser, target);
+}
+
 void _Wikitext_start_para_if_necessary(parser_t *parser)
 {
     if (!NIL_P(parser->capture))    // we don't do anything if in capturing mode
@@ -1133,7 +1139,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
                     {
                         _Wikitext_rollback_failed_link(parser);             // if any
                         _Wikitext_rollback_failed_external_link(parser);    // if any
-                        _Wikitext_pop_from_stack_up_to(parser, Qnil, BLOCKQUOTE, Qtrue);
+                        _Wikitext_pop_all_from_stack(parser, Qnil);
                         _Wikitext_indent(parser);
                         rb_str_cat(parser->output, pre_start, sizeof(pre_start) - 1);
                         ary_push(parser->scope, PRE_START);
@@ -1256,7 +1262,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
                     {
                         _Wikitext_rollback_failed_link(parser);             // if any
                         _Wikitext_rollback_failed_external_link(parser);    // if any
-                        _Wikitext_pop_from_stack_up_to(parser, Qnil, BLOCKQUOTE, Qtrue);
+                        _Wikitext_pop_all_from_stack(parser, Qnil);
                         _Wikitext_indent(parser);
                         rb_str_cat(parser->output, blockquote_start, sizeof(blockquote_start) - 1);
                         rb_str_cat(parser->output, parser->line_ending->ptr, parser->line_ending->len);
index 2f08bea..578de70 100755 (executable)
@@ -795,4 +795,44 @@ describe Wikitext::Parser, 'regressions' do
     END
     @parser.parse(input).should == expected
   end
+
+  # https://wincent.com/issues/818
+  it 'should handle BLOCKQUOTE_START blocks which follow nested BLOCKQUOTE shorthand' do
+    input = dedent <<-END
+      >>> foo
+      <blockquote>bar</blockquote>
+    END
+    expected = dedent <<-END
+      <blockquote>
+        <blockquote>
+          <blockquote>
+            <p>foo</p>
+          </blockquote>
+        </blockquote>
+      </blockquote>
+      <blockquote>
+        <p>bar</p>
+      </blockquote>
+    END
+    @parser.parse(input).should == expected
+  end
+
+  # https://wincent.com/issues/818
+  it 'should handle PRE_START blocks which follow nested BLOCKQUOTE shorthand' do
+    input = dedent <<-END
+      >>> foo
+      <pre>bar</pre>
+    END
+    expected = dedent <<-END
+      <blockquote>
+        <blockquote>
+          <blockquote>
+            <p>foo</p>
+          </blockquote>
+        </blockquote>
+      </blockquote>
+      <pre>bar</pre>
+    END
+    @parser.parse(input).should == expected
+  end
 end