cmark

My personal build of CMark ✏️

Commit
d7ffa6074d88564016de59a37b3e26627545f0ea
Parent
bc0b49fd61d8628d114d94f348ba925d58c41048
Author
John MacFarlane <jgm@berkeley.edu>
Date

Simplified add_line (only need parser parameter).

Diffstat

1 file changed, 12 insertions, 9 deletions

Status File Name N° Changes Insertions Deletions
Modified src/blocks.c 21 12 9
diff --git a/src/blocks.c b/src/blocks.c
@@ -125,20 +125,21 @@ static inline bool accepts_lines(cmark_node_type block_type) {
           block_type == CMARK_NODE_CODE_BLOCK);
 }
 
-static void add_line(cmark_node *node, cmark_chunk *ch, bufsize_t offset,
-		cmark_parser *parser) {
+static void add_line(cmark_node *node, cmark_chunk *ch, cmark_parser *parser) {
   int chars_to_tab;
   int i;
   assert(node->open);
   if (parser->partially_consumed_tab) {
-    offset += 1; // skip over tab
+    parser->offset += 1; // skip over tab
     // add space characters:
     chars_to_tab = TAB_STOP - (parser->column % TAB_STOP);
     for (i = 0; i < chars_to_tab; i++) {
       cmark_strbuf_putc(&node->string_content, ' ');
     }
   }
-  cmark_strbuf_put(&node->string_content, ch->data + offset, ch->len - offset);
+  cmark_strbuf_put(&node->string_content,
+		  ch->data + parser->offset,
+		  ch->len - parser->offset);
 }
 
 static void remove_trailing_blank_lines(cmark_strbuf *ln) {
@@ -933,7 +934,7 @@ static void S_process_line(cmark_parser *parser, const unsigned char *buffer,
       parser->current->type == CMARK_NODE_PARAGRAPH &&
       cmark_strbuf_len(&parser->current->string_content) > 0) {
 
-    add_line(parser->current, &input, parser->offset, parser);
+    add_line(parser->current, &input, parser);
 
   } else { // not a lazy continuation
 
@@ -945,11 +946,11 @@ static void S_process_line(cmark_parser *parser, const unsigned char *buffer,
 
     if (container->type == CMARK_NODE_CODE_BLOCK) {
 
-      add_line(container, &input, parser->offset, parser);
+      add_line(container, &input, parser);
 
     } else if (container->type == CMARK_NODE_HTML_BLOCK) {
 
-      add_line(container, &input, parser->offset, parser);
+      add_line(container, &input, parser);
 
       int matches_end_condition;
       switch (container->as.html_block_type) {
@@ -998,13 +999,15 @@ static void S_process_line(cmark_parser *parser, const unsigned char *buffer,
           container->as.heading.setext == false) {
         chop_trailing_hashtags(&input);
       }
-      add_line(container, &input, parser->first_nonspace, parser);
+      S_advance_offset(parser, &input, parser->first_nonspace - parser->offset, false);
+      add_line(container, &input, parser);
 
     } else {
       // create paragraph container for line
       container = add_child(parser, container, CMARK_NODE_PARAGRAPH,
                             parser->first_nonspace + 1);
-      add_line(container, &input, parser->first_nonspace, parser);
+      S_advance_offset(parser, &input, parser->first_nonspace - parser->offset, false);
+      add_line(container, &input, parser);
     }
 
     parser->current = container;