Spaces:
Running
Running
Update playground.html
Browse files- playground.html +84 -5
playground.html
CHANGED
@@ -547,6 +547,76 @@
|
|
547 |
opacity: 1;
|
548 |
}
|
549 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
550 |
</style>
|
551 |
</head>
|
552 |
|
@@ -791,12 +861,21 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
791 |
}
|
792 |
}
|
793 |
|
794 |
-
|
795 |
const formattedContent = content
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
800 |
|
801 |
currentStreamingMessage.innerHTML += formattedContent;
|
802 |
|
|
|
547 |
opacity: 1;
|
548 |
}
|
549 |
}
|
550 |
+
/* markdown */
|
551 |
+
/* Add this to your style section */
|
552 |
+
.message pre {
|
553 |
+
background-color: rgba(15, 15, 30, 0.6);
|
554 |
+
padding: 10px;
|
555 |
+
border-radius: 6px;
|
556 |
+
overflow-x: auto;
|
557 |
+
margin: 10px 0;
|
558 |
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
559 |
+
}
|
560 |
+
|
561 |
+
.message code {
|
562 |
+
font-family: 'JetBrains Mono', monospace;
|
563 |
+
font-size: 12px;
|
564 |
+
background-color: rgba(30, 30, 50, 0.3);
|
565 |
+
padding: 2px 4px;
|
566 |
+
border-radius: 3px;
|
567 |
+
}
|
568 |
+
|
569 |
+
.message pre code {
|
570 |
+
background-color: transparent;
|
571 |
+
padding: 0;
|
572 |
+
}
|
573 |
+
|
574 |
+
.message blockquote {
|
575 |
+
border-left: 3px solid var(--primary-blue);
|
576 |
+
padding-left: 10px;
|
577 |
+
margin: 10px 0;
|
578 |
+
color: var(--text-muted);
|
579 |
+
}
|
580 |
+
|
581 |
+
.message h1, .message h2, .message h3 {
|
582 |
+
margin: 15px 0 5px 0;
|
583 |
+
}
|
584 |
+
|
585 |
+
.message ul, .message ol {
|
586 |
+
margin-left: 20px;
|
587 |
+
margin-bottom: 8px;
|
588 |
+
}
|
589 |
+
|
590 |
+
.message a {
|
591 |
+
color: var(--primary-blue);
|
592 |
+
text-decoration: underline;
|
593 |
+
}
|
594 |
+
|
595 |
+
.message p {
|
596 |
+
margin-bottom: 8px;
|
597 |
+
}
|
598 |
+
|
599 |
+
.message img {
|
600 |
+
max-width: 100%;
|
601 |
+
border-radius: 8px;
|
602 |
+
margin: 10px 0;
|
603 |
+
}
|
604 |
+
|
605 |
+
.message table {
|
606 |
+
border-collapse: collapse;
|
607 |
+
width: 100%;
|
608 |
+
margin: 15px 0;
|
609 |
+
}
|
610 |
+
|
611 |
+
.message th, .message td {
|
612 |
+
border: 1px solid var(--border-color);
|
613 |
+
padding: 8px;
|
614 |
+
text-align: left;
|
615 |
+
}
|
616 |
+
|
617 |
+
.message th {
|
618 |
+
background-color: rgba(15, 15, 30, 0.6);
|
619 |
+
}
|
620 |
</style>
|
621 |
</head>
|
622 |
|
|
|
861 |
}
|
862 |
}
|
863 |
|
864 |
+
// Replace the existing formatting code in the appendMessage function
|
865 |
const formattedContent = content
|
866 |
+
.replace(/```([\s\S]*?)```/g, (match, code) => `<pre><code>${code}</code></pre>`)
|
867 |
+
.replace(/`([^`]+)`/g, '<code>$1</code>')
|
868 |
+
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
869 |
+
.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
870 |
+
.replace(/~~(.*?)~~/g, '<del>$1</del>')
|
871 |
+
.replace(/\[(.*?)\]\((.*?)\)/g, '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>')
|
872 |
+
.replace(/^#{3}\s+(.*?)$/gm, '<h3>$1</h3>')
|
873 |
+
.replace(/^#{2}\s+(.*?)$/gm, '<h2>$1</h2>')
|
874 |
+
.replace(/^#{1}\s+(.*?)$/gm, '<h1>$1</h1>')
|
875 |
+
.replace(/^\>\s+(.*?)$/gm, '<blockquote>$1</blockquote>')
|
876 |
+
.replace(/^(\d+)\.\s+(.*?)$/gm, '<ol start="$1"><li>$2</li></ol>')
|
877 |
+
.replace(/^[-*]\s+(.*?)$/gm, '<ul><li>$1</li></ul>')
|
878 |
+
.replace(/\n/g, '<br>');
|
879 |
|
880 |
currentStreamingMessage.innerHTML += formattedContent;
|
881 |
|