[HTML] Match repeated single quotes as a multiline quote

Closes #288
pull/321/head
Alexey Golub 5 years ago
parent 4ab6607e78
commit 9711a8cca4

@ -59,9 +59,19 @@ namespace DiscordChatExporter.Core.Markdown
// Capture any character until the end of the line // Capture any character until the end of the line
// Opening 'greater than' character must be followed by whitespace // Opening 'greater than' character must be followed by whitespace
private static readonly IMatcher<Node> SingleLineQuoteNodeMatcher = new RegexMatcher<Node>( private static readonly IMatcher<Node> SingleLineQuoteNodeMatcher = new RegexMatcher<Node>(
new Regex("^>\\s(.+)\r?\n?", DefaultRegexOptions), new Regex("^>\\s(.+\n?)", DefaultRegexOptions),
(p, m) => new FormattedNode(TextFormatting.Quote, Parse(p.Slice(m.Groups[1])))); (p, m) => new FormattedNode(TextFormatting.Quote, Parse(p.Slice(m.Groups[1]))));
// Repeatedly capture any character until the end of the line
// This one is tricky as it ends up producing multiple separate captures
private static readonly IMatcher<Node> RepeatedSingleLineQuoteNodeMatcher = new RegexMatcher<Node>(
new Regex("(?:^>\\s(.+\n?)){2,}", DefaultRegexOptions),
(p, m) =>
{
var children = m.Groups[1].Captures.Select(c => c.Value).SelectMany(Parse).ToArray();
return new FormattedNode(TextFormatting.Quote, children);
});
// Capture any character until the end of the input // Capture any character until the end of the input
// Opening 'greater than' characters must be followed by whitespace // Opening 'greater than' characters must be followed by whitespace
private static readonly IMatcher<Node> MultiLineQuoteNodeMatcher = new RegexMatcher<Node>( private static readonly IMatcher<Node> MultiLineQuoteNodeMatcher = new RegexMatcher<Node>(
@ -188,6 +198,7 @@ namespace DiscordChatExporter.Core.Markdown
StrikethroughFormattedNodeMatcher, StrikethroughFormattedNodeMatcher,
SpoilerFormattedNodeMatcher, SpoilerFormattedNodeMatcher,
MultiLineQuoteNodeMatcher, MultiLineQuoteNodeMatcher,
RepeatedSingleLineQuoteNodeMatcher,
SingleLineQuoteNodeMatcher, SingleLineQuoteNodeMatcher,
// Code blocks // Code blocks
@ -208,7 +219,8 @@ namespace DiscordChatExporter.Core.Markdown
// Emoji // Emoji
StandardEmojiNodeMatcher, StandardEmojiNodeMatcher,
CustomEmojiNodeMatcher); CustomEmojiNodeMatcher
);
// Minimal set of matchers for non-multimedia formats (e.g. plain text) // Minimal set of matchers for non-multimedia formats (e.g. plain text)
private static readonly IMatcher<Node> MinimalAggregateNodeMatcher = new AggregateMatcher<Node>( private static readonly IMatcher<Node> MinimalAggregateNodeMatcher = new AggregateMatcher<Node>(
@ -220,7 +232,8 @@ namespace DiscordChatExporter.Core.Markdown
RoleMentionNodeMatcher, RoleMentionNodeMatcher,
// Emoji // Emoji
CustomEmojiNodeMatcher); CustomEmojiNodeMatcher
);
private static IReadOnlyList<Node> Parse(StringPart stringPart, IMatcher<Node> matcher) => private static IReadOnlyList<Node> Parse(StringPart stringPart, IMatcher<Node> matcher) =>
matcher.MatchAll(stringPart, p => new TextNode(p.ToString())).Select(r => r.Value).ToArray(); matcher.MatchAll(stringPart, p => new TextNode(p.ToString())).Select(r => r.Value).ToArray();

Loading…
Cancel
Save