const showNumber = (lineInfo) => { const first = lineInfo.line[0]; return first === ' ' || first === '@' || first === '-' || first === '+'; } let htmlEncode const construct = (data) => { const diffs = data.diffs for(let diffLineIndex in diffs.lines) { diffs.lines[diffLineIndex].line = htmlEncode(diffs.lines[diffLineIndex].line) } let result = ` ` for(let lineInfo of diffs.lines) { result += ` ` } result += `
Old    ${diffs.old}
   New ${diffs.new}
${showNumber(lineInfo) ? lineInfo['num-old'] : '  '} ${showNumber(lineInfo) ? lineInfo['num-new'] : '  '}
${lineInfo.line}
` return result; } onmessage = function(e) { eval(`htmlEncode = ${e.data.htmlEncode}`) const result = construct(e.data); postMessage(result) }