diff --git a/CHANGELOG.md b/CHANGELOG.md index b7df406..27d4456 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ Fixes - Fixed parents of elements that prevent spill not being notified properly - Fixed paragraphs sometimes not updating their position properly when hidden because they're empty - Fixed panels sometimes not drawing children that came into view when their positions changed unexpectedly +- Fixed UiMarkdownParser not parsing formatting in headings and blockquotes ### MLEM.Data Improvements diff --git a/MLEM.Ui/Parsers/UiMarkdownParser.cs b/MLEM.Ui/Parsers/UiMarkdownParser.cs index e5f6971..b47a2b9 100644 --- a/MLEM.Ui/Parsers/UiMarkdownParser.cs +++ b/MLEM.Ui/Parsers/UiMarkdownParser.cs @@ -138,7 +138,7 @@ namespace MLEM.Ui.Parsers { // quotes if (line.StartsWith(">")) { - yield return (ElementType.Blockquote, new Paragraph(Anchor.AutoLeft, 1, line.Substring(1).Trim())); + yield return (ElementType.Blockquote, new Paragraph(Anchor.AutoLeft, 1, this.ParseParagraph(line.Substring(1).Trim()))); continue; } @@ -198,7 +198,7 @@ namespace MLEM.Ui.Parsers { for (var h = 6; h >= 1; h--) { if (line.StartsWith(new string('#', h))) { var type = UiMarkdownParser.ElementTypes[Array.IndexOf(UiMarkdownParser.ElementTypes, ElementType.Header1) + h - 1]; - yield return (type, new Paragraph(Anchor.AutoLeft, 1, line.Substring(h).Trim())); + yield return (type, new Paragraph(Anchor.AutoLeft, 1, this.ParseParagraph(line.Substring(h).Trim()))); parsedHeader = true; break; } @@ -207,22 +207,25 @@ namespace MLEM.Ui.Parsers { continue; // parse everything else as a paragraph (with formatting) - var par = line; - // replace links - par = Regex.Replace(par, @"<([^>]+)>", "$1"); - par = Regex.Replace(par, @"\[([^\]]+)\]\(([^)]+)\)", "$1"); - // replace formatting - par = Regex.Replace(par, @"\*\*([^\*]+)\*\*", "$1"); - par = Regex.Replace(par, @"__([^_]+)__", "$1"); - par = Regex.Replace(par, @"\*([^\*]+)\*", "$1"); - par = Regex.Replace(par, @"_([^_]+)_", "$1"); - par = Regex.Replace(par, @"~~([^~]+)~~", "$1"); - // replace inline code with custom code font - par = Regex.Replace(par, @"`([^`]+)`", $"$1"); - yield return (ElementType.Paragraph, new Paragraph(Anchor.AutoLeft, 1, par)); + yield return (ElementType.Paragraph, new Paragraph(Anchor.AutoLeft, 1, this.ParseParagraph(line))); } } + private string ParseParagraph(string par) { + // replace links + par = Regex.Replace(par, @"<([^>]+)>", "$1"); + par = Regex.Replace(par, @"\[([^\]]+)\]\(([^)]+)\)", "$1"); + // replace formatting + par = Regex.Replace(par, @"\*\*([^\*]+)\*\*", "$1"); + par = Regex.Replace(par, @"__([^_]+)__", "$1"); + par = Regex.Replace(par, @"\*([^\*]+)\*", "$1"); + par = Regex.Replace(par, @"_([^_]+)_", "$1"); + par = Regex.Replace(par, @"~~([^~]+)~~", "$1"); + // replace inline code with custom code font + par = Regex.Replace(par, @"`([^`]+)`", $"$1"); + return par; + } + /// /// A flags enumeration used by that contains the types of elements that can be parsed and returned in or . /// This is a flags enumeration so that can have multiple element types being styled at the same time.