Rework markdown parser and improve its performance for non-HTML formats

This commit is contained in:
Alexey Golub
2019-09-15 21:24:07 +03:00
parent 533671c59f
commit cd042e5368
20 changed files with 201 additions and 139 deletions

View File

@@ -12,16 +12,15 @@ namespace DiscordChatExporter.Core.Markdown.Nodes
public bool IsCustomEmoji => !Id.IsNullOrWhiteSpace();
public EmojiNode(string source, string id, string name, bool isAnimated)
: base(source)
public EmojiNode(string id, string name, bool isAnimated)
{
Id = id;
Name = name;
IsAnimated = isAnimated;
}
public EmojiNode(string source, string name)
: this(source, null, name, false)
public EmojiNode(string name)
: this(null, name, false)
{
}

View File

@@ -4,16 +4,12 @@ namespace DiscordChatExporter.Core.Markdown.Nodes
{
public class FormattedNode : Node
{
public string Token { get; }
public TextFormatting Formatting { get; }
public IReadOnlyList<Node> Children { get; }
public FormattedNode(string source, string token, TextFormatting formatting, IReadOnlyList<Node> children)
: base(source)
public FormattedNode(TextFormatting formatting, IReadOnlyList<Node> children)
{
Token = token;
Formatting = formatting;
Children = children;
}

View File

@@ -4,8 +4,7 @@
{
public string Code { get; }
public InlineCodeBlockNode(string source, string code)
: base(source)
public InlineCodeBlockNode(string code)
{
Code = code;
}

View File

@@ -6,14 +6,14 @@
public string Title { get; }
public LinkNode(string source, string url, string title)
: base(source)
public LinkNode(string url, string title)
{
Url = url;
Title = title;
}
public LinkNode(string source, string url) : this(source, url, url)
public LinkNode(string url)
: this(url, url)
{
}

View File

@@ -6,8 +6,7 @@
public MentionType Type { get; }
public MentionNode(string source, string id, MentionType type)
: base(source)
public MentionNode(string id, MentionType type)
{
Id = id;
Type = type;

View File

@@ -1,13 +1,12 @@
namespace DiscordChatExporter.Core.Markdown.Nodes
{
public class MultilineCodeBlockNode : Node
public class MultiLineCodeBlockNode : Node
{
public string Language { get; }
public string Code { get; }
public MultilineCodeBlockNode(string source, string language, string code)
: base(source)
public MultiLineCodeBlockNode(string language, string code)
{
Language = language;
Code = code;

View File

@@ -2,11 +2,5 @@
{
public abstract class Node
{
public string Source { get; }
protected Node(string source)
{
Source = source;
}
}
}

View File

@@ -4,16 +4,11 @@
{
public string Text { get; }
public TextNode(string source, string text)
: base(source)
public TextNode(string text)
{
Text = text;
}
public TextNode(string text) : this(text, text)
{
}
public override string ToString() => Text;
}
}