anthv123 anthv123 - 4 months ago 37
Markdown Question

MarkdownSharp does not transform list

The following string will properly be transformed from a markdown list to an HTML list:

string list = "* Item1\n* Item 2";


However, if I have some other string, then append the list to it, the output is unexpected.

string text = "here is some **bold** text " + list;


output:

here is some <b>bold</b> text * Item1 * Item 2


It seems the problem is trying to transform a list that exists in a block of other text? If that is the problem, is that the intended behavior?

Answer

I'm not familiar with MarkdownSharp, but most Markdown parsers expect two linebreaks (\n) between a paragraph and another paragraph, or new content.

So, by appending the list, you remove Item1 from potentially starting a new list. By only being a single linebreak (\n), MarkdownSharp is most likely not perceiving the content as the start of anything new (just a stray linebreak).

Try concatenating the list with \n\n.

string text = "here is some **bold** text\n\n" + list;