From d4456c19c3953c721cd125fc8c0a7c3d6bfe96d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Mon, 3 Sep 2018 12:19:28 +0200 Subject: [PATCH] Do not substitute emotes in links --- .../src/app/comments/comments.component.html | 12 +++++++- .../src/app/pipes/splitmessage.pipe.ts | 28 ++++++++++++++----- .../src/app/search/search.component.html | 12 +++++++- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/apps/twitch-logs/src/app/comments/comments.component.html b/apps/twitch-logs/src/app/comments/comments.component.html index 93b9f81..bb11286 100644 --- a/apps/twitch-logs/src/app/comments/comments.component.html +++ b/apps/twitch-logs/src/app/comments/comments.component.html @@ -75,7 +75,17 @@ {{token.title}} - + + + {{token.formatted}} + + + + + + {{token}} + + diff --git a/apps/twitch-logs/src/app/pipes/splitmessage.pipe.ts b/apps/twitch-logs/src/app/pipes/splitmessage.pipe.ts index 8a57210..4cb0129 100644 --- a/apps/twitch-logs/src/app/pipes/splitmessage.pipe.ts +++ b/apps/twitch-logs/src/app/pipes/splitmessage.pipe.ts @@ -3,7 +3,7 @@ import { PipeTransform } from '@angular/core'; -import * as linkifyString from 'linkifyjs/string'; +import * as linkify from 'linkifyjs'; @Pipe({ @@ -22,13 +22,27 @@ export class SplitMessagePipe implements PipeTransform { let regexp = RegExp('(' + exps.join('|') + ')'); - // FIXME: do not split URLs - let tokens = message.split(regexp); + let options = new linkify.options.Options(); - return tokens.map((token: any) => { - let e = emotes.filter((emote: any) => emote.title == token); + let result = []; - 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; } } diff --git a/apps/twitch-logs/src/app/search/search.component.html b/apps/twitch-logs/src/app/search/search.component.html index bbb44b5..fb75478 100644 --- a/apps/twitch-logs/src/app/search/search.component.html +++ b/apps/twitch-logs/src/app/search/search.component.html @@ -112,7 +112,17 @@ {{token.title}} - + + + {{token.formatted}} + + + + + + {{token}} + +