Open mbret opened 2 hours ago
Okay so another alternative I just though which could be faster is to create a temporary dom like this:
const newDom = document.implementation.createHTMLDocument()
const el = newDom.createElement(`textarea`)
el.innerHTML = str
return el.value || ``
Since it's not the current dom, it does not trigger html resources. However I believe we could initialize it on the constructor and destroy it once the CFI is resolved, that could increase performances.
Additionally, why is this decoding needed to begin with ? Why isn't the string just enough ?
I have an epub with this content:
The problematic is the figure section. When the method
decodeEntities
is called with the text node, theel.innerHTML = str
instruction will actually load and run the html code that was in the figure. Unintentionally trigger http requests and other wort things.Is it an actual bug or this side effect is expected and we should not work with live document ?
In the meantime I was trying to find a safer alternative and here what I came up with:
It does not crash and seems to be returning the correct node and CFI. I am not super confident regarding performance of using DOMParser vs the same document where we create an new temporary element