-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fff57ab
Add support for thinking models
JovenSoh 9135c8a
Resolve merge conflicts
JovenSoh d8c580f
[autofix.ci] apply automated fixes
autofix-ci[bot] 53d69c9
Update ThinkBlock Syntax
JovenSoh ae81191
update: custom html tag
liangfung ffc35ea
update: rename
liangfung 0b23c68
update: split into two constant arrays
liangfung bf1eac0
update: pnpm lock
liangfung 9a9b4be
update: revert files
liangfung 8aa16bb
update
liangfung 414ac2f
update
liangfung 99bb34a
[autofix.ci] apply automated fixes
autofix-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 28 additions & 0 deletions
28
ee/tabby-ui/components/message-markdown/custom-strip-tags-plugin.ts
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,28 @@ | ||
import type { Root } from 'hast' | ||
import type { Raw } from 'react-markdown/lib/ast-to-react' | ||
import { visit } from 'unist-util-visit' | ||
|
||
function createTagFilterExpression(tagNames: string[]): RegExp { | ||
const escapedTags = tagNames | ||
.map(tag => tag.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')) | ||
.join('|') | ||
return new RegExp( | ||
`<(/?)(?!/?(${escapedTags}))([^>]*)(?=[\\t\\n\\f\\r />])`, | ||
'gi' | ||
) | ||
} | ||
|
||
/** | ||
* Escape HTML tags that are not in tagNames | ||
*/ | ||
export function customStripTagsPlugin({ tagNames }: { tagNames: string[] }) { | ||
// const tagFilterExpression = /<(\/?)(?!\/?(think))([^>]*)(?=[\t\n\f\r />])/gi | ||
const tagFilterExpression = createTagFilterExpression(tagNames) | ||
|
||
return function (tree: Root) { | ||
visit(tree, 'raw', (node: Raw) => { | ||
node.value = node.value.replace(tagFilterExpression, '<$2$3') | ||
}) | ||
return tree | ||
} | ||
} |
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,3 +1,5 @@ | ||
export * as regex from './regex' | ||
|
||
export const PLACEHOLDER_EMAIL_FORM = '[email protected]' | ||
|
||
export const DEFAULT_PAGE_SIZE = 20 | ||
|
@@ -8,8 +10,9 @@ export const SESSION_STORAGE_KEY = { | |
|
||
export const SLUG_TITLE_MAX_LENGTH = 48 | ||
|
||
export * as regex from './regex' | ||
|
||
export const ERROR_CODE_NOT_FOUND = 'NOT_FOUND' | ||
|
||
export const NEWLINE_CHARACTER = '\n' | ||
|
||
export const CUSTOM_HTML_BLOCK_TAGS = ['think'] as const | ||
export const CUSTOM_HTML_INLINE_TAGS = [] as const |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[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').
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.