Skip to content

Commit 69ccd53

Browse files
authored
Merge pull request #65 from Unity-Lab-AI/codex/fix-site-tests-module-not-found-error
Avoid external dependency for site tests
2 parents dc06224 + a1d7b99 commit 69ccd53

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

js/marked.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
export const marked = {
2+
parse(markdown = '') {
3+
const lines = markdown.split('\n');
4+
let html = '';
5+
let inCode = false;
6+
let codeLines = [];
7+
for (let i = 0; i < lines.length; i++) {
8+
const line = lines[i];
9+
if (line.startsWith('```')) {
10+
if (inCode) {
11+
html += `<pre><code>${escapeHtml(codeLines.join('\n'))}</code></pre>`;
12+
inCode = false;
13+
codeLines = [];
14+
} else {
15+
inCode = true;
16+
}
17+
continue;
18+
}
19+
if (inCode) {
20+
codeLines.push(line);
21+
continue;
22+
}
23+
if (line.trim() === '---') {
24+
html += '<hr>';
25+
} else if (line.trim()) {
26+
html += `<p>${escapeHtml(line.trim())}</p>`;
27+
}
28+
}
29+
if (inCode) {
30+
html += `<pre><code>${escapeHtml(codeLines.join('\n'))}</code></pre>`;
31+
}
32+
return html;
33+
}
34+
};
35+
36+
function escapeHtml(str) {
37+
return str.replace(/[&<>"']/g, ch => {
38+
switch (ch) {
39+
case '&': return '&amp;';
40+
case '<': return '&lt;';
41+
case '>': return '&gt;';
42+
case '"': return '&quot;';
43+
case "'": return '&#39;';
44+
default: return ch;
45+
}
46+
});
47+
}
48+

tests/site-ai-response.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { strict as assert } from 'node:assert';
2-
import { marked } from 'marked';
2+
import { marked } from '../js/marked.js';
33
import { sanitizeMarkdown } from '../js/chat/markdown-sanitizer.js';
44
import { PolliClientWeb } from '../js/polliLib/src/client.js';
55
import { generateImageUrl } from '../js/polliLib/src/mcp.js';

tests/site-markdown-sanitization.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { strict as assert } from 'node:assert';
2-
import { marked } from 'marked';
2+
import { marked } from '../js/marked.js';
33
import { sanitizeMarkdown } from '../js/chat/markdown-sanitizer.js';
44

55
const input = [

0 commit comments

Comments
 (0)