Skip to content

Commit db6cda6

Browse files
committed
escape html in sidebar
1 parent dad6a09 commit db6cda6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

scripts/static/js/sidebar.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function showSidebarContent(d, fromHover = false) {
4949
// Helper to render tab content
5050
function renderSidebarTabContent(tabName, d, children) {
5151
if (tabName === 'Code') {
52-
return `<pre class="sidebar-code-pre">${d.code}</pre>`;
52+
return `<pre class="sidebar-code-pre">${escapeHtml(d.code)}</pre>`;
5353
}
5454
if (tabName === 'Prompts') {
5555
// Prompt select logic
@@ -328,4 +328,15 @@ export function openInNewTab(event, d) {
328328

329329
export function setSidebarSticky(val) {
330330
sidebarSticky = val;
331+
}
332+
333+
// Helper to escape HTML so code can be shown verbatim inside <pre>
334+
function escapeHtml(str) {
335+
if (str === undefined || str === null) return '';
336+
return String(str)
337+
.replace(/&/g, '&amp;')
338+
.replace(/</g, '&lt;')
339+
.replace(/>/g, '&gt;')
340+
.replace(/"/g, '&quot;')
341+
.replace(/'/g, '&#39;');
331342
}

0 commit comments

Comments
 (0)