public Tuple <bool, IElement> Parse(int parentIndentation, int unit, IParent last) { var definitionListItems = DefinitionListItem.Parse(this, last); if (definitionListItems.Count > 0) { var definitionList = last.Parent as DefinitionList; if (last.Parent is DefinitionListItem) { definitionList = (DefinitionList)last.Parent.Parent; } if (definitionList != null) { foreach (var item in definitionListItems) { definitionList.Add(item); } return(new Tuple <bool, IElement>(true, definitionListItems.Last())); } definitionList = new DefinitionList(definitionListItems); definitionList.Parent = last; last.Add(definitionList); var listItem = definitionListItems.Last(); return(new Tuple <bool, IElement>(true, listItem)); } IElement newElement = this; if (Indentation > parentIndentation || TextAreas[0].IsQuoted) { var lastElement = last as IElement; var lastText = lastElement?.TextAreas?.LastOrDefault()?.Content.Text.TrimEnd(); if (lastText != null && lastText.EndsWith("::")) { newElement = new LiteralBlock(TextAreas); lastElement?.TextAreas.Last().Content.RemoveLiteral(); } else { var level = newElement.TextAreas[0].Indentation / unit; while (level > 0) { newElement = new BlockQuote(level * unit, unit, newElement); level--; } } } return(new Tuple <bool, IElement>(false, newElement)); }
internal void Eat(List <IElement> raw, ITracked tracked) { Unit = tracked.IndentationTracker.Minimum; IParent last = this; int parentIndentation = 0; // IMPORTANT: block quote processing for (int i = 0; i < raw.Count; i++) { var current = raw[i]; if (current.TypeCode == ElementType.ListItem) { if (current is ListItem item && item.Enumerator != null) { if (i < raw.Count - 1) { if (raw[i + 1] is ListItem next) { item.Analyze(next); } } } last = last.Add(current); continue; } if (current.TypeCode == ElementType.Comment || current.TypeCode == ElementType.Section) { last = last.Add(current); parentIndentation = current.Indentation; continue; } if (current is Paragraph paragraph) { paragraph.Unit = Unit; if (last.TypeCode == ElementType.ListItem || last.Parent?.TypeCode == ElementType.ListItem) { last = last.Add(current); continue; } if (last.TypeCode == ElementType.BlockQuote) { if (paragraph.IsAttribution()) { last = last.Add(paragraph); continue; } } var tuple = paragraph.Parse(parentIndentation, Unit, last); if (tuple.Item1) { last = tuple.Item2; continue; } current = tuple.Item2; } last = last.Add(current); parentIndentation = current.Indentation; } if (Elements.LastOrDefault() is BlockQuote end) { end.FillAttribution(); } }
public IParent Add(IElement element, int level = 0) { return(Parent.Add(element)); }