public static string ConvertLine(string line) { var tags = new Stack <Marker>(); for (int i = 0; i < line.Length; i++) { if (line[i] == '\\') { line = line.Remove(i, 1); i++; } var tag = Marker.CreateTag(ref line, i); if (tag == null) { continue; } i += tag.Length - 1; if (Marker.IsEndTag(line, tag.Pos) && tags.Any(t => t.Type == tag.Type)) { line = ConvertTag(line, tags, tag); continue; } if (Marker.IsBeginTag(line, tag.Pos)) { tags.Push(tag); } } return(line); }
private static string ParseLine(string markdown) { var isInsideEmTags = false; var strongTagsPairs = new Stack <(Marker, Marker)>(); var line = markdown; var tagStack = new Stack <Marker>(); for (var i = 0; i < line.Length; i++) { if (line[i] == '\\') { line = line.Remove(i, 1); i++; } var tag = Marker.CreateTag(line, i); if (tag == null) { continue; } i += tag.Length - 1; if (Marker.IsClosingTag(line, tag.Pos) && tagStack.Any(openTag => openTag.Type == tag.Type)) { var tags = Marker.GetTagsPair(line, tag, tagStack); if (tags.openingTag.Type == MarkerType.Em) { isInsideEmTags = false; strongTagsPairs.Clear(); } else if (tags.openingTag.Type == MarkerType.Strong && isInsideEmTags) { strongTagsPairs.Push(tags); continue; } line = Marker.ConvertToHtmlTag(line, tags.openingTag, tags.closingTag); } else if (Marker.IsOpeningTag(line, tag.Pos)) { if (tag.Type == MarkerType.Em) { isInsideEmTags = true; line = ConvertStrongTagFromStack(strongTagsPairs, line); } tagStack.Push(tag); } } line = ConvertStrongTagFromStack(strongTagsPairs, line); return(line); }