Skip to content

Commit 06ee336

Browse files
authored
Update index.html
markdown again, b/c it's so useful and img tags working
1 parent 80134c3 commit 06ee336

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

index.html

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ <h1>HTMLChat</h1>
317317
<div id="chat" class="chat-box"></div>
318318
<div class="input-area">
319319
<div id="chat-form" class="input-container">
320-
<input id="msg" class="msg-input" placeholder="Type message here..." maxlength="200" />
320+
<input id="msg" class="msg-input" placeholder="Type message here..." maxlength="1000" />
321321
<button type="button" class="send-btn" id="send-btn">Send</button>
322322
</div>
323323
</div>
@@ -342,7 +342,8 @@ <h1>HTMLChat</h1>
342342

343343
<!-- External dependencies -->
344344
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.0.5/purify.min.js"></script>
345-
345+
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
346+
346347
<script>
347348
// Global variables
348349
let refreshTimer = null;
@@ -351,15 +352,25 @@ <h1>HTMLChat</h1>
351352
let lastMessageTime = 0;
352353
let lastFetchTime = 0;
353354

354-
// Simple text processing (no markdown for retro feel)
355355
function processText(text) {
356-
// Basic URL detection and linking
357-
const urlRegex = /(https?:\/\/[^\s]+)/g;
358-
let processed = DOMPurify.sanitize(text);
359-
processed = processed.replace(urlRegex, '<a href="$1" target="_blank" style="color:#0066cc">$1</a>');
360-
return processed;
356+
// 1. Convert Markdown to HTML
357+
let html = marked.parse(text);
358+
359+
// 2. Sanitize the HTML to prevent XSS
360+
html = DOMPurify.sanitize(html, {
361+
ALLOWED_TAGS: [
362+
'b','i','em','strong','u','a','p','ul','ol','li','code',
363+
'pre','img','h1','h2','h3','h4','h5','h6','br','span','div'
364+
],
365+
ALLOWED_ATTR: ['href','src','alt','title','target','style']
366+
});
367+
368+
// 3. convert remaining plain URLs (not inside tags) into clickable links
369+
html = html.replace(/(?<!["'>])\bhttps?:\/\/[^\s<]+/g, '<a href="$&" target="_blank" style="color:#0066cc">$&</a>');
370+
371+
return html;
361372
}
362-
373+
363374
// Simple color assignment
364375
const userColors = [
365376
'#cc0000', '#00cc00', '#0000cc', '#cc6600', '#cc00cc',

0 commit comments

Comments
 (0)