-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: updated ChatInput to a WYSIWYG editor to support Markdown and Codeblocks #1562
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this PR, thanks a lot for the contrib, it would make a great addition!
A couple of comments:
-
When we apply markdown like italic, bold or even code blocks, it looks like they get removed in the sent message and only text is sent. (
*Hi*
becomesHi
in the prompt) I think a lot of people expect markdown elements to be passed to the LLM, so would it be possible to pass them directly? -
Love the code blocks, but i was a bit confused by the behaviour for starting them. If i start a codeblock with ``` and then exit it by going down with the arrow, if I start another codeblock with ``` and then shift+enter, it doesnt start a codeblock.
-
Would be nice to support inline code like
this
too if possible -
Could we extract the editor component into a separate component? I think there's a few other places in the app where we would need this functionality and it would be nice to reuse the same editor everywhere.
-
Would it be easy to reuse the same style we use for highlight.js already for consistency? https://github.com/Mounayer/chat-ui/blob/e06910495bf7773a9f25b4c4be416c9c8effe12a/src/styles/highlight-js.css#L1-L2
Overall this is super nice, if you think we could get those changes in that would be great, let me know if you need help on those. 🚀
Thank you for your review @nsarrazin , let me address your requests:
I'll work on these changes at once, thanks again for your review, and I'd appreciate if you could provide more information regarding the first point! |
Hey @nsarrazin ! I have updated the following:
Matter of fact, it now looks identical to claude's: Now the one thing I haven't touched yet is your last comment, which is regarding sending Either way, I'm really happy to help, this was so much fun! And please, should you have any suggestions and/or ideas to improve, let me know! |
Hey @Mounayer thanks for adding the changes looks great! Couple more things:
Love the new style thanks 😁 |
Glad to help!
|
Hi @nsarrazin ! This was much easier than expected, gotta love how many extensions there are for I also read through the tiptap docs and found a built-in function that not only empties the entire document, but also emits an update event! So now it should be working as expected (hopefully!) Here are some images of the behvavior: And the result (what is being sent): I'm also going to try and figure out if there's anything we missed while waiting your response! |
I've tested quite a lot and used more than one model, it works great, there is just one thing I've noticed. Newlines translate to |
Description
Closes #1545
Closes #1592
Updated the ChatInput component from using a
textarea
element into using aWYSIWYG
editor by tiptap.I first of all compared and contrasted all candidate tools for this task, and found that
tiptap
is the mostsvelte
compatible out of them, additionally,tiptap
is well supported and maintained.I made sure to preserve the original functionality, everything behaves the same, including placeholders, and text submit. Any data submitted by the user is regular text. I reviewed how Claude works, and made sure the features implemented are very similar. Additionally, I also made sure to only include
bold
,italic
, andcodeblocks
. For future references,tiptap
also supports a bunch of other functionalities, such asimages
,tables
, and others...I also resulted to using lowlight for syntax highlighting which is based on highlight.js, particularly because
tiptap
has an extension that directly supportslowlight
in its code blocks! So now the code blocks look clean and flashy!I also fixed an issue in the MarkdownRenderer where markdown was being interpreted as a string rather than rendered html:
This was being caused by the
escapeHTML
function in theMarkdownRenderer
which wasn't really needed since sanitization was being applied later on!Examples
I also made sure it is resizable and works on various screen sizes (if you really want to open up a codeblock and code in it on phone)
User messages:
Usage
Upgraded features include:
ctrl + b
before writing bolds a wordctrl + i
before writing italicizes a wordMarkdownRenderer
and editableTesting
To test, I recommend trying all of the above mentioned features out. Try to italicize and bold at the same time, open code blocks, etc..
This is my first time working with Svelte, so let me know if any suggestions arise!