summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-06-03 09:49:40 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2015-06-03 09:49:40 +0200
commit9ff1cccc955f108ed76b0039e1ca1b61d44cad56 (patch)
tree7d90ff206d6854c8079e1cb244e77a63513f90cb
parentcc818d27efdf7f1b4a60811c46f813b2a3149041 (diff)
Fixed bug in list item parsing when items indented >= 4 spaces.
Closes #52.
-rw-r--r--src/blocks.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/blocks.c b/src/blocks.c
index a15f819..b006cc1 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -526,6 +526,7 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes)
bool blank = false;
int first_nonspace;
int indent;
+ bool indented;
cmark_chunk input;
bool maybe_lazy;
@@ -657,10 +658,10 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes)
first_nonspace++;
indent = first_nonspace - offset;
+ indented = indent >= CODE_INDENT;
blank = peek_at(&input, first_nonspace) == '\n';
- if (indent >= CODE_INDENT) {
- if (!maybe_lazy && !blank) {
+ if (indented && !maybe_lazy && !blank) {
offset += CODE_INDENT;
container = add_child(parser, container, NODE_CODE_BLOCK, offset + 1);
container->as.code.fenced = false;
@@ -668,11 +669,8 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes)
container->as.code.fence_length = 0;
container->as.code.fence_offset = 0;
container->as.code.info = cmark_chunk_literal("");
- } else { // indent > 4 in lazy line
- break;
- }
- } else if (peek_at(&input, first_nonspace) == '>') {
+ } else if (!indented && peek_at(&input, first_nonspace) == '>') {
offset = first_nonspace + 1;
// optional following character
@@ -680,7 +678,7 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes)
offset++;
container = add_child(parser, container, NODE_BLOCK_QUOTE, offset + 1);
- } else if ((matched = scan_atx_header_start(&input, first_nonspace))) {
+ } else if (!indented && (matched = scan_atx_header_start(&input, first_nonspace))) {
offset = first_nonspace + matched;
container = add_child(parser, container, NODE_HEADER, offset + 1);
@@ -695,7 +693,7 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes)
container->as.header.level = level;
container->as.header.setext = false;
- } else if ((matched = scan_open_code_fence(&input, first_nonspace))) {
+ } else if (!indented && (matched = scan_open_code_fence(&input, first_nonspace))) {
container = add_child(parser, container, NODE_CODE_BLOCK, first_nonspace + 1);
container->as.code.fenced = true;
@@ -705,12 +703,13 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes)
container->as.code.info = cmark_chunk_literal("");
offset = first_nonspace + matched;
- } else if ((matched = scan_html_block_tag(&input, first_nonspace))) {
+ } else if (!indented && (matched = scan_html_block_tag(&input, first_nonspace))) {
container = add_child(parser, container, NODE_HTML, first_nonspace + 1);
// note, we don't adjust offset because the tag is part of the text
- } else if (container->type == NODE_PARAGRAPH &&
+ } else if (!indented &&
+ container->type == NODE_PARAGRAPH &&
(lev = scan_setext_header_line(&input, first_nonspace)) &&
// check that there is only one line in the paragraph:
cmark_strbuf_strrchr(&container->string_content, '\n',
@@ -721,7 +720,9 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes)
container->as.header.setext = true;
offset = input.len - 1;
- } else if (!(container->type == NODE_PARAGRAPH && !all_matched) &&
+ } else if (!indented &&
+ !(container->type == NODE_PARAGRAPH &&
+ !all_matched) &&
(matched = scan_hrule(&input, first_nonspace))) {
// it's only now that we know the line is not part of a setext header: