setup.placeDiffInDom = (title, oldContent, newContent, domSelector) => { setup.externalCodePromise('diff').then(()=>{ const escapedChars = { /*'&' : '&', '<' : '<', '>' : '>',*/ '"' : '"', "'" : ''', '`' : '`' }; for(const [toBeEscaped, asEscaped] of Object.entries(escapedChars)) oldContent = oldContent.replaceAll(toBeEscaped,asEscaped); const unifiedDiffPatch = window.Diff.createTwoFilesPatch(title,title,oldContent,newContent,undefined,undefined,{ignoreWhitespace: true, stripTrailingCr: true}); let resultingHTML = ""; unifiedDiffPatch.split('\n').forEach((line)=>{ if(line.startsWith('@@')){ resultingHTML += `

${line}

`; }else if(line.startsWith('---')){ }else if(line.startsWith('+++')){ }else if(line.startsWith('-')){ resultingHTML += `

${line}

`; }else if(line.startsWith('+')){ resultingHTML += `

${line}

`; } }); $(domSelector).html(resultingHTML); }); }