Nested parsed as List-List-List, always one list to much
Closed this issue ยท 10 comments
When using CommonMarkConverter.Parse(X) nested list output one list to much.
Example md list:
- item1
- item2
- item2-1
- item2-2
- item2-3
Gives output:
- List
- ListItem
- Paragraph "item1"
- ListItem
- Paragraph "item2"
- List (so far so good)
- ListItem
- Paragraph "item2-1"
- List
- ListItem
- Paragraph
- ListItem
- Paragraph "item2-2"
- ListItem
- Paragraph "item2-3"
- ListItem
- ListItem
- ListItem
I'm only using the CommonMarkConverter, so I could make a work around where I detect nestedlist with only one listitem. https://github.com/Toine-db/Xamarin.MarkdownParser
What is the Markdown text you're passing to the converter? If I run the following test, I get the correct output:
using System;
//
using NUnit.Framework;
//
using CommonMark;
namespace CommonMarkTests
{
[TestFixture]
public class MarkdownListTests
{
[Test]
public void NestedListsShouldProduceValidHTML_Test()
{
// arrange
string original = string.Join(Environment.NewLine, "- item1" , "- item2", " - item2-1" , " - item2-2", " - item2-3");
string expected = "<ul>{0}<li>item1</li>{0}<li>item2{0}<ul>{0}<li>item2-1</li>{0}<li>item2-2</li>{0}<li>item2-3</li>{0}</ul>{0}</li>{0}</ul>{0}{0}".Replace("{0}", Environment.NewLine);
string actual = string.Empty;
// act
actual = CommonMarkConverter.Convert(original);
// assert
Assert.AreEqual(expected, actual);
}
}
}
This is an NUnit 3 test, with the extra line return mentioned in #105 (which means this will fail when the next release is made).
The list is exactly something I want to convert, its a Unit test in my library.
I do not use .Convert to HTML, I only use the Parsing to c# object with .Parse.
https://github.com/Toine-db/Xamarin.MarkdownParser/blob/master/Sources/Xamarin.MarkdownParser.Core/MarkdownParser.cs#L27
I really get a list in list in list
https://1drv.ms/i/s!AqZ7dJLKaN9Tj-5zE9IqzqbPvFklXw
(an enumeration from item2, skipping item 1)
At this point in code I only read a md file and used it for CommonMarkConverter.Parse()
PS: Im working on 0.14 and using https://github.com/Knagis/CommonMark.NET/blob/master/CommonMark/CommonMarkConverter.cs#L252
Could you please upload the exact file you are parsing and getting this result? Perhaps there are some tab characters hidden there.
I tried it with the console app and it works correctly:
>type test.txt
* item1
* item2
* item2-1
* item2-2
* item2-3
>CommonMark.Console.exe --ast test.txt
document
list(type=bullet tight=True bullet_char=*)
list_item
paragraph
str "item1"
list_item
paragraph
str "item2"
list(type=bullet tight=True bullet_char=*)
list_item
paragraph
str "item2-1"
list_item
paragraph
str "item2-2"
list_item
paragraph
str "item2-3"
Thanks for helping guys.
The file is in my rep; https://github.com/Toine-db/Xamarin.MarkdownParser/blob/master/Sources/Xamarin.MarkdownParser.Test/examples/sections/nestedlist.md
Thank you, it indeed reproduces the issue; it seems that the tab conversion is incorrect since using four spaces instead of tabs work as expected.
I will let you know as soon as it is fixed.
0.15.0 has been released with the fix.
Just checked, and the same issue still occurs on: (with indent by tabs)
- item1
- item2
- item2-1
- item2-2
- item2-3
Sorry about the very slow response rate...
The 0.15.0 release was again improperly compiled and thus was actually an older version of the binaries. 0.15.1 that I just pushed to nuget should fix it.
@Knagis no problem, I also don't have a lot of time...... it's great you have taken a look.
Thanks, ill test it in a few days (hopefully)
I tested it on my implementation and it seems to work for 2 levels nested listings.
So good job, thanks!