private static ListItemPreamble ParseItemPreamble(string markdown, int start, int maxEnd)
{
// There are two types of lists.
// A numbered list starts with a number, then a period ('.'), then a space.
// A bulleted list starts with a star ('*'), dash ('-') or plus ('+'), then a period, then a space.
ListStyle style;
if (markdown[start] == '*' || markdown[start] == '-' || markdown[start] == '+')
{
style = ListStyle.Bulleted;
start++;
}
else if (markdown[start] >= '0' && markdown[start] <= '9')
{
style = ListStyle.Numbered;
start++;
// Skip any other digits.
while (start < maxEnd)
{
char c = markdown[start];
if (c < '0' || c > '9')
break;
start++;
}
// Next should be a period ('.').
if (start == maxEnd || markdown[start] != '.')
return null;
start++;
}
else
return null;
// Next should be a space.
if (start == maxEnd || (markdown[start] != ' ' && markdown[start] != '\t'))
return null;
start++;
// This is a valid list item.
return new ListItemPreamble { Style = style, ContentStartPos = start };
}