Skip to content

Commit

Permalink
Fixed parsing list items that are indented with >= 4 spaces (see also c…
Browse files Browse the repository at this point in the history
  • Loading branch information
Knagis committed Jun 25, 2015
1 parent 9bcb148 commit 8bd1257
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions CommonMark/Parser/BlockMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ public static void IncorporateLine(LineInfo line, ref Block curptr)
if (blank && container.IsLastLineBlank)
BreakOutOfLists(ref container, line);

var maybeLazy = cur.Tag == BlockTag.Paragraph;

// unless last matched container is code block, try new container starts:
while (container.Tag != BlockTag.FencedCode &&
container.Tag != BlockTag.IndentedCode &&
Expand All @@ -566,23 +568,9 @@ public static void IncorporateLine(LineInfo line, ref Block curptr)

indent = first_nonspace - offset;
blank = curChar == '\n';
var indented = indent >= CODE_INDENT;

if (indent >= CODE_INDENT)
{

if (cur.Tag != BlockTag.Paragraph && !blank)
{
offset += CODE_INDENT;
container = CreateChildBlock(container, line, BlockTag.IndentedCode, offset);
}
else
{
// indent > 4 in lazy line
break;
}

}
else if (curChar == '>')
if (!indented && curChar == '>')
{

offset = first_nonspace + 1;
Expand All @@ -593,15 +581,15 @@ public static void IncorporateLine(LineInfo line, ref Block curptr)
container = CreateChildBlock(container, line, BlockTag.BlockQuote, first_nonspace);

}
else if (curChar == '#' && 0 != (matched = Scanner.scan_atx_header_start(ln, first_nonspace, ln.Length, out i)))
else if (!indented && curChar == '#' && 0 != (matched = Scanner.scan_atx_header_start(ln, first_nonspace, ln.Length, out i)))
{

offset = first_nonspace + matched;
container = CreateChildBlock(container, line, BlockTag.AtxHeader, first_nonspace);
container.HeaderLevel = i;

}
else if ((curChar == '`' || curChar == '~') && 0 != (matched = Scanner.scan_open_code_fence(ln, first_nonspace, ln.Length)))
else if (!indented && (curChar == '`' || curChar == '~') && 0 != (matched = Scanner.scan_open_code_fence(ln, first_nonspace, ln.Length)))
{

container = CreateChildBlock(container, line, BlockTag.FencedCode, first_nonspace);
Expand All @@ -613,14 +601,14 @@ public static void IncorporateLine(LineInfo line, ref Block curptr)
offset = first_nonspace + matched;

}
else if (curChar == '<' && Scanner.scan_html_block_tag(ln, first_nonspace, ln.Length))
else if (!indented && curChar == '<' && Scanner.scan_html_block_tag(ln, first_nonspace, ln.Length))
{

container = CreateChildBlock(container, line, BlockTag.HtmlBlock, first_nonspace);
// note, we don't adjust offset because the tag is part of the text

}
else if (container.Tag == BlockTag.Paragraph && (curChar == '=' || curChar == '-')
else if (!indented && container.Tag == BlockTag.Paragraph && (curChar == '=' || curChar == '-')
&& 0 != (matched = Scanner.scan_setext_header_line(ln, first_nonspace, ln.Length))
&& ContainsSingleLine(container.StringContent))
{
Expand All @@ -630,7 +618,9 @@ public static void IncorporateLine(LineInfo line, ref Block curptr)
offset = ln.Length - 1;

}
else if (!(container.Tag == BlockTag.Paragraph && !all_matched) && 0 != (Scanner.scan_hrule(ln, first_nonspace, ln.Length)))
else if (!indented
&& !(container.Tag == BlockTag.Paragraph && !all_matched)
&& 0 != (Scanner.scan_hrule(ln, first_nonspace, ln.Length)))
{

// it's only now that we know the line is not part of a setext header:
Expand All @@ -640,7 +630,8 @@ public static void IncorporateLine(LineInfo line, ref Block curptr)
offset = ln.Length - 1;

}
else if (0 != (matched = ParseListMarker(ln, first_nonspace, out data)))
else if ((!indented || container.Tag == BlockTag.List)
&& 0 != (matched = ParseListMarker(ln, first_nonspace, out data)))
{

// compute padding:
Expand Down Expand Up @@ -677,6 +668,11 @@ public static void IncorporateLine(LineInfo line, ref Block curptr)
container = CreateChildBlock(container, line, BlockTag.ListItem, first_nonspace);
container.ListData = data;
}
else if (indented && !maybeLazy && !blank)
{
offset += CODE_INDENT;
container = CreateChildBlock(container, line, BlockTag.IndentedCode, offset);
}
else
{
break;
Expand All @@ -687,6 +683,8 @@ public static void IncorporateLine(LineInfo line, ref Block curptr)
// if it's a line container, it can't contain other containers
break;
}

maybeLazy = false;
}

// what remains at offset is a text line. add the text to the
Expand Down

0 comments on commit 8bd1257

Please sign in to comment.