/// <summary> /// Initializes a new instance of the <see cref="MarkdownInline"/> class. /// </summary> internal MarkdownInline(MarkdownInlineType type) { Type = type; }
private void RenderInlineType(IList <MarkdownInline> inlines, MarkdownInlineType markdownInlineType, IRenderContext context) { _inlineTypeStack.Push(markdownInlineType); RenderInlineChildren(inlines, context); _inlineTypeStack.Pop(); }
/// <summary> /// Default constructor for this class. /// </summary> public MarkdownInline(MarkdownInlineType type) { Type = type; }
/// <summary> /// Called when the object should parse it's goods out of the markdown. The markdown, start, and stop are given. /// The start and stop are what is returned from the FindNext function below. The object should do it's parsing and /// return up to the last pos it used. This can be shorter than what is given to the function in endingPos. /// </summary> /// <param name="markdown">The markdown</param> /// <param name="startingPos">Where the parse should start</param> /// <param name="endingPos">Where the parse should end</param> /// <returns></returns> internal override int Parse(ref string markdown, int startingPos, int endingPos) { // Find all of the link parts int linkTextOpen = Common.IndexOf(ref markdown, '[', startingPos, endingPos); int linkTextClose = Common.IndexOf(ref markdown, ']', linkTextOpen, endingPos); int linkOpen = Common.IndexOf(ref markdown, '(', linkTextClose, endingPos); int linkClose = Common.IndexOf(ref markdown, ')', linkOpen, endingPos); // These should always be = if (linkTextOpen != startingPos) { DebuggingReporter.ReportCriticalError("link parse didn't find [ in at the starting pos"); } if (linkClose + 1 != endingPos) { DebuggingReporter.ReportCriticalError("link parse didn't find ] in at the end pos"); } // Make sure there is something to parse, and not just dead space linkTextOpen++; if (linkTextClose > linkTextOpen) { // Parse any children of this link element ParseInlineChildren(ref markdown, linkTextOpen, linkTextClose); } // We can't render links in links. So if anything in the children of this is a link // we have to remove it for (int count = 0; count < Children.Count; count++) { // Look through the children for a link, if found grab the text MarkdownInlineType type = ((MarkdownInline)Children[count]).Type; string replaceText = null; if (type == MarkdownInlineType.MarkdownLink) { // If it is a link just grab the URL. Ideally we would grab the text // but that is too hard and this will never happen. replaceText = ((MarkdownLinkInline)Children[count]).Url; } else if (type == MarkdownInlineType.RawHyperlink) { replaceText = ((RawHyperlinkInline)Children[count]).Url; } else if (type == MarkdownInlineType.RawSubreddit) { replaceText = ((RawSubredditInline)Children[count]).Text; } // If we found text to replace add a new text element as the text. if (replaceText != null) { TextRunInline textRun = new TextRunInline(); textRun.Text = replaceText; Children[count] = textRun; } } // Grab the link linkOpen++; Url = markdown.Substring(linkOpen, linkClose - linkOpen); // Return the point after the ) return(linkClose + 1); }