md_analyze_line: Fix prioritization of "brother" list item detection.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
diff --git a/md4c/md4c.c b/md4c/md4c.c
index 7119abf..41e006c 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -4722,9 +4722,6 @@ md_is_container_mark(MD_CTX* ctx, unsigned indent, OFF beg, OFF* p_end, MD_CONTA
OFF off = beg;
OFF max_end;
- if(indent >= ctx->code_indent_offset)
- return FALSE;
-
/* Check for block quote mark. */
if(off < ctx->size && CH(off) == _T('>')) {
off++;
@@ -4923,18 +4920,6 @@ redo:
ctx->last_line_has_list_loosening_effect = FALSE;
}
- /* Check for indented code.
- * Note indented code block cannot interrupt paragraph. */
- if(line->indent >= ctx->code_indent_offset &&
- (pivot_line->type == MD_LINE_BLANK || pivot_line->type == MD_LINE_INDENTEDCODE))
- {
- line->type = MD_LINE_INDENTEDCODE;
- MD_ASSERT(line->indent >= ctx->code_indent_offset);
- line->indent -= ctx->code_indent_offset;
- line->data = 0;
- goto done;
- }
-
/* Check whether we are Setext underline. */
if(line->indent < ctx->code_indent_offset && pivot_line->type == MD_LINE_TEXT
&& (CH(off) == _T('=') || CH(off) == _T('-'))
@@ -4965,8 +4950,58 @@ redo:
}
}
+ /* Check for "brother" container. I.e. whether we are another list item
+ * in already started list. */
+ if(n_parents < ctx->n_containers && n_brothers + n_children == 0) {
+ OFF tmp;
+
+ if(md_is_container_mark(ctx, line->indent, off, &tmp, &container) &&
+ md_is_container_compatible(&ctx->containers[n_parents], &container))
+ {
+ pivot_line = &md_dummy_blank_line;
+
+ off = tmp;
+
+ total_indent += container.contents_indent - container.mark_indent;
+ line->indent = md_line_indentation(ctx, total_indent, off, &off);
+ total_indent += line->indent;
+ line->beg = off;
+
+ /* Some of the following whitespace actually still belongs to the mark. */
+ if(off >= ctx->size || ISNEWLINE(off)) {
+ container.contents_indent++;
+ } else if(line->indent <= ctx->code_indent_offset) {
+ container.contents_indent += line->indent;
+ line->indent = 0;
+ } else {
+ container.contents_indent += 1;
+ line->indent--;
+ }
+
+ ctx->containers[n_parents].mark_indent = container.mark_indent;
+ ctx->containers[n_parents].contents_indent = container.contents_indent;
+
+ n_brothers++;
+ goto redo;
+ }
+ }
+
+ /* Check for indented code.
+ * Note indented code block cannot interrupt paragraph. */
+ if(line->indent >= ctx->code_indent_offset &&
+ (pivot_line->type == MD_LINE_BLANK || pivot_line->type == MD_LINE_INDENTEDCODE))
+ {
+ line->type = MD_LINE_INDENTEDCODE;
+ MD_ASSERT(line->indent >= ctx->code_indent_offset);
+ line->indent -= ctx->code_indent_offset;
+ line->data = 0;
+ goto done;
+ }
+
/* Check for start of a new container block. */
- if(md_is_container_mark(ctx, line->indent, off, &off, &container)) {
+ if(line->indent < ctx->code_indent_offset &&
+ md_is_container_mark(ctx, line->indent, off, &off, &container))
+ {
total_indent += container.contents_indent - container.mark_indent;
line->indent = md_line_indentation(ctx, total_indent, off, &off);
@@ -4994,17 +5029,9 @@ redo:
line->indent--;
}
- if(n_brothers + n_children == 0) {
+ if(n_brothers + n_children == 0)
pivot_line = &md_dummy_blank_line;
- if(n_parents < ctx->n_containers && md_is_container_compatible(&ctx->containers[n_parents], &container)) {
- ctx->containers[n_parents].mark_indent = container.mark_indent;
- ctx->containers[n_parents].contents_indent = container.contents_indent;
- n_brothers++;
- goto redo;
- }
- }
-
if(n_children == 0)
MD_CHECK(md_leave_child_containers(ctx, n_parents + n_brothers));