]> git.wincent.com - wikitext.git/commitdiff
Extract repeated pattern into wiki_append_pre_start()
authorWincent Colaiuta <win@wincent.com>
Tue, 26 May 2009 19:30:22 +0000 (21:30 +0200)
committerWincent Colaiuta <win@wincent.com>
Tue, 26 May 2009 19:30:22 +0000 (21:30 +0200)
This refactoring will make it easier to add code to handle CSS classes
in PRE_START tags (for syntax highlighting).

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

index e7f272715451d3e339c71ad259f58d3055693b03..dd15e7af31c2402b34e3aba979bd29c471311cf5 100644 (file)
@@ -338,6 +338,14 @@ void wiki_indent(parser_t *parser)
     parser->current_indent += 2;
 }
 
+void wiki_append_pre_start(parser_t *parser, token_t *token)
+{
+    wiki_indent(parser);
+    str_append(parser->output, pre_start, sizeof(pre_start) - 1);
+    ary_push(parser->scope, PRE_START);
+    ary_push(parser->line, PRE_START);
+}
+
 void wiki_dedent(parser_t *parser, bool emit)
 {
     if (parser->base_indent == -1) // indentation disabled
@@ -1185,10 +1193,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
                 {
                     wiki_rollback_failed_link(parser); // if any
                     wiki_pop_from_stack_up_to(parser, NULL, BLOCKQUOTE_START, false);
-                    wiki_indent(parser);
-                    str_append(parser->output, pre_start, sizeof(pre_start) - 1);
-                    ary_push(parser->scope, PRE_START);
-                    ary_push(parser->line, PRE_START);
+                    wiki_append_pre_start(parser, token);
                 }
                 else if (IN(BLOCKQUOTE))
                 {
@@ -1196,10 +1201,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
                     {
                         wiki_rollback_failed_link(parser); // if any
                         wiki_pop_all_from_stack(parser);
-                        wiki_indent(parser);
-                        str_append(parser->output, pre_start, sizeof(pre_start) - 1);
-                        ary_push(parser->scope, PRE_START);
-                        ary_push(parser->line, PRE_START);
+                        wiki_append_pre_start(parser, token);
                     }
                     else // PRE_START illegal here
                     {
@@ -1213,10 +1215,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
                 {
                     wiki_rollback_failed_link(parser); // if any
                     wiki_pop_from_stack_up_to(parser, NULL, P, true);
-                    wiki_indent(parser);
-                    str_append(parser->output, pre_start, sizeof(pre_start) - 1);
-                    ary_push(parser->scope, PRE_START);
-                    ary_push(parser->line, PRE_START);
+                    wiki_append_pre_start(parser, token);
                 }
                 break;