changed the color of the chat links and unit test
This commit is contained in:
parent
3d84a9c8cd
commit
4ad7f4d5a3
@ -151,15 +151,6 @@ export class DiscussionManager {
|
||||
this.nbpParticipants.innerText = `PARTICIPANTS (${nb})`;
|
||||
}
|
||||
|
||||
private urlify(text: string) {
|
||||
const urlRegex = /(https?:\/\/[^\s]+)/g;
|
||||
return text.replace(urlRegex, (url: string) => {
|
||||
return '<a href="' + url + '" target="_blank">' + url + '</a>';
|
||||
})
|
||||
// or alternatively
|
||||
// return text.replace(urlRegex, '<a href="$1">$1</a>')
|
||||
}
|
||||
|
||||
public addMessage(name: string, message: string, isMe: boolean = false) {
|
||||
const divMessage: HTMLDivElement = document.createElement('div');
|
||||
divMessage.classList.add('message');
|
||||
@ -179,7 +170,7 @@ export class DiscussionManager {
|
||||
divMessage.appendChild(pMessage);
|
||||
|
||||
const userMessage: HTMLParagraphElement = document.createElement('p');
|
||||
userMessage.innerHTML = this.urlify(message);
|
||||
userMessage.innerHTML = HtmlUtils.urlify(message);
|
||||
userMessage.classList.add('body');
|
||||
divMessage.appendChild(userMessage);
|
||||
this.divMessages?.appendChild(divMessage);
|
||||
|
@ -17,4 +17,11 @@ export class HtmlUtils {
|
||||
elem.remove();
|
||||
return elem as T;
|
||||
}
|
||||
|
||||
public static urlify(text: string): string {
|
||||
const urlRegex = /(https?:\/\/[^\s]+)/g;
|
||||
return text.replace(urlRegex, (url: string) => {
|
||||
return '<a href="' + url + '" target="_blank" style=":visited {color: white}">' + url + '</a>';
|
||||
})
|
||||
}
|
||||
}
|
||||
|
14
front/tests/Phaser/Game/HtmlUtilsTest.ts
Normal file
14
front/tests/Phaser/Game/HtmlUtilsTest.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import "jasmine";
|
||||
import {HtmlUtils} from "../../../src/WebRtc/HtmlUtils";
|
||||
|
||||
describe("urlify()", () => {
|
||||
it("should transform an url into a link", () => {
|
||||
const text = HtmlUtils.urlify('https://google.com');
|
||||
expect(text).toEqual('<a href="https://google.com" target="_blank" style=":visited {color: white}">https://google.com</a>');
|
||||
});
|
||||
|
||||
it("should not transform a normal text into a link", () => {
|
||||
const text = HtmlUtils.urlify('hello');
|
||||
expect(text).toEqual('hello');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user