Skip to content
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: support markdown on user message #3848

Merged
merged 8 commits into from
Oct 22, 2024
Merged

feat: support markdown on user message #3848

merged 8 commits into from
Oct 22, 2024

Conversation

urmauur
Copy link
Member

@urmauur urmauur commented Oct 21, 2024

Describe Your Changes

  1. New Rich Editor Component (RichTextEditor.tsx):

    • A new TypeScript file RichTextEditor.tsx is created, which defines a React component for a rich text editor using Slate.js.
    • The component supports basic formatting (bold, italic), inline code blocks, and syntax highlighting for code blocks.
  2. Custom Types for Slate:

    • The slate module declaration is updated to include custom types (CustomElement, CustomText) that extend the default Slate Editor interface.
    • This allows the editor to handle paragraphs, code blocks, and text with formatting attributes.
  3. Initial Value:

    • The initial value for the editor is set to a single paragraph element with an empty text field.
  4. Decorate Function:

    • A custom decorate function is implemented to identify code blocks and apply styles (bold, italic) to text ranges.
    • It also handles syntax highlighting for inline and block code using highlight.js.
  5. RenderLeaf Function:

    • The renderLeaf function applies the formatting and styling attributes to the text elements in the editor.
  6. Event Handling:

    • Key handlers like onKeyDown are implemented to handle specific key events (e.g., Enter, Tab) for inserting new lines, toggling code blocks, and handling tab indentation.
    • The component also handles state updates and side effects such as focusing the textarea and adjusting its height.
  7. Styling:

    • The RichEditor component includes various CSS classes to style the editor and its content, including syntax highlighting for different programming languages.
  8. Integration with Existing Components:

    • The ChatInput.tsx file is modified to use the new RichTextEditor component instead of the old CodeEditor.
    • The RichEditor component is configured with options such as className, style, placeholder, and spellCheck.
  9. Code Refactoring:

    • The old TextArea component is commented out in favor of the new RichEditor.
    • Various refactoring and clean-up are done throughout the codebase to integrate the new editor seamlessly with existing components and logic.

These changes significantly enhance the text editing capabilities of the application, allowing for more complex and formatted text input, including support for code blocks with syntax highlighting.

Fixes Issues

  • Support for inline syntax highlighting in the chat input box:
    • Code enclosed within triple backticks (```) will be highlighted for syntax.
    • The chat user’s message will render with the appropriate code syntax highlighting.
Screenshot 2024-10-21 at 12 40 05 Screenshot 2024-10-21 at 12 38 32 Screenshot 2024-10-21 at 12 38 03 Screenshot 2024-10-21 at 12 49 52
  • Support for inline text formatting (bold and italic) in the chat input box:
    • Users can apply bold and italic formatting directly within the input box.
    • The chat user’s message will display the correctly formatted text.
Screenshot 2024-10-21 at 12 52 07 Screenshot 2024-10-21 at 12 52 39
  • Chat user support all markdown
    • Code blocks with syntax highlighting
    • Lists (ordered and unordered)
    • Bold and italic text
    • Links
    • Blockquotes
Screenshot 2024-10-21 at 12 53 23 Screenshot 2024-10-21 at 12 53 43 Screenshot 2024-10-21 at 13 02 48 Screenshot 2024-10-21 at 13 03 15

Note: The reason we only support syntax highlighting and text formatting (bold and italic) in the chat input is to avoid making the input box interface cluttered or unattractive. For example, rendering blockquotes inside the chat input would lead to a messy and visually unappealing interface.

Self Checklist

  • Added relevant comments, esp in complex areas
  • Updated docs (for bug fixes / features)
  • Created issues for follow-up changes or refactoring needed

@urmauur urmauur added the type: feature request A new feature label Oct 21, 2024
@urmauur urmauur added this to the v0.5.7 milestone Oct 21, 2024
@urmauur urmauur self-assigned this Oct 21, 2024
@imtuyethan
Copy link
Contributor

Works well on my end.

Copy link
Contributor

@louis-jan louis-jan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@urmauur urmauur merged commit 9867634 into dev Oct 22, 2024
24 of 30 checks passed
@urmauur urmauur deleted the feat/markdown-render branch October 22, 2024 08:44
@dan-homebrew
Copy link
Contributor

Thanks @urmauur, this looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

idea: Add markdown rendering support to Jan feat: render code, indents, markdown for user inputs
4 participants