Bug 1645607 - avoid changing plain text documents when entering reader mode, r=jaws

The issue in this bug was caused by reader mode replacing the 'pre' tag
that we use to wrap plaintext documents with a series of paragraphs.
This change affected the original document. Instead, we can put the
paragraphs in a clone of the original document, which is fine for
reader mode and avoids altering the original.

Differential Revision: https://phabricator.services.mozilla.com/D79713
This commit is contained in:
Gijs Kruitbosch 2020-06-15 22:03:09 +00:00
Родитель 82df51ad78
Коммит f4baf697be
1 изменённых файлов: 8 добавлений и 6 удалений

Просмотреть файл

@ -459,6 +459,9 @@ var ReaderMode = {
let serializer = new XMLSerializer();
let serializedDoc = serializer.serializeToString(doc);
// Explicitly null out doc to make it clear it might not be available from this
// point on.
doc = null;
let options = {
classesToPreserve: CLASSES_TO_PRESERVE,
@ -476,10 +479,6 @@ var ReaderMode = {
histogram.add(PARSE_ERROR_WORKER);
}
// Explicitly null out doc to make it clear it might not be available from this
// point on.
doc = null;
if (!article) {
this.log("Worker did not return an article");
histogram.add(PARSE_ERROR_NO_ARTICLE);
@ -660,8 +659,11 @@ var ReaderMode = {
}
docFrag.append(pElem);
}
preTag.parentNode.replaceChild(docFrag, preTag);
return doc;
// Clone the document to avoid the original document being affected
// (which shows up when exiting reader mode again).
let clone = doc.documentElement.cloneNode(true);
clone.querySelector("pre").replaceWith(docFrag);
return clone;
},
};