mirror of
https://github.com/turboderp-org/exui.git
synced 2026-04-21 14:59:23 +00:00
Prevent HTML tags from rendering in code blocks
This commit is contained in:
@@ -11,11 +11,21 @@ import * as roles from "./roles.js";
|
||||
|
||||
const renderer = new marked.Renderer();
|
||||
|
||||
function escapeHTML(html) {
|
||||
return html
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
renderer.code = function(code, infostring, escaped) {
|
||||
const uniqueId = `copy-${Math.random().toString(16).slice(2)}`;
|
||||
let escapedCode = escapeHTML(code);
|
||||
return `
|
||||
<div class="code-block">
|
||||
<pre><code>${code}</code></pre>
|
||||
<pre><code>${escapedCode}</code></pre>
|
||||
<button id="${uniqueId}" data-clipboard-text="${escape(code)}" class="copy-btn">🗎 Copy</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user