forked from mirrors/gecko-dev
The phrasing content change means that the contents of <div id="foo"> were being put in their own paragraph inside that div, and then later the singly nested <div><p></p></div> is unnested and we throw the div away, thus losing the ID attribute, which causes the browser_readerMode_with_anchor test to fail. The test document is a bit abstract and I doubt this will be an issue in practice, though I filed https://github.com/mozilla/readability/issues/460 to copy the id attribute across for cases where the inner <p> has no such attribute (which would preserve the id in this case). MozReview-Commit-ID: 8XBKFiYllxY --HG-- extra : rebase_source : 8aa713bced0dfb517de5a6a4463356741eb3c5a0
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
/* eslint-env mozilla/chrome-worker */
|
|
|
|
"use strict";
|
|
|
|
/**
|
|
* A worker dedicated to handle parsing documents for reader view.
|
|
*/
|
|
|
|
importScripts("resource://gre/modules/workers/require.js",
|
|
"resource://gre/modules/reader/JSDOMParser.js",
|
|
"resource://gre/modules/reader/Readability.js");
|
|
|
|
var PromiseWorker = require("resource://gre/modules/workers/PromiseWorker.js");
|
|
|
|
const DEBUG = false;
|
|
|
|
var worker = new PromiseWorker.AbstractWorker();
|
|
worker.dispatch = function(method, args = []) {
|
|
return Agent[method](...args);
|
|
};
|
|
worker.postMessage = function(result, ...transfers) {
|
|
self.postMessage(result, ...transfers);
|
|
};
|
|
worker.close = function() {
|
|
self.close();
|
|
};
|
|
worker.log = function(...args) {
|
|
if (DEBUG) {
|
|
dump("ReaderWorker: " + args.join(" ") + "\n");
|
|
}
|
|
};
|
|
|
|
self.addEventListener("message", msg => worker.handleMessage(msg));
|
|
|
|
var Agent = {
|
|
/**
|
|
* Parses structured article data from a document.
|
|
*
|
|
* @param {object} uri URI data for the document.
|
|
* @param {string} serializedDoc The serialized document.
|
|
* @param {object} options Options object to pass to Readability.
|
|
*
|
|
* @return {object} Article object returned from Readability.
|
|
*/
|
|
parseDocument(uri, serializedDoc, options) {
|
|
let doc = new JSDOMParser().parse(serializedDoc, uri.spec);
|
|
return new Readability(doc, options).parse();
|
|
},
|
|
};
|