mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-04 17:48:50 +01:00
fix code parsing bug
This commit is contained in:
parent
cbcc1a1bb4
commit
897c384ac9
3 changed files with 12 additions and 35 deletions
|
|
@ -1,4 +1,5 @@
|
|||
const regex = /```([^`\n]*?)\n([\s\S]*?)\n```/g;
|
||||
const primaryRegex = /```([^`\n]*?)\n([\s\S]*?)\n```/g;
|
||||
const secondaryRegex = /```([^`\n]*?)\n?([\s\S]*?)\n?```/g;
|
||||
|
||||
const unenclosedCodeTest = (text) => {
|
||||
let workingText = text;
|
||||
|
|
@ -10,7 +11,12 @@ const unenclosedCodeTest = (text) => {
|
|||
};
|
||||
|
||||
export default function regexSplit(string) {
|
||||
const matches = [...string.matchAll(regex)];
|
||||
let matches = [...string.matchAll(primaryRegex)];
|
||||
|
||||
if (!matches[0]) {
|
||||
matches = [...string.matchAll(secondaryRegex)];
|
||||
}
|
||||
|
||||
const output = [matches[0].input.slice(0, matches[0].index)];
|
||||
|
||||
// console.log(matches);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue