Skip to content

Commit 46d86c3

Browse files
przemvse-maad
andauthored
fix: Wire deeplink with custom passed url [WPB-17649] (#19158)
* fix: Wire deeplink with custom passed url * Update src/script/util/messageRenderer.ts Co-authored-by: Immad Abdul Jabbar <[email protected]> --------- Co-authored-by: Immad Abdul Jabbar <[email protected]>
1 parent 261d763 commit 46d86c3

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/script/util/messageRenderer.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ describe('renderMessage', () => {
197197
);
198198
});
199199

200+
it('renders a wire deeplink with config url', () => {
201+
expect(renderMessage('wire://access/?config=https://test.com/deeplink.json')).toBe(
202+
'<a href="wire://access/?config=https://test.com/deeplink.json" target="_blank" rel="nofollow noopener noreferrer" data-uie-name="wire-deep-link">wire://access/?config=https://test.com/deeplink.json</a>',
203+
);
204+
});
205+
206+
it('renders a wire deeplink with config url with alias', () => {
207+
expect(renderMessage('[deeplink](wire://access/?config=https://test.com/deeplink.json)')).toBe(
208+
'<a href="wire://access/?config=https://test.com/deeplink.json" target="_blank" rel="nofollow noopener noreferrer" data-uie-name="wire-deep-link">deeplink</a>',
209+
);
210+
});
211+
200212
it('renders a link from markdown notation with formatting', () => {
201213
expect(renderMessage('[**doop**](http://www.example.com)')).toBe(
202214
'<a href="http://www.example.com" target="_blank" rel="nofollow noopener noreferrer" data-md-link="true" data-uie-name="markdown-link"><strong>doop</strong></a>',

src/script/util/messageRenderer.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@ const markdownit = new MarkdownIt('zero', {
5959
'blockquote',
6060
]);
6161

62+
markdownit.linkify.add('wire:', {
63+
validate: (text, pos) => {
64+
// Typical linkify schema: valid url chars to first whitespace or control char
65+
const tail = text.slice(pos);
66+
67+
// A simple matcher: up to the first space, <, or a parenthesis.
68+
const match = /^[^\s<>()]+/.exec(tail);
69+
if (match) {
70+
return match[0].length;
71+
}
72+
return 0;
73+
},
74+
normalize: match => {
75+
// match.url has the form ‘wire:/...’; replace it with ‘wire://...’ if needed
76+
if (match.url.startsWith('wire:/') && !match.url.startsWith('wire://')) {
77+
match.url = match.url.replace('wire:/', 'wire://');
78+
}
79+
},
80+
});
81+
6282
const originalFenceRule = markdownit.renderer.rules.fence!;
6383

6484
markdownit.renderer.rules.heading_open = (tokens, idx) => {

0 commit comments

Comments
 (0)