1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 20:58:34 +01:00

return the ElementType along with each Element in Parse

This commit is contained in:
Ell 2022-06-14 00:08:05 +02:00
parent 01fb5288ff
commit d0ece92550

View file

@ -78,22 +78,22 @@ namespace MLEM.Ui.Parsers {
/// <param name="element">The element to add the parsed elements to.</param> /// <param name="element">The element to add the parsed elements to.</param>
/// <returns>The <paramref name="element"/>, for chaining.</returns> /// <returns>The <paramref name="element"/>, for chaining.</returns>
public Element ParseInto(string markdown, Element element) { public Element ParseInto(string markdown, Element element) {
foreach (var el in this.Parse(markdown)) foreach (var (_, e) in this.Parse(markdown))
element.AddChild(el); element.AddChild(e);
return element; return element;
} }
/// <summary> /// <summary>
/// Parses the given markdown string into a set of elements and returns them. /// Parses the given markdown string into a set of elements and returns them along with their <see cref="ElementType"/>.
/// During this process, the element stylings specified using <see cref="Style{T}"/> are also applied. /// During this process, the element stylings specified using <see cref="Style{T}"/> are also applied.
/// </summary> /// </summary>
/// <param name="markdown">The markdown to parse.</param> /// <param name="markdown">The markdown to parse.</param>
/// <returns>The parsed elements.</returns> /// <returns>The parsed elements.</returns>
public IEnumerable<Element> Parse(string markdown) { public IEnumerable<(ElementType, Element)> Parse(string markdown) {
foreach (var (type, element) in this.ParseUnstyled(markdown)) { foreach (var (t, e) in this.ParseUnstyled(markdown)) {
if (this.elementStyles.TryGetValue(type, out var style)) if (this.elementStyles.TryGetValue(t, out var style))
style.Invoke(element); style.Invoke(e);
yield return element; yield return (t, e);
} }
} }