From 668ac70fae6aafa420b2c871eb4474f5602e9b31 Mon Sep 17 00:00:00 2001 From: Alexey Golub Date: Sun, 3 Mar 2019 21:24:37 +0200 Subject: [PATCH] Fix some parsing issues --- .../Internal/Grammar.cs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/DiscordChatExporter.Core.Markdown/Internal/Grammar.cs b/DiscordChatExporter.Core.Markdown/Internal/Grammar.cs index c5090bb..f364c57 100644 --- a/DiscordChatExporter.Core.Markdown/Internal/Grammar.cs +++ b/DiscordChatExporter.Core.Markdown/Internal/Grammar.cs @@ -126,21 +126,13 @@ namespace DiscordChatExporter.Core.Markdown.Internal private static readonly Parser TitledLinkNode = Parse.RegexMatch("\\[(.+)\\]\\((.+)\\)") .Select(m => new LinkNode(m.Value, m.Groups[2].Value, m.Groups[1].Value)); - // Matches text that represents a link - private static readonly Parser AutoLinkMatch = Parse.RegexMatch("(https?://\\S*[^\\.,:;\"\'\\s])"); - // Starts with http:// or https://, stops at the last non-whitespace character followed by whitespace or punctuation character - private static readonly Parser AutoLinkNode = - AutoLinkMatch.Select(m => new LinkNode(m.Value, m.Groups[1].Value)); + private static readonly Parser AutoLinkNode = Parse.RegexMatch("(https?://\\S*[^\\.,:;\"\'\\s])") + .Select(m => new LinkNode(m.Value, m.Groups[1].Value)); // Autolink surrounded by angular brackets - private static readonly Parser HiddenLinkNode = - from open in Parse.Char('<') - from linkMatch in AutoLinkMatch - from close in Parse.Char('>') - let url = linkMatch.Groups[1].Value - let lexeme = $"{open}{url}{close}" - select new LinkNode(lexeme, url); + private static readonly Parser HiddenLinkNode = Parse.RegexMatch("<(https?://\\S*[^\\.,:;\"\'\\s])>") + .Select(m => new LinkNode(m.Value, m.Groups[1].Value)); // Combinator, order matters private static readonly Parser AnyLinkNode = TitledLinkNode.Or(HiddenLinkNode).Or(AutoLinkNode); @@ -156,7 +148,7 @@ namespace DiscordChatExporter.Core.Markdown.Internal from slash in Parse.Char('\\') from high in Parse.AnyChar.Where(char.IsHighSurrogate) from low in Parse.AnyChar - let lexeme = $"\\{high}{low}" + let lexeme = $"{slash}{high}{low}" let text = $"{high}{low}" select new TextNode(lexeme, text);