Merge branch 'soru/fix-pills-in-urls' into 'main'

fix: Accidental pills in URLs

See merge request famedly/famedlysdk!621
This commit is contained in:
Krille Fear 2021-01-20 11:47:03 +00:00
commit f57e6afdfe
2 changed files with 7 additions and 0 deletions

View File

@ -153,6 +153,11 @@ class PillSyntax extends InlineSyntax {
@override @override
bool onMatch(InlineParser parser, Match match) { 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 identifier = match[1];
final element = Element.text('a', identifier); final element = Element.text('a', identifier);
element.attributes['href'] = 'https://matrix.to/#/${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'); '<a href="https://matrix.to/#/#fox:sorunome.de">#fox:sorunome.de</a>: you all are awesome');
expect(markdown('!blah:example.org'), expect(markdown('!blah:example.org'),
'<a href="https://matrix.to/#/!blah:example.org">!blah:example.org</a>'); '<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', () { test('latex', () {
expect(markdown('meep \$\\frac{2}{3}\$'), expect(markdown('meep \$\\frac{2}{3}\$'),