From dda32d8af2e14e44f7d71345ad71cacd31d30559 Mon Sep 17 00:00:00 2001 From: Alexey Golub Date: Wed, 6 Mar 2019 22:37:36 +0200 Subject: [PATCH] Fix markdown grammar being too greedy in some places Fixes #150 --- DiscordChatExporter.Core.Markdown/Internal/Grammar.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DiscordChatExporter.Core.Markdown/Internal/Grammar.cs b/DiscordChatExporter.Core.Markdown/Internal/Grammar.cs index f364c57..3e144a8 100644 --- a/DiscordChatExporter.Core.Markdown/Internal/Grammar.cs +++ b/DiscordChatExporter.Core.Markdown/Internal/Grammar.cs @@ -71,7 +71,7 @@ namespace DiscordChatExporter.Core.Markdown.Internal // The first word is a language identifier if it's the only word followed by a newline, the rest is code private static readonly Parser MultilineCodeBlockNode = - Parse.RegexMatch(new Regex("```(?:(\\w*?)?(?:\\s*?\\n))?(.+)```", RegexOptions.Singleline)) + Parse.RegexMatch(new Regex("```(?:(\\w*?)?(?:\\s*?\\n))?(.+?)```", RegexOptions.Singleline)) .Select(m => new MultilineCodeBlockNode(m.Value, m.Groups[1].Value, m.Groups[2].Value)); // Combinator, order matters @@ -114,7 +114,7 @@ namespace DiscordChatExporter.Core.Markdown.Internal .Select(m => new EmojiNode(m.Value, m.Groups[1].Value)); // <:lul:123456> or - private static readonly Parser CustomEmojiNode = Parse.RegexMatch("<(a)?:(.+):(\\d+)>") + private static readonly Parser CustomEmojiNode = Parse.RegexMatch("<(a)?:(.+?):(\\d+)>") .Select(m => new EmojiNode(m.Value, m.Groups[3].Value, m.Groups[2].Value, m.Groups[1].Value.IsNotBlank())); // Combinator, order matters @@ -123,7 +123,7 @@ namespace DiscordChatExporter.Core.Markdown.Internal /* Links */ // [title](link) - private static readonly Parser TitledLinkNode = Parse.RegexMatch("\\[(.+)\\]\\((.+)\\)") + private static readonly Parser TitledLinkNode = Parse.RegexMatch("\\[(.+?)\\]\\((.+?)\\)") .Select(m => new LinkNode(m.Value, m.Groups[2].Value, m.Groups[1].Value)); // Starts with http:// or https://, stops at the last non-whitespace character followed by whitespace or punctuation character