Update index.html
Browse files- index.html +22 -103
index.html
CHANGED
@@ -465,7 +465,7 @@
|
|
465 |
<script>
|
466 |
const userInput = document.getElementById('user-input');
|
467 |
const sendBtn = document.getElementById('send-btn');
|
468 |
-
const chatOutput = document.
|
469 |
let messages = [];
|
470 |
|
471 |
async function sendMessage() {
|
@@ -488,87 +488,33 @@
|
|
488 |
}
|
489 |
}
|
490 |
|
491 |
-
|
492 |
-
|
|
|
493 |
|
494 |
-
|
495 |
-
|
496 |
-
messageElement.classList.add('message', `${role}-message`);
|
497 |
|
498 |
-
|
499 |
-
|
500 |
-
const inlineCodeRegex = /`([^`]+?)`/g;
|
501 |
-
const htmlTagRegex = /<[^>]+>/g;
|
502 |
-
const jsCodeRegex = /\b(function|if|else|for|while|do|switch|case|break|continue|return|try|catch|finally|throw)\b/g;
|
503 |
-
const jsCommentRegex = /\/\/.*|\/\*[\s\S]*?\*\//g;
|
504 |
-
const cssCodeRegex = /[^{};]+\s*{\s*[^{}]*}/g;
|
505 |
-
const cssCommentRegex = /\/\*[\s\S]*?\*\//g;
|
506 |
|
507 |
-
|
508 |
-
|
509 |
-
const codeBlock = document.createElement('code');
|
510 |
-
if (language) {
|
511 |
-
codeBlock.classList.add(`language-${language}`);
|
512 |
}
|
513 |
-
codeBlock.textContent = code;
|
514 |
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
matches.forEach(match => {
|
528 |
-
const codeBlock = createCodeBlock(language, match);
|
529 |
-
messageElement.appendChild(codeBlock);
|
530 |
-
});
|
531 |
-
}
|
532 |
-
}
|
533 |
-
|
534 |
-
// Process code block matches
|
535 |
-
let lastIndex = 0;
|
536 |
-
let match;
|
537 |
-
while ((match = codeBlockRegex.exec(message)) !== null) {
|
538 |
-
if (match.index > lastIndex) {
|
539 |
-
const textBeforeCode = document.createTextNode(message.substring(lastIndex, match.index));
|
540 |
-
messageElement.appendChild(textBeforeCode);
|
541 |
-
}
|
542 |
-
|
543 |
-
const language = match[1] ? match[1].toLowerCase() : null;
|
544 |
-
const codeContent = match[2];
|
545 |
-
const codeBlock = createCodeBlock(language, codeContent);
|
546 |
-
messageElement.appendChild(codeBlock);
|
547 |
-
|
548 |
-
lastIndex = match.index + match[0].length;
|
549 |
-
}
|
550 |
-
|
551 |
-
// Process inline code matches
|
552 |
-
processCodeMatches(message.match(inlineCodeRegex), null);
|
553 |
-
|
554 |
-
// Process specific code structures
|
555 |
-
processCodeMatches(message.match(htmlTagRegex), 'html');
|
556 |
-
processCodeMatches(message.match(jsCodeRegex), 'javascript');
|
557 |
-
processCodeMatches(message.match(jsCommentRegex), 'javascript-comment');
|
558 |
-
processCodeMatches(message.match(cssCodeRegex), 'css');
|
559 |
-
processCodeMatches(message.match(cssCommentRegex), 'css-comment');
|
560 |
-
|
561 |
-
// Add any remaining text after the last code block
|
562 |
-
if (lastIndex < message.length) {
|
563 |
-
const textAfterCode = document.createTextNode(message.substring(lastIndex));
|
564 |
-
messageElement.appendChild(textAfterCode);
|
565 |
}
|
566 |
-
|
567 |
-
chatOutput.appendChild(messageElement);
|
568 |
-
chatOutput.scrollTop = chatOutput.scrollHeight;
|
569 |
-
}
|
570 |
-
|
571 |
-
|
572 |
sendBtn.addEventListener('click', async () => {
|
573 |
const message = userInput.value.trim();
|
574 |
if (message !== '') {
|
@@ -586,33 +532,6 @@ function displayMessage(message, role) {
|
|
586 |
sendBtn.click();
|
587 |
}
|
588 |
});
|
589 |
-
function displayMessage(message, role) {
|
590 |
-
const messageElement = document.createElement('div');
|
591 |
-
messageElement.classList.add('message', `${role}-message`);
|
592 |
-
|
593 |
-
// Parse Markdown syntax
|
594 |
-
const markdownParsedMessage = parseMarkdown(message);
|
595 |
-
|
596 |
-
// Set HTML content
|
597 |
-
messageElement.innerHTML = markdownParsedMessage;
|
598 |
-
|
599 |
-
chatOutput.appendChild(messageElement);
|
600 |
-
chatOutput.scrollTop = chatOutput.scrollHeight;
|
601 |
-
}
|
602 |
-
|
603 |
-
function parseMarkdown(message) {
|
604 |
-
// Initialize Showdown converter
|
605 |
-
const converter = new showdown.Converter({
|
606 |
-
// Enable all Markdown extensions
|
607 |
-
simplifiedAutoLink: true,
|
608 |
-
strikethrough: true,
|
609 |
-
tables: true,
|
610 |
-
tasklists: true,
|
611 |
-
literalMidWordUnderscores: true,
|
612 |
-
});
|
613 |
-
// Convert Markdown to HTML
|
614 |
-
return converter.makeHtml(message);
|
615 |
-
}
|
616 |
</script>
|
617 |
|
618 |
</body>
|
|
|
465 |
<script>
|
466 |
const userInput = document.getElementById('user-input');
|
467 |
const sendBtn = document.getElementById('send-btn');
|
468 |
+
const chatOutput = document.querySelector('.message-container');
|
469 |
let messages = [];
|
470 |
|
471 |
async function sendMessage() {
|
|
|
488 |
}
|
489 |
}
|
490 |
|
491 |
+
function displayMessage(message, role) {
|
492 |
+
const messageElement = document.createElement('div');
|
493 |
+
messageElement.classList.add('message', `${role}-message`);
|
494 |
|
495 |
+
// Parse Markdown syntax
|
496 |
+
const markdownParsedMessage = parseMarkdown(message);
|
|
|
497 |
|
498 |
+
// Set HTML content
|
499 |
+
messageElement.innerHTML = markdownParsedMessage;
|
|
|
|
|
|
|
|
|
|
|
|
|
500 |
|
501 |
+
chatOutput.appendChild(messageElement);
|
502 |
+
chatOutput.scrollTop = chatOutput.scrollHeight;
|
|
|
|
|
|
|
503 |
}
|
|
|
504 |
|
505 |
+
function parseMarkdown(message) {
|
506 |
+
// Initialize Showdown converter
|
507 |
+
const converter = new showdown.Converter({
|
508 |
+
// Enable all Markdown extensions
|
509 |
+
simplifiedAutoLink: true,
|
510 |
+
strikethrough: true,
|
511 |
+
tables: true,
|
512 |
+
tasklists: true,
|
513 |
+
literalMidWordUnderscores: true,
|
514 |
+
});
|
515 |
+
// Convert Markdown to HTML
|
516 |
+
return converter.makeHtml(message);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
517 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
518 |
sendBtn.addEventListener('click', async () => {
|
519 |
const message = userInput.value.trim();
|
520 |
if (message !== '') {
|
|
|
532 |
sendBtn.click();
|
533 |
}
|
534 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
535 |
</script>
|
536 |
|
537 |
</body>
|