fix code parsing bug

This commit is contained in:
Daniel Avila 2023-03-01 21:59:13 -05:00
parent cbcc1a1bb4
commit 897c384ac9
3 changed files with 12 additions and 35 deletions

View file

@ -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);