mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
Fixed UiMarkdownParser not parsing formatting in headings and blockquotes
This commit is contained in:
parent
af0aee6c40
commit
6a271af017
2 changed files with 19 additions and 15 deletions
|
@ -29,6 +29,7 @@ Fixes
|
||||||
- Fixed parents of elements that prevent spill not being notified properly
|
- 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 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 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
|
### MLEM.Data
|
||||||
Improvements
|
Improvements
|
||||||
|
|
|
@ -138,7 +138,7 @@ namespace MLEM.Ui.Parsers {
|
||||||
|
|
||||||
// quotes
|
// quotes
|
||||||
if (line.StartsWith(">")) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ namespace MLEM.Ui.Parsers {
|
||||||
for (var h = 6; h >= 1; h--) {
|
for (var h = 6; h >= 1; h--) {
|
||||||
if (line.StartsWith(new string('#', h))) {
|
if (line.StartsWith(new string('#', h))) {
|
||||||
var type = UiMarkdownParser.ElementTypes[Array.IndexOf(UiMarkdownParser.ElementTypes, ElementType.Header1) + h - 1];
|
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;
|
parsedHeader = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -207,22 +207,25 @@ namespace MLEM.Ui.Parsers {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// parse everything else as a paragraph (with formatting)
|
// parse everything else as a paragraph (with formatting)
|
||||||
var par = line;
|
yield return (ElementType.Paragraph, new Paragraph(Anchor.AutoLeft, 1, this.ParseParagraph(line)));
|
||||||
// replace links
|
|
||||||
par = Regex.Replace(par, @"<([^>]+)>", "<l $1>$1</l>");
|
|
||||||
par = Regex.Replace(par, @"\[([^\]]+)\]\(([^)]+)\)", "<l $2>$1</l>");
|
|
||||||
// replace formatting
|
|
||||||
par = Regex.Replace(par, @"\*\*([^\*]+)\*\*", "<b>$1</b>");
|
|
||||||
par = Regex.Replace(par, @"__([^_]+)__", "<b>$1</b>");
|
|
||||||
par = Regex.Replace(par, @"\*([^\*]+)\*", "<i>$1</i>");
|
|
||||||
par = Regex.Replace(par, @"_([^_]+)_", "<i>$1</i>");
|
|
||||||
par = Regex.Replace(par, @"~~([^~]+)~~", "<st>$1</st>");
|
|
||||||
// replace inline code with custom code font
|
|
||||||
par = Regex.Replace(par, @"`([^`]+)`", $"<f {this.CodeFont}>$1</f>");
|
|
||||||
yield return (ElementType.Paragraph, new Paragraph(Anchor.AutoLeft, 1, par));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string ParseParagraph(string par) {
|
||||||
|
// replace links
|
||||||
|
par = Regex.Replace(par, @"<([^>]+)>", "<l $1>$1</l>");
|
||||||
|
par = Regex.Replace(par, @"\[([^\]]+)\]\(([^)]+)\)", "<l $2>$1</l>");
|
||||||
|
// replace formatting
|
||||||
|
par = Regex.Replace(par, @"\*\*([^\*]+)\*\*", "<b>$1</b>");
|
||||||
|
par = Regex.Replace(par, @"__([^_]+)__", "<b>$1</b>");
|
||||||
|
par = Regex.Replace(par, @"\*([^\*]+)\*", "<i>$1</i>");
|
||||||
|
par = Regex.Replace(par, @"_([^_]+)_", "<i>$1</i>");
|
||||||
|
par = Regex.Replace(par, @"~~([^~]+)~~", "<st>$1</st>");
|
||||||
|
// replace inline code with custom code font
|
||||||
|
par = Regex.Replace(par, @"`([^`]+)`", $"<f {this.CodeFont}>$1</f>");
|
||||||
|
return par;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A flags enumeration used by <see cref="UiMarkdownParser"/> that contains the types of elements that can be parsed and returned in <see cref="Parse"/> or <see cref="UiMarkdownParser.ParseInto"/>.
|
/// A flags enumeration used by <see cref="UiMarkdownParser"/> that contains the types of elements that can be parsed and returned in <see cref="Parse"/> or <see cref="UiMarkdownParser.ParseInto"/>.
|
||||||
/// This is a flags enumeration so that <see cref="UiMarkdownParser.Style{T}"/> can have multiple element types being styled at the same time.
|
/// This is a flags enumeration so that <see cref="UiMarkdownParser.Style{T}"/> can have multiple element types being styled at the same time.
|
||||||
|
|
Loading…
Reference in a new issue