mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-13 11:26:18 +01:00
🪄 fix: Code Block handling in Artifact Updates (#11417)
Some checks are pending
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Waiting to run
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Waiting to run
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Waiting to run
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Waiting to run
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Waiting to run
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Blocked by required conditions
Some checks are pending
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Waiting to run
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Waiting to run
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Waiting to run
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Waiting to run
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Waiting to run
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Blocked by required conditions
* Improved detection of code blocks to support both language identifiers and plain code fences. * Updated tests to cover various scenarios, including edge cases with different language identifiers and multiline content. * Ensured proper handling of code blocks with trailing whitespace and complex syntax.
This commit is contained in:
parent
4a1d2b0d94
commit
e509ba5be0
2 changed files with 277 additions and 4 deletions
|
|
@ -73,15 +73,25 @@ const replaceArtifactContent = (originalText, artifact, original, updated) => {
|
|||
return null;
|
||||
}
|
||||
|
||||
// Check if there are code blocks
|
||||
const codeBlockStart = artifactContent.indexOf('```\n', contentStart);
|
||||
// Check if there are code blocks - handle both ```\n and ```lang\n formats
|
||||
let codeBlockStart = artifactContent.indexOf('```', contentStart);
|
||||
const codeBlockEnd = artifactContent.lastIndexOf('\n```', contentEnd);
|
||||
|
||||
// If we found opening backticks, find the actual newline (skipping any language identifier)
|
||||
if (codeBlockStart !== -1) {
|
||||
const newlineAfterBackticks = artifactContent.indexOf('\n', codeBlockStart);
|
||||
if (newlineAfterBackticks !== -1 && newlineAfterBackticks < contentEnd) {
|
||||
codeBlockStart = newlineAfterBackticks;
|
||||
} else {
|
||||
codeBlockStart = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Determine where to look for the original content
|
||||
let searchStart, searchEnd;
|
||||
if (codeBlockStart !== -1) {
|
||||
// Code block starts
|
||||
searchStart = codeBlockStart + 4; // after ```\n
|
||||
// Code block starts - searchStart is right after the newline following ```[lang]
|
||||
searchStart = codeBlockStart + 1; // after the newline
|
||||
|
||||
if (codeBlockEnd !== -1 && codeBlockEnd > codeBlockStart) {
|
||||
// Code block has proper ending
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue