Do not substitute emotes in links

master
Nikola Forró 6 years ago
parent cbbb3f503d
commit d4456c19c3

@ -75,7 +75,17 @@
<img src="{{token.url}}" alt="{{token.title}}" *ngIf="token.hasOwnProperty('url')"> <img src="{{token.url}}" alt="{{token.title}}" *ngIf="token.hasOwnProperty('url')">
<span *ngIf="!token.hasOwnProperty('url')" [innerHtml]="token"></span> <a href="{{token.formattedHref}}" target="_blank" *ngIf="token.hasOwnProperty('formatted')">
{{token.formatted}}
</a>
<span *ngIf="!token.hasOwnProperty('url') && !token.hasOwnProperty('formatted')">
{{token}}
</span>
</ng-template> </ng-template>

@ -3,7 +3,7 @@ import {
PipeTransform PipeTransform
} from '@angular/core'; } from '@angular/core';
import * as linkifyString from 'linkifyjs/string'; import * as linkify from 'linkifyjs';
@Pipe({ @Pipe({
@ -22,13 +22,27 @@ export class SplitMessagePipe implements PipeTransform {
let regexp = RegExp('(' + exps.join('|') + ')'); let regexp = RegExp('(' + exps.join('|') + ')');
// FIXME: do not split URLs let options = new linkify.options.Options();
let tokens = message.split(regexp);
return tokens.map((token: any) => { let result = [];
let e = emotes.filter((emote: any) => emote.title == token);
return e.length > 0 ? e[0] : linkifyString(token); for (let token of linkify.tokenize(message)) {
}); if (token.isLink) {
result.push(options.resolve(token));
continue;
}
for (let part of token.toString().split(regexp)) {
let e = emotes.filter((emote: any) => emote.title == part);
if (e.length > 0) {
result.push(e[0]);
} else {
result.push(part);
}
}
}
return result;
} }
} }

@ -112,7 +112,17 @@
<img src="{{token.url}}" alt="{{token.title}}" *ngIf="token.hasOwnProperty('url')"> <img src="{{token.url}}" alt="{{token.title}}" *ngIf="token.hasOwnProperty('url')">
<span *ngIf="!token.hasOwnProperty('url')" [innerHtml]="token"></span> <a href="{{token.formattedHref}}" target="_blank" *ngIf="token.hasOwnProperty('formatted')">
{{token.formatted}}
</a>
<span *ngIf="!token.hasOwnProperty('url') && !token.hasOwnProperty('formatted')">
{{token}}
</span>
</ng-template> </ng-template>

Loading…
Cancel
Save