simov / markdown-viewer

Markdown Viewer / Browser Extension
MIT License
1.05k stars 133 forks source link

Escape html within TOC entries #106

Closed JMcKiern closed 4 years ago

JMcKiern commented 4 years ago

Fixes #103

simov commented 4 years ago

Thanks, I was considering your PR for a while, I even reworked it into:

var escape = ((
  xml = new XMLSerializer(),
  node = document.createTextNode('')
) => (input) => {
  node.textContent = input
  return xml.serializeToString(node)
})()

Which theoretically should have better performance .. in cases of huge markdown documents with lots of headers ..

Anyway, in the end I went on with this:

title: node.innerText.replace(/</g, '&lt;').replace(/>/g, '&gt;')

The XMLSerializer additionally escapes & but I prefer being a bit more explicit + escaping just <> should be fine I think.

Will publish it shortly :+1: