fix newlines and list blocks

This commit is contained in:
Ruud Poutsma
2020-09-27 13:16:53 +02:00
parent fa1c117011
commit 68d12d0212
3 changed files with 51 additions and 48 deletions

View File

@@ -131,7 +131,9 @@ namespace Markdig.Parsers
if (!(state.NextContinue is ListBlock))
{
list.CountAllBlankLines++;
listItem.Add(new BlankLineBlock());
//listItem.Add(new BlankLineBlock());
//state.BeforeLines ??= new List<StringSlice>();
//state.BeforeLines.Add(state.Line);
}
list.CountBlankLinesReset++;
}
@@ -312,48 +314,49 @@ namespace Markdig.Parsers
public override bool Close(BlockProcessor processor, Block blockToClose)
{
// Process only if we have blank lines
if (blockToClose is ListBlock listBlock && listBlock.CountAllBlankLines > 0)
{
if (listBlock.Parent is ListItemBlock parentListItemBlock &&
listBlock.LastChild is ListItemBlock lastListItem &&
lastListItem.LastChild is BlankLineBlock)
{
// Inform the outer list that we have a blank line
var parentList = (ListBlock)parentListItemBlock.Parent;
parentList.CountAllBlankLines++;
parentListItemBlock.Add(new BlankLineBlock());
}
for (int listIndex = listBlock.Count - 1; listIndex >= 0; listIndex--)
{
var listItem = (ListItemBlock)listBlock[listIndex];
for (int i = listItem.Count - 1; i >= 0; i--)
{
if (listItem[i] is BlankLineBlock)
{
if (i == listItem.Count - 1 ? listIndex < listBlock.Count - 1 : i > 0)
{
listBlock.IsLoose = true;
}
listItem.RemoveAt(i);
// If we have removed all blank lines, we can exit
listBlock.CountAllBlankLines--;
if (listBlock.CountAllBlankLines == 0)
{
goto done;
}
}
}
}
}
done:
return true;
// // Process only if we have blank lines
// if (blockToClose is ListBlock listBlock && listBlock.CountAllBlankLines > 0)
// {
// if (listBlock.Parent is ListItemBlock parentListItemBlock &&
// listBlock.LastChild is ListItemBlock lastListItem &&
// lastListItem.LastChild is BlankLineBlock)
// {
// // Inform the outer list that we have a blank line
// var parentList = (ListBlock)parentListItemBlock.Parent;
// parentList.CountAllBlankLines++;
// parentListItemBlock.Add(new BlankLineBlock());
// }
// for (int listIndex = listBlock.Count - 1; listIndex >= 0; listIndex--)
// {
// var listItem = (ListItemBlock)listBlock[listIndex];
// for (int i = listItem.Count - 1; i >= 0; i--)
// {
// if (listItem[i] is BlankLineBlock)
// {
// if (i == listItem.Count - 1 ? listIndex < listBlock.Count - 1 : i > 0)
// {
// listBlock.IsLoose = true;
// }
// //listItem.RemoveAt(i);
// // If we have removed all blank lines, we can exit
// //listBlock.CountAllBlankLines--;
// //if (listBlock.CountAllBlankLines == 0)
// //{
// // goto done;
// //}
// }
// }
// }
// }
//done:
// return true;
}
}
}

View File

@@ -91,11 +91,11 @@ namespace Markdig.Renderers.Normalize
}
renderer.CompactParagraph = compact;
// TODO: make reusable method?
if (listBlock.Parent is MarkdownDocument md && md.LastChild != listBlock)
{
renderer.WriteLine();
}
//// TODO: make reusable method?
//if (listBlock.Parent is MarkdownDocument md && md.LastChild != listBlock)
//{
// renderer.WriteLine();
//}
renderer.RenderLinesAfter(listBlock);
}

View File

@@ -54,7 +54,7 @@ namespace Markdig.Renderers.Normalize
{
if (!IsLastInContainer)
{
WriteLine();
WriteLine(); // TODO: remove this method?
}
}