-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from zamm-dev/markdown-chat
Add Markdown rendering for chat messages
- Loading branch information
Showing
18 changed files
with
224 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-2 KB
(96%)
...elte/screenshots/baseline/screens/chat/conversation/bottom-scroll-indicator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-926 Bytes
(97%)
src-svelte/screenshots/baseline/screens/chat/conversation/full-message-width.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+50 KB
...lte/screenshots/baseline/screens/chat/conversation/multiline-chat-variant-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.58 KB
(110%)
src-svelte/screenshots/baseline/screens/chat/conversation/multiline-chat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+277 Bytes
(100%)
src-svelte/screenshots/baseline/screens/chat/conversation/not-empty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-134 Bytes
(99%)
src-svelte/screenshots/baseline/screens/chat/message/ai-multiline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.1 KB
src-svelte/screenshots/baseline/screens/chat/message/code-variant-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<script lang="ts"> | ||
import Highlight from "svelte-highlight"; | ||
import bash from "svelte-highlight/languages/bash"; | ||
import javascript from "svelte-highlight/languages/javascript"; | ||
import typescript from "svelte-highlight/languages/typescript"; | ||
import rust from "svelte-highlight/languages/rust"; | ||
import python from "svelte-highlight/languages/python"; | ||
import plaintext from "svelte-highlight/languages/plaintext"; | ||
import "svelte-highlight/styles/github.css"; | ||
export let text: string; | ||
export let lang: string; | ||
function getLanguageStr() { | ||
if (lang) { | ||
return lang.split(" ")[0]; | ||
} | ||
return "plaintext"; | ||
} | ||
function getLanguage() { | ||
let languageStr = getLanguageStr(); | ||
switch (languageStr) { | ||
case "sh": | ||
case "bash": | ||
return bash; | ||
case "js": | ||
case "javascript": | ||
return javascript; | ||
case "typescript": | ||
return typescript; | ||
case "rust": | ||
return rust; | ||
case "py": | ||
case "python": | ||
return python; | ||
default: | ||
return plaintext; | ||
} | ||
} | ||
let language = getLanguage(); | ||
</script> | ||
|
||
<div class="code"> | ||
<Highlight {language} code={text} /> | ||
</div> | ||
|
||
<style> | ||
.code { | ||
overflow-x: auto; | ||
box-sizing: border-box; | ||
border-radius: var(--corner-roundness); | ||
background-color: #ffffff88; | ||
} | ||
.code :global(code) { | ||
padding: var(--internal-spacing) 1rem; | ||
background-color: transparent; | ||
font-family: "Inconsolata", monospace; | ||
} | ||
.code, | ||
.code :global(pre), | ||
.code :global(code) { | ||
width: fit-content; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,32 @@ | ||
<script lang="ts"> | ||
import type { ChatMessage } from "$lib/bindings"; | ||
import MessageUI from "./MessageUI.svelte"; | ||
import CodeRender from "./CodeRender.svelte"; | ||
import SvelteMarkdown from "svelte-markdown"; | ||
export let message: ChatMessage; | ||
</script> | ||
|
||
<MessageUI role={message.role} {...$$restProps}> | ||
{message.text} | ||
<div class="markdown"> | ||
<SvelteMarkdown source={message.text} renderers={{ code: CodeRender }} /> | ||
</div> | ||
</MessageUI> | ||
|
||
<style> | ||
.markdown { | ||
width: fit-content; | ||
} | ||
.markdown :global(p) { | ||
margin: var(--internal-spacing) 0; | ||
} | ||
.markdown :global(:first-child) { | ||
margin-top: 0; | ||
} | ||
.markdown :global(:last-child) { | ||
margin-bottom: 0; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.