fix: handle edge cases syntax highlight (#3969)
This commit is contained in:
parent
fb1fcc573f
commit
8d4734cb8a
@ -95,7 +95,7 @@ const LocalServerRightPanel = () => {
|
|||||||
<div className="mt-2">
|
<div className="mt-2">
|
||||||
<Input
|
<Input
|
||||||
value={selectedModel?.id || ''}
|
value={selectedModel?.id || ''}
|
||||||
className="cursor-pointer text-[hsla(var(--text-secondary))]"
|
className="cursor-pointer text-[hsla(var(--text-secondary))] hover:border-[hsla(var(--app-border))] focus-visible:outline-0 focus-visible:ring-0"
|
||||||
readOnly
|
readOnly
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
clipboard.copy(selectedModel?.id)
|
clipboard.copy(selectedModel?.id)
|
||||||
|
|||||||
@ -132,20 +132,6 @@ const RichTextEditor = ({
|
|||||||
if (Editor.isBlock(editor, node) && node.type === 'paragraph') {
|
if (Editor.isBlock(editor, node) && node.type === 'paragraph') {
|
||||||
node.children.forEach((child: { text: any }, childIndex: number) => {
|
node.children.forEach((child: { text: any }, childIndex: number) => {
|
||||||
const text = child.text
|
const text = child.text
|
||||||
const { selection } = editor
|
|
||||||
|
|
||||||
if (selection) {
|
|
||||||
const selectedNode = Editor.node(editor, selection)
|
|
||||||
|
|
||||||
if (Editor.isBlock(editor, selectedNode[0] as CustomElement)) {
|
|
||||||
const isNodeEmpty = Editor.string(editor, selectedNode[1]) === ''
|
|
||||||
|
|
||||||
if (isNodeEmpty) {
|
|
||||||
// Reset language when a node is cleared
|
|
||||||
currentLanguage.current = 'plaintext'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Match code block start and end
|
// Match code block start and end
|
||||||
const startMatch = text.match(/^```(\w*)$/)
|
const startMatch = text.match(/^```(\w*)$/)
|
||||||
@ -346,6 +332,14 @@ const RichTextEditor = ({
|
|||||||
.join('\n')
|
.join('\n')
|
||||||
|
|
||||||
setCurrentPrompt(combinedText)
|
setCurrentPrompt(combinedText)
|
||||||
|
if (combinedText.trim() === '') {
|
||||||
|
currentLanguage.current = 'plaintext'
|
||||||
|
}
|
||||||
|
const hasCodeBlockStart = combinedText.match(/^```(\w*)/m)
|
||||||
|
// Set language to plaintext if no code block with language identifier is found
|
||||||
|
if (!hasCodeBlockStart) {
|
||||||
|
currentLanguage.current = 'plaintext'
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Editable
|
<Editable
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
.hljs-comment,
|
.hljs-comment,
|
||||||
.hljs-quote {
|
.hljs-quote {
|
||||||
color: #d4d0ab;
|
color: var(--hljs-comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Red */
|
/* Red */
|
||||||
@ -12,7 +12,7 @@
|
|||||||
.hljs-selector-class,
|
.hljs-selector-class,
|
||||||
.hljs-regexp,
|
.hljs-regexp,
|
||||||
.hljs-deletion {
|
.hljs-deletion {
|
||||||
color: #ffa07a;
|
color: var(--hljs-variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Orange */
|
/* Orange */
|
||||||
@ -24,12 +24,12 @@
|
|||||||
.hljs-params,
|
.hljs-params,
|
||||||
.hljs-meta,
|
.hljs-meta,
|
||||||
.hljs-link {
|
.hljs-link {
|
||||||
color: #f5ab35;
|
color: var(--hljs-number);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Yellow */
|
/* Yellow */
|
||||||
.hljs-attribute {
|
.hljs-attribute {
|
||||||
color: #ffd700;
|
color: var(--hljs-attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Green */
|
/* Green */
|
||||||
@ -37,19 +37,19 @@
|
|||||||
.hljs-symbol,
|
.hljs-symbol,
|
||||||
.hljs-bullet,
|
.hljs-bullet,
|
||||||
.hljs-addition {
|
.hljs-addition {
|
||||||
color: #abe338;
|
color: var(--hljs-string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Blue */
|
/* Blue */
|
||||||
.hljs-title,
|
.hljs-title,
|
||||||
.hljs-section {
|
.hljs-section {
|
||||||
color: #00e0e0;
|
color: var(--hljs-title);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Purple */
|
/* Purple */
|
||||||
.hljs-keyword,
|
.hljs-keyword,
|
||||||
.hljs-selector-tag {
|
.hljs-selector-tag {
|
||||||
color: #dcc6e0;
|
color: var(--hljs-keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
.hljs {
|
.hljs {
|
||||||
|
|||||||
@ -40,6 +40,14 @@
|
|||||||
--text-secondary: 0, 0%, 0%, 0.6;
|
--text-secondary: 0, 0%, 0%, 0.6;
|
||||||
--text-tertiary: 0, 0%, 0%, 0.4;
|
--text-tertiary: 0, 0%, 0%, 0.4;
|
||||||
--text-quaternary: 0, 0%, 0%, 0.2;
|
--text-quaternary: 0, 0%, 0%, 0.2;
|
||||||
|
|
||||||
|
--hljs-comment: #6e7781;
|
||||||
|
--hljs-variable: #cf222e;
|
||||||
|
--hljs-number: #bc4c00;
|
||||||
|
--hljs-attribute: #b58407;
|
||||||
|
--hljs-string: #116329;
|
||||||
|
--hljs-title: #0550ae;
|
||||||
|
--hljs-keyword: #8250df;
|
||||||
}
|
}
|
||||||
|
|
||||||
html.dark {
|
html.dark {
|
||||||
@ -68,4 +76,12 @@ html.dark {
|
|||||||
--text-secondary: 0, 0%, 68%, 1;
|
--text-secondary: 0, 0%, 68%, 1;
|
||||||
--text-tertiary: 0, 0%, 68%, 0.4;
|
--text-tertiary: 0, 0%, 68%, 0.4;
|
||||||
--text-quaternary: 0, 0%, 68%, 0.2;
|
--text-quaternary: 0, 0%, 68%, 0.2;
|
||||||
|
|
||||||
|
--hljs-comment: #8b949e;
|
||||||
|
--hljs-variable: #ff7b72;
|
||||||
|
--hljs-number: #f0883e;
|
||||||
|
--hljs-attribute: #ffa657;
|
||||||
|
--hljs-string: #7ee787;
|
||||||
|
--hljs-title: #79c0ff;
|
||||||
|
--hljs-keyword: #d2a8ff;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user