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(ui): add support for custom html tag rendering in markdown #4091

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

liangfung
Copy link
Collaborator

@liangfung liangfung commented Mar 31, 2025

based on #4075

cc @JovenSoh

@liangfung liangfung requested a review from Copilot March 31, 2025 10:48
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for custom HTML tag rendering in Markdown by introducing new functionality for formatting tags and integrating custom tag handling in Markdown components. Key changes include:

  • A new utility function to format custom markdown tags in chat messages.
  • Addition of a custom strip tags plugin to escape non-whitelisted HTML tags.
  • Updates to Markdown and MessageMarkdown components to integrate the new custom tag handling.

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ee/tabby-ui/lib/utils/chat.ts Added formatMarkdownCustomTags function to adjust newlines for custom HTML tags.
ee/tabby-ui/lib/constants/index.ts Added MARKDOWN_CUSTOM_TAGS constant for whitelisting custom markdown tags.
ee/tabby-ui/components/message-markdown/index.tsx Integrated custom tag formatting and added a custom React component for rendering 'think'.
ee/tabby-ui/components/message-markdown/custom-strip-tags-plugin.ts Introduced a plugin to escape HTML tags not in the whitelist.
ee/tabby-ui/components/markdown.tsx Extended markdown options to support custom HTML tag rendering.
Files not reviewed (1)
  • ee/tabby-ui/package.json: Language not supported

export function customStripTagsPlugin() {
return function (tree: Root) {
visit(tree, 'raw', (node: Raw) => {
node.value = node.value.replace(tagFilterExpression, '<$2$3')
Copy link
Preview

Copilot AI Mar 31, 2025

Choose a reason for hiding this comment

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

[nitpick] The replacement string omits the leading slash captured as group1, which may lead to incorrect escaping of closing tags. Consider changing the replacement to include group1 (e.g., '<$1$3').

Suggested change
node.value = node.value.replace(tagFilterExpression, '&lt;$2$3')
node.value = node.value.replace(tagFilterExpression, '&lt;$1$2$3')

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

@liangfung liangfung force-pushed the feat-ui-support-custom-html-tag-rendering branch from bd1fa35 to a8dac96 Compare March 31, 2025 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants