@meetelise/chat 1.53.0 → 1.53.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -107,21 +107,25 @@ export class PubnubMessage extends LitElement {
|
|
|
107
107
|
const allWords = this.preserveHTMLTags(sanitizedLine);
|
|
108
108
|
if (!allWords) return html``;
|
|
109
109
|
return html`${allWords.map((word) => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
110
|
+
const markedLinks = hyperlinks.filter((obj) =>
|
|
111
|
+
word.includes(obj.id)
|
|
112
|
+
);
|
|
113
|
+
if (markedLinks.length) {
|
|
114
|
+
// EliseAI made hyperlink, possibly inside markdown formatting like <b>
|
|
115
|
+
let wordWithLinks = word;
|
|
116
|
+
markedLinks.forEach((link) => {
|
|
117
|
+
imagesToDisplay.push({
|
|
118
|
+
redirectTo: link.link,
|
|
119
|
+
source: link.link,
|
|
120
|
+
});
|
|
121
|
+
wordWithLinks = wordWithLinks.replace(
|
|
122
|
+
link.id,
|
|
123
|
+
this.hyperlinkHTML(link.link, link.hyperlink)
|
|
124
|
+
);
|
|
117
125
|
});
|
|
118
|
-
return html
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
target="_blank"
|
|
122
|
-
rel="noopener noreferrer"
|
|
123
|
-
>${link?.hyperlink}
|
|
124
|
-
</a>`;
|
|
126
|
+
return html`${unsafeHTML(
|
|
127
|
+
DOMPurify.sanitize(wordWithLinks, { ADD_ATTR: ["target"] })
|
|
128
|
+
)} `;
|
|
125
129
|
}
|
|
126
130
|
if (urlRegex.test(word)) {
|
|
127
131
|
// general url
|
|
@@ -145,6 +149,16 @@ export class PubnubMessage extends LitElement {
|
|
|
145
149
|
});
|
|
146
150
|
}
|
|
147
151
|
|
|
152
|
+
private hyperlinkHTML(link: string, hyperlink: string): string {
|
|
153
|
+
const anchor = document.createElement("a");
|
|
154
|
+
anchor.className = "redirect-link";
|
|
155
|
+
anchor.href = link;
|
|
156
|
+
anchor.target = "_blank";
|
|
157
|
+
anchor.rel = "noopener noreferrer";
|
|
158
|
+
anchor.textContent = hyperlink;
|
|
159
|
+
return anchor.outerHTML;
|
|
160
|
+
}
|
|
161
|
+
|
|
148
162
|
private preserveHTMLTags(text: string): string[] {
|
|
149
163
|
const tagRegex = /(<\/?[a-z][^>]*>[^<]*<\/?[a-z]*>|[^\s]+[.,?!]?|\S)/gi;
|
|
150
164
|
const splitTags = text.match(tagRegex);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { expect } from "@esm-bundle/chai";
|
|
2
|
+
import "../public/dist/index";
|
|
3
|
+
import type { SimpleTextChatMessage } from "./MyPubnub";
|
|
4
|
+
import type { PubnubMessage } from "./WebComponent/pubnub-message";
|
|
5
|
+
|
|
6
|
+
declare const it: (name: string, callback: () => void | Promise<void>) => void;
|
|
7
|
+
|
|
8
|
+
const renderMessage = async (message: string): Promise<ShadowRoot> => {
|
|
9
|
+
const element = document.createElement("pubnub-message") as PubnubMessage;
|
|
10
|
+
element.message = {
|
|
11
|
+
timestamp: 100,
|
|
12
|
+
message,
|
|
13
|
+
isLeadMessage: false,
|
|
14
|
+
chunks: [{ text: message, order: 0, isDone: true }],
|
|
15
|
+
type: "text" as SimpleTextChatMessage["type"],
|
|
16
|
+
};
|
|
17
|
+
document.body.appendChild(element);
|
|
18
|
+
await element.updateComplete;
|
|
19
|
+
await element.updateComplete;
|
|
20
|
+
return element.shadowRoot as ShadowRoot;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
it("renders bolded and plain markdown links as links to the community", async () => {
|
|
24
|
+
const root = await renderMessage(
|
|
25
|
+
"- **[Alder House](https://www.clg-test.com/alder)** apartment 109\n" +
|
|
26
|
+
"- [Cedar Row](https://www.clg-test.com/cedar) apartment 103"
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const boldLink = root.querySelector("b a.redirect-link");
|
|
30
|
+
expect(boldLink?.getAttribute("href")).to.equal(
|
|
31
|
+
"https://www.clg-test.com/alder"
|
|
32
|
+
);
|
|
33
|
+
expect(boldLink?.getAttribute("target")).to.equal("_blank");
|
|
34
|
+
expect(boldLink?.textContent?.trim()).to.equal("Alder House");
|
|
35
|
+
|
|
36
|
+
const plainLink = Array.from(root.querySelectorAll("a.redirect-link")).find(
|
|
37
|
+
(anchor) => anchor.textContent?.trim() === "Cedar Row"
|
|
38
|
+
);
|
|
39
|
+
expect(plainLink?.getAttribute("href")).to.equal(
|
|
40
|
+
"https://www.clg-test.com/cedar"
|
|
41
|
+
);
|
|
42
|
+
expect(plainLink?.getAttribute("target")).to.equal("_blank");
|
|
43
|
+
expect(root.textContent).not.to.match(/[0-9a-f]{32}/);
|
|
44
|
+
});
|