fix: Accidental pills in URLs

This commit is contained in:
Sorunome 2021-01-20 12:02:40 +01:00
parent 8de72c869a
commit 44a1bcfd57
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
2 changed files with 7 additions and 0 deletions

View File

@ -153,6 +153,11 @@ class PillSyntax extends InlineSyntax {
@override
bool onMatch(InlineParser parser, Match match) {
if (match.start > 0 &&
!RegExp(r'[\s.!?:;\(]').hasMatch(match.input[match.start - 1])) {
parser.addNode(Text(match[0]));
return true;
}
final identifier = match[1];
final element = Element.text('a', identifier);
element.attributes['href'] = 'https://matrix.to/#/${identifier}';

View File

@ -69,6 +69,8 @@ void main() {
'<a href="https://matrix.to/#/#fox:sorunome.de">#fox:sorunome.de</a>: you all are awesome');
expect(markdown('!blah:example.org'),
'<a href="https://matrix.to/#/!blah:example.org">!blah:example.org</a>');
expect(markdown('https://matrix.to/#/#fox:sorunome.de'),
'https://matrix.to/#/#fox:sorunome.de');
});
test('latex', () {
expect(markdown('meep \$\\frac{2}{3}\$'),