setup.codeSanitize = (code) => { function varnameToTW(varname){ varname = "QSP."+varname; if(varname.indexOf("[") == -1) varname += "[0]"; return varname; } const regexp = /<>/g; const matches = [...code.matchAll(regexp)]; for(const match of matches){ const completeMatch = match[0]; let updatedMatch = completeMatch; const setValue = match[1]; let updatedSetValue = setValue; const linkRegex = /(.*?)<\/a>/g; const linkMatches = [...setValue.matchAll(linkRegex)]; for(const linkMatch of linkMatches){ const completeLinkMatch = linkMatch[0]; let updatedLink = completeLinkMatch; const commands = linkMatch[1]; const label = linkMatch[2]; const singleCommands = commands.split('&'); const commandsOut = []; for(const singleCommand of singleCommands){ let trimmed = singleCommand.trim(); if (trimmed.startsWith('gt')){ const gtArguments = trimmed.substring(3); commandsOut.push("<>"); }else{ //$start_type[''loc''] = ''' + QSP.$ARGS[2] + ''' const setSplit = trimmed.split("="); let varname = varnameToTW(setSplit[0].replaceAll("''","'")); let val = setSplit[1].replaceAll("'''","''").replaceAll("[''","['").replaceAll("'']","']"); commandsOut.push("<>"); } } updatedLink = "<>" + commandsOut.join("")+ "<>"; //updatedMatch = updatedMatch.replace(completeLinkMatch,updatedLink); updatedSetValue = updatedSetValue.replace(completeLinkMatch,updatedLink); } //code = code.replace(completeMatch, "`"+ updatedMatch + "`"); code = code.replace(setValue, "`"+ updatedSetValue + "`"); } //code = code.replaceAll("QSP.$ARGS[","_dynevalVars["); /* <> <
'`>> <> <
<'>><><><><>
'`>> <
> */ return code; } setup.dyneval = function (code, ...margs){ const resultBackupt = QSP.$result[0]; State.variables.ARGSstack.push(margs); //State.temporary.dynevalVars = margs; const saneCode = setup.codeSanitize(code); //const completeCode = "<>"+saneCode+"<>"; let completeCode = saneCode; for (let index = 0; index < margs.length; index++) { const varnamePlain = "QSP.$ARGS["+index+"]"; const val = JSON.stringify(margs[index]); completeCode = completeCode.replaceAll(varnamePlain, val); } console.log("CODE",completeCode); $.wiki(completeCode); State.variables.ARGSstack.pop(); const result = QSP.$result[0]; QSP.$result[0] = resultBackupt; return result; }