mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-04 05:44:50 +00:00
fix newlines and list blocks
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Markdig.Renderers.Normalize
|
||||
{
|
||||
if (!IsLastInContainer)
|
||||
{
|
||||
WriteLine();
|
||||
WriteLine(); // TODO: remove this method?
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user