/// <summary> /// This function can be called by any element parsing. Given a start and stopping point this will /// parse all found elements out of the range. /// </summary> /// <param name="markdown"></param> /// <param name="startingPos"></param> /// <param name="maxEndingPos"></param> protected void ParseInlineChildren(ref string markdown, int startingPos, int maxEndingPos) { int currentParsePosition = startingPos; while (currentParsePosition < maxEndingPos) { int nextElemntStart = 0; int nextElementEnd = 0; // Find the next element MarkdownInline element = Common.FindNextInlineElement(ref markdown, currentParsePosition, maxEndingPos, ref nextElemntStart, ref nextElementEnd); // If the element we found doesn't start at the position we are looking for there is text between the element and // the start. We need to wrap it into a Text Run if (nextElemntStart != currentParsePosition) { TextRunInline textRun = new TextRunInline(); textRun.Parse(ref markdown, currentParsePosition, nextElemntStart); Children.Add(textRun); } // Ask it to parse, it will return us the ending pos of itself. currentParsePosition = element.Parse(ref markdown, nextElemntStart, nextElementEnd); // Add it the the children Children.Add(element); } }
public InlineParseResult(MarkdownInline parsedElement, int start, int end) { ParsedElement = parsedElement; Start = start; End = end; }
/// <summary> /// Called to render an inline element. /// </summary> /// <param name="inlineCollection"> The list to add to. </param> /// <param name="element"> The parsed inline element to render. </param> /// <param name="parent"> The container element. </param> /// <param name="context"> Persistent state. </param> private void RenderInline(InlineCollection inlineCollection, MarkdownInline element, TextElement parent, RenderContext context) { switch (element.Type) { case MarkdownInlineType.TextRun: RenderTextRun(inlineCollection, (TextRunInline)element, parent, context); break; case MarkdownInlineType.Italic: RenderItalicRun(inlineCollection, (ItalicTextInline)element, parent, context); break; case MarkdownInlineType.Bold: RenderBoldRun(inlineCollection, (BoldTextInline)element, parent, context); break; case MarkdownInlineType.MarkdownLink: RenderMarkdownLink(inlineCollection, (MarkdownLinkInline)element, parent, context); break; case MarkdownInlineType.RawHyperlink: RenderHyperlink(inlineCollection, (HyperlinkInline)element, parent, context); break; case MarkdownInlineType.Strikethrough: RenderStrikethroughRun(inlineCollection, (StrikethroughTextInline)element, parent, context); break; case MarkdownInlineType.Superscript: RenderSuperscriptRun(inlineCollection, (SuperscriptTextInline)element, parent, context); break; case MarkdownInlineType.Code: RenderCodeRun(inlineCollection, (CodeInline)element, parent, context); break; } }
/// <summary> /// Called to render an inline element /// </summary> /// <param name="element"></param> /// <param name="currentInlines"></param> private void RendnerInline(MarkdownInline element, InlineCollection currentInlines, ref bool trimTextStart) { switch(element.Type) { case MarkdownInlineType.TextRun: RenderTextRun((TextRunInline)element, currentInlines, ref trimTextStart); break; case MarkdownInlineType.Bold: RenderBoldRun((BoldTextElement)element, currentInlines, ref trimTextStart); break; case MarkdownInlineType.MarkdownLink: RenderMarkdownLink((MarkdownLinkInline)element, currentInlines, ref trimTextStart); break; case MarkdownInlineType.Italic: RenderItalicRun((ItalicTextElement)element, currentInlines, ref trimTextStart); break; case MarkdownInlineType.RawHyperlink: RenderRawHyperlink((RawHyperlinkInline)element, currentInlines, ref trimTextStart); break; case MarkdownInlineType.RawSubreddit: RenderRawSubreddit((RawSubredditInline)element, currentInlines, ref trimTextStart); break; } }