Render guild invites in HTML

Closes #649
This commit is contained in:
Tyrrrz
2023-02-14 21:22:07 +02:00
parent 8e5269f0ab
commit 191294b4fe
11 changed files with 184 additions and 14 deletions

View File

@@ -2,4 +2,7 @@
namespace DiscordChatExporter.Core.Markdown;
internal record FormattingNode(FormattingKind Kind, IReadOnlyList<MarkdownNode> Children) : MarkdownNode;
internal record FormattingNode(
FormattingKind Kind,
IReadOnlyList<MarkdownNode> Children
) : MarkdownNode, IContainerNode;

View File

@@ -0,0 +1,8 @@
using System.Collections.Generic;
namespace DiscordChatExporter.Core.Markdown;
internal interface IContainerNode
{
IReadOnlyList<MarkdownNode> Children { get; }
}

View File

@@ -2,9 +2,10 @@
namespace DiscordChatExporter.Core.Markdown;
// Named links can contain child nodes (e.g. [**bold URL**](https://test.com))
internal record LinkNode(
string Url,
IReadOnlyList<MarkdownNode> Children) : MarkdownNode
IReadOnlyList<MarkdownNode> Children) : MarkdownNode, IContainerNode
{
public LinkNode(string url)
: this(url, new[] { new TextNode(url) })

View File

@@ -385,12 +385,32 @@ internal static partial class MarkdownParser
private static IReadOnlyList<MarkdownNode> Parse(StringSegment segment) =>
Parse(segment, AggregateNodeMatcher);
public static IReadOnlyList<MarkdownNode> Parse(string markdown) =>
Parse(new StringSegment(markdown));
private static IReadOnlyList<MarkdownNode> ParseMinimal(StringSegment segment) =>
Parse(segment, MinimalAggregateNodeMatcher);
public static IReadOnlyList<MarkdownNode> Parse(string input) =>
Parse(new StringSegment(input));
public static IReadOnlyList<MarkdownNode> ParseMinimal(string markdown) =>
ParseMinimal(new StringSegment(markdown));
public static IReadOnlyList<MarkdownNode> ParseMinimal(string input) =>
ParseMinimal(new StringSegment(input));
private static void ExtractLinks(IEnumerable<MarkdownNode> nodes, ICollection<LinkNode> links)
{
foreach (var node in nodes)
{
if (node is LinkNode linkNode)
links.Add(linkNode);
if (node is IContainerNode containerNode)
ExtractLinks(containerNode.Children, links);
}
}
public static IReadOnlyList<LinkNode> ExtractLinks(string markdown)
{
var links = new List<LinkNode>();
ExtractLinks(Parse(markdown), links);
return links;
}
}