Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/client/adapters/webcontainer/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WebContainer } from '@webcontainer/api';
import base64 from 'base64-js';
import AnsiToHtml from 'ansi-to-html';
import { get_depth } from '../../../utils.js';
import { escape_html, get_depth } from '../../../utils.js';
import { ready } from '../common/index.js';

const converter = new AnsiToHtml({
Expand Down Expand Up @@ -59,7 +59,7 @@ export async function create(base, error, progress, logs) {
// clear screen
logs.set([]);
} else {
const log = converter.toHtml(chunk);
const log = converter.toHtml(escape_html(chunk));
logs.update(($logs) => [...$logs, log]);
}
}
Expand Down
17 changes: 3 additions & 14 deletions src/lib/server/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'prismjs/components/prism-diff.js';
import 'prismjs/components/prism-typescript.js';
import 'prism-svelte';
import { marked } from 'marked';
import { escape_html } from '$lib/utils';

const languages = {
bash: 'bash',
Expand All @@ -17,18 +18,6 @@ const languages = {
'': ''
};

/** @type {Record<string, string>} */
const chars = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;'
};

/** @param {string} html */
function escape(html) {
return html.replace(/[&<>]/g, (c) => chars[c]);
}

const delimiter_substitutes = {
'+++': ' ',
'---': ' ',
Expand Down Expand Up @@ -84,7 +73,7 @@ const default_renderer = {

return {
type,
content: escape(content)
content: escape_html(content)
};
});

Expand All @@ -99,7 +88,7 @@ const default_renderer = {
const plang = languages[lang];
const highlighted = plang
? PrismJS.highlight(source, PrismJS.languages[plang], language)
: escape(source);
: escape_html(source);

html = `<div class="code-block">${
options.file ? `<span class="filename">${options.file}</span>` : ''
Expand Down
12 changes: 12 additions & 0 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@
export function get_depth(name) {
return name.split('/').length - 1;
}

/** @type {Record<string, string>} */
const chars = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;'
};

/** @param {string} html */
export function escape_html(html) {
return html.replace(/[&<>]/g, (c) => chars[c]);
}