Skip to content

Commit fd48fb1

Browse files
authored
add links to console output (#967)
1 parent a82171f commit fd48fb1

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

packages/repl/src/lib/Output/console/ConsoleLine.svelte

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@
9797
9898
return formatted;
9999
}
100+
101+
const chars: Record<string, string> = {
102+
'&': '&amp;',
103+
'<': '&lt;',
104+
'>': '&gt;'
105+
};
106+
107+
function escape_html(html: string) {
108+
return html.replace(/[&<>]/g, (c) => chars[c]);
109+
}
110+
111+
function link(str: string) {
112+
return str.replace(
113+
/(http|ftp|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])/g,
114+
(m) => `<a target="_blank" href="${m}">${m}</a>`
115+
);
116+
}
100117
</script>
101118

102119
{#if log.command === 'table'}
@@ -108,7 +125,7 @@
108125
<div
109126
role="button"
110127
tabindex="0"
111-
on:click={toggle_group_collapse}
128+
onclick={toggle_group_collapse}
112129
class="log"
113130
class:expandable={log.stack || log.command === 'group'}
114131
>
@@ -135,7 +152,10 @@
135152
{/if}{#if part.type === 'value'}
136153
<JSONNode value={part.value} defaultExpandedLevel={log.expanded ? 1 : 0} />
137154
{:else}
138-
<span class="styled" style={part.style}>{part.value}</span>
155+
<!-- svelte-ignore a11y_no_static_element_interactions -->
156+
<span class="styled" style={part.style} onclick={(e) => e.stopPropagation()}>
157+
{@html link(escape_html(part.value))}
158+
</span>
139159
{/if}
140160
{/each}
141161
</span>

0 commit comments

Comments
 (0)