diff options
author | John MacFarlane <jgm@berkeley.edu> | 2016-02-05 22:57:48 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2016-02-05 22:57:48 -0800 |
commit | bc0b49fd61d8628d114d94f348ba925d58c41048 (patch) | |
tree | fcb593c0f6a002d40254e4cc71e3870839e0600f /src | |
parent | c351c72220406d3e934049808ecd09e599487a85 (diff) |
Properly handle partially consumed tab.
E.g. in
```
- foo
<TAB><TAB>bar
```
we should consume two spaces from the second tab,
including two spaces in the code block.
Diffstat (limited to 'src')
-rw-r--r-- | src/blocks.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/blocks.c b/src/blocks.c index 424257c..30e5be6 100644 --- a/src/blocks.c +++ b/src/blocks.c @@ -125,8 +125,19 @@ 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) { +static void add_line(cmark_node *node, cmark_chunk *ch, bufsize_t offset, + cmark_parser *parser) { + int chars_to_tab; + int i; assert(node->open); + if (parser->partially_consumed_tab) { + 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); } @@ -922,7 +933,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); + add_line(parser->current, &input, parser->offset, parser); } else { // not a lazy continuation @@ -934,11 +945,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); + add_line(container, &input, parser->offset, parser); } else if (container->type == CMARK_NODE_HTML_BLOCK) { - add_line(container, &input, parser->offset); + add_line(container, &input, parser->offset, parser); int matches_end_condition; switch (container->as.html_block_type) { @@ -987,13 +998,13 @@ 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); + add_line(container, &input, parser->first_nonspace, 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); + add_line(container, &input, parser->first_nonspace, parser); } parser->current = container; |