private BlockState TryParseSetexHeading(BlockProcessor state, Block block) { var paragraph = (ParagraphBlock)block; var headingChar = (char)0; bool checkForSpaces = false; var line = state.Line; var c = line.CurrentChar; while (c != '\0') { if (headingChar == 0) { if (c == '=' || c == '-') { headingChar = c; continue; } break; } if (checkForSpaces) { if (!c.IsSpaceOrTab()) { headingChar = (char)0; break; } } else if (c != headingChar) { if (c.IsSpaceOrTab()) { checkForSpaces = true; } else { headingChar = (char)0; break; } } c = line.NextChar(); } if (headingChar != 0) { // We dicard the paragraph that will be transformed to a heading state.Discard(paragraph); // If we matched a LinkReferenceDefinition before matching the heading, and the remaining // lines are empty, we can early exit and remove the paragraph if (!(TryMatchLinkReferenceDefinition(ref paragraph.Lines, state) && paragraph.Lines.Count == 0)) { var level = headingChar == '=' ? 1 : 2; var heading = new HeadingBlock(this) { Column = paragraph.Column, Span = new SourceSpan(paragraph.Span.Start, line.Start), Level = level, Lines = paragraph.Lines, }; heading.Lines.Trim(); // Remove the paragraph as a pending block state.NewBlocks.Push(heading); } return(BlockState.BreakDiscard); } block.Span.End = state.Line.End; return(BlockState.Continue); }