/// <summary> /// Attempts to parse a strikethrough text span. /// </summary> /// <param name="markdown"> The markdown text. </param> /// <param name="start"> The location to start parsing. </param> /// <param name="maxEnd"> The location to stop parsing. </param> /// <returns> A parsed strikethrough text span, or <c>null</c> if this is not a strikethrough text span. </returns> internal static Common.InlineParseResult Parse(string markdown, int start, int maxEnd) { // Check the start sequence. if (start >= maxEnd - 1 || markdown.Substring(start, 2) != "~~") { return(null); } // Find the end of the span. var innerStart = start + 2; int innerEnd = Common.IndexOf(markdown, "~~", innerStart, maxEnd); if (innerEnd == -1) { return(null); } // The span must contain at least one character. if (innerStart == innerEnd) { return(null); } // The first character inside the span must NOT be a space. if (Common.IsWhiteSpace(markdown[innerStart])) { return(null); } // The last character inside the span must NOT be a space. if (Common.IsWhiteSpace(markdown[innerEnd - 1])) { return(null); } // We found something! var result = new StrikethroughTextInline(); result.Inlines = Common.ParseInlineChildren(markdown, innerStart, innerEnd); return(new Common.InlineParseResult(result, start, innerEnd + 2)); }
/// <summary> /// Renders a strikethrough 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 RenderStrikethroughRun(InlineCollection inlineCollection, StrikethroughTextInline element, TextElement parent, RenderContext context) { Span span = new Span(); span.FontFamily = new FontFamily("Consolas"); // Render the children into the inline. RenderInlineChildren(span.Inlines, element.Inlines, span, context); AlterChildRuns(span, (parentSpan, run) => { var text = run.Text; var builder = new StringBuilder(text.Length * 2); foreach (var c in text) { builder.Append((char)0x0336); builder.Append(c); } run.Text = builder.ToString(); }); // Add it to the current inlines inlineCollection.Add(span); }
/// <summary> /// Attempts to parse a strikethrough text span. /// </summary> /// <param name="markdown"> The markdown text. </param> /// <param name="start"> The location to start parsing. </param> /// <param name="maxEnd"> The location to stop parsing. </param> /// <returns> A parsed strikethrough text span, or <c>null</c> if this is not a strikethrough text span. </returns> internal static Common.InlineParseResult Parse(string markdown, int start, int maxEnd) { // Check the start sequence. if (start >= maxEnd - 1 || markdown.Substring(start, 2) != "~~") return null; // Find the end of the span. var innerStart = start + 2; int innerEnd = Common.IndexOf(markdown, "~~", innerStart, maxEnd); if (innerEnd == -1) return null; // The span must contain at least one character. if (innerStart == innerEnd) return null; // The first character inside the span must NOT be a space. if (Common.IsWhiteSpace(markdown[innerStart])) return null; // The last character inside the span must NOT be a space. if (Common.IsWhiteSpace(markdown[innerEnd - 1])) return null; // We found something! var result = new StrikethroughTextInline(); result.Inlines = Common.ParseInlineChildren(markdown, innerStart, innerEnd); return new Common.InlineParseResult(result, start, innerEnd + 2); }