Fix some parsing issues

pull/162/head
Alexey Golub 6 years ago
parent 0d1ce38489
commit 668ac70fae

@ -126,21 +126,13 @@ namespace DiscordChatExporter.Core.Markdown.Internal
private static readonly Parser<Node> TitledLinkNode = Parse.RegexMatch("\\[(.+)\\]\\((.+)\\)") private static readonly Parser<Node> TitledLinkNode = Parse.RegexMatch("\\[(.+)\\]\\((.+)\\)")
.Select(m => new LinkNode(m.Value, m.Groups[2].Value, m.Groups[1].Value)); .Select(m => new LinkNode(m.Value, m.Groups[2].Value, m.Groups[1].Value));
// Matches text that represents a link
private static readonly Parser<Match> AutoLinkMatch = Parse.RegexMatch("(https?://\\S*[^\\.,:;\"\'\\s])");
// Starts with http:// or https://, stops at the last non-whitespace character followed by whitespace or punctuation character // Starts with http:// or https://, stops at the last non-whitespace character followed by whitespace or punctuation character
private static readonly Parser<Node> AutoLinkNode = private static readonly Parser<Node> AutoLinkNode = Parse.RegexMatch("(https?://\\S*[^\\.,:;\"\'\\s])")
AutoLinkMatch.Select(m => new LinkNode(m.Value, m.Groups[1].Value)); .Select(m => new LinkNode(m.Value, m.Groups[1].Value));
// Autolink surrounded by angular brackets // Autolink surrounded by angular brackets
private static readonly Parser<Node> HiddenLinkNode = private static readonly Parser<Node> HiddenLinkNode = Parse.RegexMatch("<(https?://\\S*[^\\.,:;\"\'\\s])>")
from open in Parse.Char('<') .Select(m => new LinkNode(m.Value, m.Groups[1].Value));
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);
// Combinator, order matters // Combinator, order matters
private static readonly Parser<Node> AnyLinkNode = TitledLinkNode.Or(HiddenLinkNode).Or(AutoLinkNode); private static readonly Parser<Node> AnyLinkNode = TitledLinkNode.Or(HiddenLinkNode).Or(AutoLinkNode);
@ -156,7 +148,7 @@ namespace DiscordChatExporter.Core.Markdown.Internal
from slash in Parse.Char('\\') from slash in Parse.Char('\\')
from high in Parse.AnyChar.Where(char.IsHighSurrogate) from high in Parse.AnyChar.Where(char.IsHighSurrogate)
from low in Parse.AnyChar from low in Parse.AnyChar
let lexeme = $"\\{high}{low}" let lexeme = $"{slash}{high}{low}"
let text = $"{high}{low}" let text = $"{high}{low}"
select new TextNode(lexeme, text); select new TextNode(lexeme, text);

Loading…
Cancel
Save