addons/firefox-addons/feed-preview

changeset 6:5d7c13e998e9

Create feed previews using a stream filter

Instead of replacing the feed document with an XHTML preview from a content
script after it has already been rendered, create an XHTML preview using a
stream filter before it is passed into the rendering engine and use an XSL
style sheet to convert it to HTML. This has two advantages, firstly it
results in an HTMLDocument with the full HTML DOM available and secondly it
avoids rendering the document twice.
Refactor the feed preview creation and split parsing and rendering into
seperate modules.
author Guido Berhoerster <guido+feed-preview@berhoerster.name>
date Thu Nov 08 16:30:34 2018 +0100 (19 months ago)
parents 341a0f4b7ce0
children 2bbb7617dd13
files Makefile background.html background.js content_scripts/feed-preview.js js/background.js js/feed-parser.js js/feed-preview.js manifest.json.in web_resources/feed-preview.xhtml web_resources/xhtml-to-html.xsl
line diff
     1.1 --- a/Makefile	Sun Nov 04 10:03:05 2018 +0100
     1.2 +++ b/Makefile	Thu Nov 08 16:30:34 2018 +0100
     1.3 @@ -36,11 +36,13 @@
     1.4  		NEWS \
     1.5  		README \
     1.6  		$(wildcard _locales/*/messages.json) \
     1.7 -		background.js \
     1.8 +		background.html \
     1.9  		content_scripts/feed-probe.js \
    1.10 -		content_scripts/feed-preview.js \
    1.11  		icons/feed-preview.svg \
    1.12  		$(BITMAP_ICONS) \
    1.13 +		js/background.js \
    1.14 +		js/feed-parser.js \
    1.15 +		js/feed-preview.js \
    1.16  		popup/feed-selection.js \
    1.17  		popup/feed-selection.html \
    1.18  		web_resources/style/feed-preview.css \
    1.19 @@ -48,6 +50,7 @@
    1.20  		web_resources/style/common.css \
    1.21  		web_resources/style/entry-content.css \
    1.22  		web_resources/feed-preview.xhtml \
    1.23 +		web_resources/xhtml-to-html.xsl \
    1.24  		web_resources/images/arrow.svg
    1.25  
    1.26  .DEFAULT_TARGET = all
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/background.html	Thu Nov 08 16:30:34 2018 +0100
     2.3 @@ -0,0 +1,9 @@
     2.4 +<!DOCTYPE html>
     2.5 +<html lang="en">
     2.6 +  <head>
     2.7 +    <meta charset="utf-8">
     2.8 +    <script type="module" src="js/feed-parser.js"></script>
     2.9 +    <script type="module" src="js/feed-preview.js"></script>
    2.10 +    <script type="module" src="js/background.js"></script>
    2.11 +  </head>
    2.12 +</html>
     3.1 --- a/background.js	Sun Nov 04 10:03:05 2018 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,67 +0,0 @@
     3.4 -/*
     3.5 - * Copyright (C) 2018 Guido Berhoerster <guido+feed-preview@berhoerster.name>
     3.6 - *
     3.7 - * This Source Code Form is subject to the terms of the Mozilla Public
     3.8 - * License, v. 2.0. If a copy of the MPL was not distributed with this
     3.9 - * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    3.10 - */
    3.11 -
    3.12 -'use strict';
    3.13 -
    3.14 -var tabsFeeds = new Map();
    3.15 -
    3.16 -// until content handlers become available to webextensions
    3.17 -// (https://bugzilla.mozilla.org/show_bug.cgi?id=1457500) intercept all
    3.18 -// responses and change the content type from application/atom+xml or
    3.19 -// application/rss+xml to application/xml which will then be handled by a
    3.20 -// content script
    3.21 -browser.webRequest.onHeadersReceived.addListener(details => {
    3.22 -    if (details.statusCode != 200 ||
    3.23 -            typeof details.responseHeaders === 'undefined') {
    3.24 -        return;
    3.25 -    }
    3.26 -
    3.27 -    let contentTypeHeader = details.responseHeaders.find(element => {
    3.28 -        return element.name.toLowerCase() === 'content-type';
    3.29 -    });
    3.30 -    if (typeof contentTypeHeader !== 'undefined') {
    3.31 -        let contentType = contentTypeHeader.value.split(';');
    3.32 -        let mediaType = contentType[0].trim().toLowerCase();
    3.33 -        if (mediaType === 'application/atom+xml' ||
    3.34 -                mediaType === 'application/rss+xml') {
    3.35 -            contentType[0] = 'application/xml';
    3.36 -            contentTypeHeader.value = contentType.join(';');
    3.37 -        }
    3.38 -    }
    3.39 -
    3.40 -    return {responseHeaders: details.responseHeaders};
    3.41 -}, {urls: ['http://*/*', 'https://*/*'], types: ['main_frame']},
    3.42 -['blocking', 'responseHeaders']);
    3.43 -
    3.44 -browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
    3.45 -    let tab = sender.tab;
    3.46 -    if (typeof tab !== 'undefined') {
    3.47 -        // content script sending feeds
    3.48 -        tabsFeeds.set(tab.id, request);
    3.49 -        browser.pageAction.show(tab.id);
    3.50 -    } else {
    3.51 -        let response = tabsFeeds.get(request);
    3.52 -        // popup querying feeds
    3.53 -        sendResponse(tabsFeeds.get(request));
    3.54 -    }
    3.55 -});
    3.56 -
    3.57 -browser.tabs.onUpdated.addListener((id, changeInfo, tab) => {
    3.58 -    if (typeof changeInfo.url === 'undefined') {
    3.59 -        // filter out updates which do not change the URL
    3.60 -        return;
    3.61 -    }
    3.62 -
    3.63 -    // hide the page action when the URL changes since it is no longer valid,
    3.64 -    // it will be shown again if the content script detects a feed
    3.65 -    browser.pageAction.hide(tab.id);
    3.66 -});
    3.67 -
    3.68 -browser.tabs.onRemoved.addListener((tabId, removeInfo) => {
    3.69 -    tabsFeeds.delete(tabId);
    3.70 -});
     4.1 --- a/content_scripts/feed-preview.js	Sun Nov 04 10:03:05 2018 +0100
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,598 +0,0 @@
     4.4 -/*
     4.5 - * Copyright (C) 2018 Guido Berhoerster <guido+feed-preview@berhoerster.name>
     4.6 - *
     4.7 - * This Source Code Form is subject to the terms of the Mozilla Public
     4.8 - * License, v. 2.0. If a copy of the MPL was not distributed with this
     4.9 - * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    4.10 - */
    4.11 -
    4.12 -'use strict';
    4.13 -
    4.14 -const ALLOWED_PROTOCOLS = new Set(['http:', 'https:', 'ftp:']);
    4.15 -
    4.16 -function encodeXML(str) {
    4.17 -    return str.replace(/[<>&'"]/g, c => {
    4.18 -        switch (c) {
    4.19 -            case '<': return '&lt;';
    4.20 -            case '>': return '&gt;';
    4.21 -            case '&': return '&amp;';
    4.22 -            case '\'': return '&apos;';
    4.23 -            case '"': return '&quot;';
    4.24 -        }
    4.25 -    });
    4.26 -}
    4.27 -
    4.28 -function parseDate(s) {
    4.29 -    let date = new Date(s);
    4.30 -
    4.31 -    return isNaN(date) ? new Date(0) : date;
    4.32 -}
    4.33 -
    4.34 -function parseURL(text, baseURL = window.location.href) {
    4.35 -    let url;
    4.36 -
    4.37 -    try {
    4.38 -        url = new URL(text, baseURL);
    4.39 -    } catch (e) {
    4.40 -        return null;
    4.41 -    }
    4.42 -    if (!ALLOWED_PROTOCOLS.has(url.protocol)) {
    4.43 -        return null;
    4.44 -    }
    4.45 -
    4.46 -    return url;
    4.47 -}
    4.48 -
    4.49 -function feedNSResolver(prefix) {
    4.50 -    switch (prefix) {
    4.51 -        case 'atom':
    4.52 -            return 'http://www.w3.org/2005/Atom'
    4.53 -        case 'rss':
    4.54 -            return 'http://my.netscape.com/rdf/simple/0.9/'
    4.55 -    }
    4.56 -    return null;
    4.57 -}
    4.58 -
    4.59 -function feedQueryXPath(feedDocument, scopeElement, xpathQuery) {
    4.60 -    return feedDocument.evaluate(xpathQuery, scopeElement, feedNSResolver,
    4.61 -            XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    4.62 -}
    4.63 -
    4.64 -function feedQueryXPathAll(feedDocument, scopeElement, xpathQuery) {
    4.65 -    let result = feedDocument.evaluate(xpathQuery, scopeElement, feedNSResolver,
    4.66 -            XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
    4.67 -    let nodes = [];
    4.68 -    for (let node = result.iterateNext(); node !== null;
    4.69 -            node = result.iterateNext()) {
    4.70 -        nodes.push(node);
    4.71 -    }
    4.72 -
    4.73 -    return nodes;
    4.74 -}
    4.75 -
    4.76 -class FeedLogo {
    4.77 -    constructor(url, title = '') {
    4.78 -        this.url = url;
    4.79 -        this.title = title;
    4.80 -    }
    4.81 -}
    4.82 -
    4.83 -class RSS1Logo extends FeedLogo {
    4.84 -    constructor(feedDocument, imageElement) {
    4.85 -        let urlElement = feedQueryXPath(feedDocument, imageElement,
    4.86 -                './rss:url');
    4.87 -        if (urlElement === null) {
    4.88 -            throw new TypeError('missing <url> element in <logo> element');
    4.89 -        }
    4.90 -        let url = parseURL(urlElement.textContent.trim());
    4.91 -        if (url === null) {
    4.92 -            throw new TypeError('invalid URL in <logo> element');
    4.93 -        }
    4.94 -        super(url);
    4.95 -
    4.96 -        let titleElement = feedQueryXPath(feedDocument, imageElement,
    4.97 -                './rss:title');
    4.98 -        if (titleElement !== null) {
    4.99 -            this.title = titleElement.textContent.trim();
   4.100 -        }
   4.101 -    }
   4.102 -}
   4.103 -
   4.104 -class RSS2Logo extends FeedLogo {
   4.105 -    constructor(feedDocument, imageElement) {
   4.106 -        let urlElement = feedQueryXPath(feedDocument, imageElement, './url');
   4.107 -        if (urlElement === null) {
   4.108 -            throw new TypeError('missing <url> element in <logo> element');
   4.109 -        }
   4.110 -        let url = parseURL(urlElement.textContent.trim());
   4.111 -        if (url === null) {
   4.112 -            throw new TypeError('invalid URL in <logo> element');
   4.113 -        }
   4.114 -        super(url);
   4.115 -
   4.116 -        let titleElement = feedQueryXPath(feedDocument, imageElement,
   4.117 -                './title');
   4.118 -        if (titleElement !== null) {
   4.119 -            this.title = titleElement.textContent.trim();
   4.120 -        }
   4.121 -    }
   4.122 -}
   4.123 -
   4.124 -class AtomLogo extends FeedLogo {
   4.125 -    constructor(logoElement) {
   4.126 -        let url = parseURL(logoElement.textContent.trim());
   4.127 -        if (url === null) {
   4.128 -            throw new TypeError('invalid URL in <logo> element');
   4.129 -        }
   4.130 -        super(url);
   4.131 -    }
   4.132 -}
   4.133 -
   4.134 -class FeedEntryFile {
   4.135 -    constructor(url, type = browser.i18n.getMessage('defaultFileType'),
   4.136 -            size = 0) {
   4.137 -        this.url = url;
   4.138 -        let filename = url.pathname.split('/').pop();
   4.139 -        this.filename = filename !== '' ? filename :
   4.140 -                browser.i18n.getMessage('defaultFileName');
   4.141 -        this.type = type;
   4.142 -        this.size = size;
   4.143 -    }
   4.144 -}
   4.145 -
   4.146 -class RSS2EntryFile extends FeedEntryFile {
   4.147 -    constructor(enclosureElement) {
   4.148 -        let url = parseURL(enclosureElement.getAttribute('url'));
   4.149 -        if (url === null) {
   4.150 -            throw new TypeError('invalid URL in <enclosure> element');
   4.151 -        }
   4.152 -        super(url);
   4.153 -
   4.154 -        let type = enclosureElement.getAttribute('type');
   4.155 -        if (type !== null) {
   4.156 -            this.type = type;
   4.157 -        }
   4.158 -
   4.159 -        let size = parseInt(enclosureElement.getAttribute('length'), 10);
   4.160 -        if (!isNaN(size)) {
   4.161 -            this.size = size;
   4.162 -        }
   4.163 -    }
   4.164 -}
   4.165 -
   4.166 -class FeedEntry {
   4.167 -    constructor(title = browser.i18n.getMessage('defaultFeedEntryTitle'),
   4.168 -            url = null, date = new Date(0), content = '', files = []) {
   4.169 -        this.title = title;
   4.170 -        this.url = url;
   4.171 -        this.date = date;
   4.172 -        this._content;
   4.173 -        this.content = content;
   4.174 -        this.files = files;
   4.175 -    }
   4.176 -
   4.177 -    set content(content) {
   4.178 -        this._content = this.normalizeContent(content);
   4.179 -    }
   4.180 -
   4.181 -    get content() {
   4.182 -        return this._content;
   4.183 -    }
   4.184 -
   4.185 -    normalizeContent(text) {
   4.186 -        let parsedDocument = new DOMParser().parseFromString(text, 'text/html');
   4.187 -
   4.188 -        let linkElement = parsedDocument.createElement('link');
   4.189 -        linkElement.rel = 'stylesheet';
   4.190 -        linkElement.href ='style/entry-content.css';
   4.191 -        parsedDocument.head.appendChild(linkElement);
   4.192 -
   4.193 -        return new XMLSerializer().serializeToString(parsedDocument);
   4.194 -    }
   4.195 -}
   4.196 -
   4.197 -class RSS1Entry extends FeedEntry {
   4.198 -    constructor(feedDocument, itemElement) {
   4.199 -        super();
   4.200 -
   4.201 -        let titleElement = feedQueryXPath(feedDocument, itemElement,
   4.202 -                './rss:title');
   4.203 -        if (titleElement !== null) {
   4.204 -            this.title = titleElement.textContent;
   4.205 -        }
   4.206 -
   4.207 -        let linkElement = feedQueryXPath(feedDocument, itemElement,
   4.208 -                './rss:link');
   4.209 -        if (linkElement !== null) {
   4.210 -            this.url = parseURL(linkElement.textContent);
   4.211 -        }
   4.212 -    }
   4.213 -}
   4.214 -
   4.215 -class RSS2Entry extends FeedEntry {
   4.216 -    constructor(feedDocument, itemElement) {
   4.217 -        super();
   4.218 -
   4.219 -        let titleElement = feedQueryXPath(feedDocument, itemElement, './title');
   4.220 -        if (titleElement !== null) {
   4.221 -            this.title = titleElement.textContent;
   4.222 -        }
   4.223 -
   4.224 -        let linkElement = feedQueryXPath(feedDocument, itemElement, './link');
   4.225 -        if (linkElement !== null) {
   4.226 -            this.url = parseURL(linkElement.textContent);
   4.227 -        }
   4.228 -
   4.229 -        let pubDateElement = feedQueryXPath(feedDocument, itemElement,
   4.230 -                './pubDate');
   4.231 -        if (pubDateElement !== null) {
   4.232 -            this.date = parseDate(pubDateElement.textContent);
   4.233 -        }
   4.234 -
   4.235 -        let descriptionElement = feedQueryXPath(feedDocument, itemElement,
   4.236 -                './description');
   4.237 -        if (descriptionElement !== null) {
   4.238 -            this.content = descriptionElement.textContent.trim();
   4.239 -        }
   4.240 -
   4.241 -        for (let enclosureElement of
   4.242 -                feedQueryXPathAll(feedDocument, itemElement, './enclosure')) {
   4.243 -            try {
   4.244 -                let entryFile = new RSS2EntryFile(enclosureElement);
   4.245 -                this.files.push(entryFile);
   4.246 -            } catch (e) {}
   4.247 -        }
   4.248 -    }
   4.249 -}
   4.250 -
   4.251 -class AtomEntry extends FeedEntry {
   4.252 -    constructor(feedDocument, entryElement) {
   4.253 -        super();
   4.254 -
   4.255 -        let titleElement = feedQueryXPath(feedDocument, entryElement,
   4.256 -                './atom:title');
   4.257 -        if (titleElement !== null) {
   4.258 -            this.title = titleElement.textContent.trim();
   4.259 -        }
   4.260 -
   4.261 -        let linkElement = feedQueryXPath(feedDocument, entryElement,
   4.262 -                './atom:link[@href][@rel="alternate"]');
   4.263 -        if (linkElement !== null) {
   4.264 -            this.url = parseURL(linkElement.getAttribute('href'));
   4.265 -        }
   4.266 -
   4.267 -        let updatedElement = feedQueryXPath(feedDocument, entryElement,
   4.268 -                './atom:updated');
   4.269 -        if (updatedElement !== null) {
   4.270 -            this.date = parseDate(updatedElement.textContent);
   4.271 -        }
   4.272 -
   4.273 -        let contentElement = feedQueryXPath(feedDocument, entryElement,
   4.274 -                './atom:content');
   4.275 -        if (contentElement === null) {
   4.276 -            contentElement = feedQueryXPath(feedDocument, entryElement,
   4.277 -                    './atom:summary');
   4.278 -        }
   4.279 -        if (contentElement !== null) {
   4.280 -            let contentType = contentElement.getAttribute('type');
   4.281 -            if (contentType === null) {
   4.282 -                contentType = 'text';
   4.283 -            }
   4.284 -            contentType = contentType.toLowerCase();
   4.285 -            if (contentType === 'xhtml') {
   4.286 -                this.content = contentElement.innerHTML;
   4.287 -            } else if (contentType === 'html') {
   4.288 -                this.content = contentElement.textContent;
   4.289 -            } else {
   4.290 -                let encodedContent =
   4.291 -                        encodeXML(contentElement.textContent.trim());
   4.292 -                this.content = `<pre>${encodedContent}</pre>`;
   4.293 -            }
   4.294 -        }
   4.295 -    }
   4.296 -}
   4.297 -
   4.298 -class Feed {
   4.299 -    constructor(title = browser.i18n.getMessage('defaultFeedTitle'),
   4.300 -            subtitle = '', logo = null, entries = []) {
   4.301 -        this.title = title;
   4.302 -        this.subtitle = subtitle;
   4.303 -        this.logo = logo;
   4.304 -        this.entries = entries;
   4.305 -    }
   4.306 -
   4.307 -    async createPreviewDocument() {
   4.308 -        let url = browser.extension.getURL('web_resources/feed-preview.xhtml');
   4.309 -        let response;
   4.310 -        let text;
   4.311 -        try {
   4.312 -            response = await fetch(url);
   4.313 -            text = await response.text();
   4.314 -        } catch (e) {
   4.315 -            console.log(`Error: failed to read preview template: ${e.message}`);
   4.316 -            return;
   4.317 -        }
   4.318 -        let previewDocument = (new DOMParser()).parseFromString(text,
   4.319 -                'application/xhtml+xml');
   4.320 -
   4.321 -        previewDocument.querySelector('base').href =
   4.322 -                browser.extension.getURL('web_resources/');
   4.323 -
   4.324 -        previewDocument.querySelector('title').textContent = this.title;
   4.325 -        previewDocument.querySelector('#feed-title').textContent = this.title;
   4.326 -        previewDocument.querySelector('#feed-subtitle').textContent =
   4.327 -                this.subtitle;
   4.328 -        if (this.logo !== null) {
   4.329 -            let feedLogoTemplate =
   4.330 -                    previewDocument.querySelector('#feed-logo-template');
   4.331 -            let logoNode = previewDocument.importNode(feedLogoTemplate.content,
   4.332 -                    true);
   4.333 -            let imgElement = logoNode.querySelector('#feed-logo');
   4.334 -            imgElement.setAttribute('src', this.logo.url);
   4.335 -            imgElement.setAttribute('alt', this.logo.title);
   4.336 -            previewDocument.querySelector('#feed-header').prepend(logoNode);
   4.337 -        }
   4.338 -
   4.339 -        let entryTemplateElement =
   4.340 -                previewDocument.querySelector('#entry-template');
   4.341 -        let entryTitleTemplateElement =
   4.342 -                previewDocument.querySelector('#entry-title-template');
   4.343 -        let entryTitleLinkedTemplateElement =
   4.344 -                previewDocument.querySelector('#entry-title-linked-template');
   4.345 -        let entryFileListTemplateElement =
   4.346 -                previewDocument.querySelector('#entry-files-list-template');
   4.347 -        let entryFileTemplateElement =
   4.348 -                previewDocument.querySelector('#entry-file-template');
   4.349 -        if (this.entries.length === 0) {
   4.350 -            let hintTemplateElement =
   4.351 -                    previewDocument.querySelector('#no-entries-hint-template');
   4.352 -            let hintNode =
   4.353 -                    previewDocument.importNode(hintTemplateElement.content,
   4.354 -                    true);
   4.355 -            hintNode.querySelector("#no-entries-hint").textContent =
   4.356 -                browser.i18n.getMessage('noEntriesHint');
   4.357 -
   4.358 -            previewDocument.body.append(hintNode);
   4.359 -        }
   4.360 -        for (let entry of this.entries) {
   4.361 -            let entryNode =
   4.362 -                    previewDocument.importNode(entryTemplateElement.content,
   4.363 -                    true);
   4.364 -            let titleElement;
   4.365 -            let titleNode;
   4.366 -
   4.367 -            if (entry.url !== null) {
   4.368 -                titleNode = previewDocument
   4.369 -                        .importNode(entryTitleLinkedTemplateElement.content,
   4.370 -                        true);
   4.371 -                titleElement = titleNode.querySelector('.entry-link');
   4.372 -                titleElement.href = entry.url;
   4.373 -                titleElement.title = entry.title;
   4.374 -            } else {
   4.375 -                titleNode = previewDocument
   4.376 -                        .importNode(entryTitleTemplateElement.content, true);
   4.377 -                titleElement = titleNode.querySelector('.entry-title');
   4.378 -            }
   4.379 -            titleElement.textContent = entry.title;
   4.380 -            entryNode.querySelector('.entry-header').prepend(titleNode);
   4.381 -
   4.382 -            let timeElement = entryNode.querySelector('.entry-date > time');
   4.383 -            timeElement.textContent = entry.date.toLocaleString();
   4.384 -
   4.385 -            let contentElement = entryNode.querySelector('.entry-content');
   4.386 -            contentElement.srcdoc = entry.content;
   4.387 -            contentElement.title = entry.title;
   4.388 -
   4.389 -            if (entry.files.length > 0) {
   4.390 -                let fileListNode = previewDocument
   4.391 -                        .importNode(entryFileListTemplateElement.content, true);
   4.392 -                fileListNode.querySelector('.entry-files-title').textContent =
   4.393 -                        browser.i18n.getMessage('filesTitle');
   4.394 -                let fileListElement =
   4.395 -                        fileListNode.querySelector('.entry-files-list');
   4.396 -
   4.397 -                for (let file of entry.files) {
   4.398 -                    let fileNode = previewDocument
   4.399 -                            .importNode(entryFileTemplateElement.content, true);
   4.400 -
   4.401 -                    let fileLinkElement =
   4.402 -                            fileNode.querySelector('.entry-file-link');
   4.403 -                    fileLinkElement.href = file.url;
   4.404 -                    fileLinkElement.title = file.filename;
   4.405 -                    fileLinkElement.textContent = file.filename;
   4.406 -
   4.407 -                    fileNode.querySelector('.entry-file-info').textContent =
   4.408 -                            `(${file.type}, ${file.size} bytes)`;
   4.409 -
   4.410 -                    fileListElement.appendChild(fileNode);
   4.411 -                }
   4.412 -
   4.413 -                entryNode.querySelector('.entry').append(fileListNode);
   4.414 -            }
   4.415 -
   4.416 -            previewDocument.body.append(entryNode);
   4.417 -        }
   4.418 -
   4.419 -        return previewDocument;
   4.420 -    }
   4.421 -}
   4.422 -
   4.423 -class RSS1Feed extends Feed {
   4.424 -    constructor(feedDocument) {
   4.425 -        super();
   4.426 -
   4.427 -        let documentElement = feedDocument.documentElement;
   4.428 -        let titleElement = feedQueryXPath(feedDocument, documentElement,
   4.429 -                './rss:channel/rss:title');
   4.430 -        if (titleElement !== null) {
   4.431 -            this.title = titleElement.textContent;
   4.432 -        }
   4.433 -
   4.434 -        let descriptionElement = feedQueryXPath(feedDocument, documentElement,
   4.435 -                './channel/description');
   4.436 -        if (descriptionElement !== null) {
   4.437 -            this.subtitle = descriptionElement.textContent;
   4.438 -        }
   4.439 -
   4.440 -        let imageElement = feedQueryXPath(feedDocument, documentElement,
   4.441 -                './rss:image');
   4.442 -        if (imageElement !== null) {
   4.443 -            try {
   4.444 -                let logo = new RSS1Logo(feedDocument, imageElement);
   4.445 -                this.logo = logo;
   4.446 -            } catch (e) {}
   4.447 -        }
   4.448 -
   4.449 -        let itemElements = feedQueryXPathAll(feedDocument, documentElement,
   4.450 -                './rss:item');
   4.451 -        for (let itemElement of itemElements) {
   4.452 -            let entry = new RSS1Entry(feedDocument, itemElement);
   4.453 -            if (typeof entry !== 'undefined') {
   4.454 -                this.entries.push(entry);
   4.455 -            }
   4.456 -        }
   4.457 -    }
   4.458 -}
   4.459 -
   4.460 -class RSS2Feed extends Feed {
   4.461 -    constructor(feedDocument) {
   4.462 -        super();
   4.463 -
   4.464 -        let documentElement = feedDocument.documentElement;
   4.465 -        let titleElement = feedQueryXPath(feedDocument, documentElement,
   4.466 -                './channel/title');
   4.467 -        if (titleElement !== null) {
   4.468 -            this.title = titleElement.textContent;
   4.469 -        }
   4.470 -
   4.471 -        let descriptionElement = feedQueryXPath(feedDocument, documentElement,
   4.472 -                './channel/description');
   4.473 -        if (descriptionElement !== null) {
   4.474 -            this.subtitle = descriptionElement.textContent;
   4.475 -        }
   4.476 -
   4.477 -        let imageElement = feedQueryXPath(feedDocument, documentElement,
   4.478 -                './channel/image');
   4.479 -        if (imageElement !== null) {
   4.480 -            try {
   4.481 -                let logo = new RSS2Logo(feedDocument, imageElement);
   4.482 -                this.logo = logo;
   4.483 -            } catch (e) {}
   4.484 -        }
   4.485 -
   4.486 -        let itemElements = feedQueryXPathAll(feedDocument, documentElement,
   4.487 -                './channel/item');
   4.488 -        for (let itemElement of itemElements) {
   4.489 -            let entry = new RSS2Entry(feedDocument, itemElement);
   4.490 -            if (typeof entry !== 'undefined') {
   4.491 -                this.entries.push(entry);
   4.492 -            }
   4.493 -        }
   4.494 -    }
   4.495 -}
   4.496 -
   4.497 -class AtomFeed extends Feed {
   4.498 -    constructor(feedDocument, atomVersion) {
   4.499 -        super();
   4.500 -
   4.501 -        let documentElement = feedDocument.documentElement;
   4.502 -        let titleElement = feedQueryXPath(feedDocument, documentElement,
   4.503 -                './atom:title');
   4.504 -        if (titleElement !== null) {
   4.505 -            this.title = titleElement.textContent.trim();
   4.506 -        }
   4.507 -
   4.508 -        let subtitleElement = feedQueryXPath(feedDocument, documentElement,
   4.509 -                './atom:subtitle');
   4.510 -        if (subtitleElement !== null) {
   4.511 -            this.subtitle = subtitleElement.textContent.trim();
   4.512 -        }
   4.513 -
   4.514 -        let logoElement =  feedQueryXPath(feedDocument, documentElement,
   4.515 -                './atom:logo');
   4.516 -        if (logoElement !== null) {
   4.517 -            try {
   4.518 -                let logo = new AtomLogo(logoElement);
   4.519 -                this.logo = logo;
   4.520 -            } catch (e) {}
   4.521 -        }
   4.522 -
   4.523 -        let entryElements = feedQueryXPathAll(feedDocument, documentElement,
   4.524 -                './atom:entry');
   4.525 -        for (let entryElement of entryElements) {
   4.526 -            this.entries.push(new AtomEntry(feedDocument, entryElement));
   4.527 -        }
   4.528 -    }
   4.529 -}
   4.530 -
   4.531 -function probeFeedType(feedDocument) {
   4.532 -    if (feedDocument.documentElement.nodeName === 'feed') {
   4.533 -        let version = feedDocument.documentElement.getAttribute('version');
   4.534 -        if (version === null) {
   4.535 -            version = '1.0';
   4.536 -        }
   4.537 -        for (let attr of feedDocument.documentElement.attributes) {
   4.538 -            if (attr.name === 'xmlns' &&
   4.539 -                    attr.value === 'http://www.w3.org/2005/Atom') {
   4.540 -                return ['atom', version];
   4.541 -            }
   4.542 -        }
   4.543 -    } else if (feedDocument.documentElement.nodeName === 'rss') {
   4.544 -        let version = feedDocument.documentElement.getAttribute('version');
   4.545 -        if (version !== null) {
   4.546 -            return ['rss', version];
   4.547 -        }
   4.548 -    } else if (feedDocument.documentElement.localName.toLowerCase() === 'rdf') {
   4.549 -        for (let attr of feedDocument.documentElement.attributes) {
   4.550 -            if (attr.name === 'xmlns' &&
   4.551 -                    attr.value === 'http://my.netscape.com/rdf/simple/0.9/') {
   4.552 -                return ['rss', '0.9'];
   4.553 -            }
   4.554 -        }
   4.555 -    }
   4.556 -
   4.557 -    return [undefined, undefined];
   4.558 -}
   4.559 -
   4.560 -async function replaceDocumentWithPreview(type, version) {
   4.561 -    let feed;
   4.562 -    switch (type) {
   4.563 -        case 'rss':
   4.564 -            switch (version) {
   4.565 -                case '0.9':
   4.566 -                case '1.0':
   4.567 -                    feed = new RSS1Feed(document, version);
   4.568 -                    break;
   4.569 -                case '0.90':
   4.570 -                case '0.91':
   4.571 -                case '0.92':
   4.572 -                case '0.93':
   4.573 -                case '0.94':
   4.574 -                case '2.0':
   4.575 -                    feed = new RSS2Feed(document, version);
   4.576 -                    break;
   4.577 -                default:
   4.578 -                    return;
   4.579 -            }
   4.580 -            break;
   4.581 -        case 'atom':
   4.582 -            feed = new AtomFeed(document, version);
   4.583 -            break;
   4.584 -        default:
   4.585 -            return;
   4.586 -    }
   4.587 -
   4.588 -    // replace original document with preview
   4.589 -    let previewDocument = await feed.createPreviewDocument();
   4.590 -    if (typeof previewDocument === 'undefined') {
   4.591 -        return;
   4.592 -    }
   4.593 -    let documentElement = previewDocument.documentElement;
   4.594 -    document.replaceChild(document.importNode(documentElement, true),
   4.595 -            document.documentElement);
   4.596 -}
   4.597 -
   4.598 -let [type, version] = probeFeedType(document);
   4.599 -if (typeof type !== 'undefined') {
   4.600 -    replaceDocumentWithPreview(type, version);
   4.601 -}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/js/background.js	Thu Nov 08 16:30:34 2018 +0100
     5.3 @@ -0,0 +1,161 @@
     5.4 +/*
     5.5 + * Copyright (C) 2018 Guido Berhoerster <guido+feed-preview@berhoerster.name>
     5.6 + *
     5.7 + * This Source Code Form is subject to the terms of the Mozilla Public
     5.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     5.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    5.10 + */
    5.11 +
    5.12 +'use strict';
    5.13 +
    5.14 +import * as feedParser from './feed-parser.js';
    5.15 +import {renderFeedPreview} from './feed-preview.js';
    5.16 +
    5.17 +const FEED_MAGIC = [
    5.18 +    '<rss',
    5.19 +    '<feed',
    5.20 +    ...Object.values(feedParser.XMLNS)
    5.21 +];
    5.22 +var tabsFeeds = new Map();
    5.23 +var fetchingFeedPreview = fetch('web_resources/feed-preview.xhtml')
    5.24 +        .then(response => response.text());
    5.25 +
    5.26 +function parseContentType(header) {
    5.27 +    let contentType = {
    5.28 +        mediaType: '',
    5.29 +        charset: 'utf-8'
    5.30 +    };
    5.31 +    let parts = header.toLowerCase().split(';');
    5.32 +    contentType.mediaType = parts.shift().trim();
    5.33 +    for (let parameter of parts) {
    5.34 +        let [, name, value, ] = parameter.trim().split(/([^=]+)="?([^"]*)"?/);
    5.35 +        if (name.toLowerCase() === 'charset') {
    5.36 +            contentType.charset = value.toLowerCase();
    5.37 +            break;
    5.38 +        }
    5.39 +    }
    5.40 +
    5.41 +    return contentType;
    5.42 +}
    5.43 +
    5.44 +async function handleFeed(inputText, url) {
    5.45 +    // fast-path: eliminate XML documents which cannot be Atom nor RSS feeds
    5.46 +    let inputTextStart = inputText.substring(0, 512);
    5.47 +    if (!FEED_MAGIC.some(element => inputTextStart.includes(element))) {
    5.48 +        return inputText;
    5.49 +    }
    5.50 +
    5.51 +    let feed;
    5.52 +    try {
    5.53 +        feed = (new feedParser.FeedParser).parseFromString(inputText, url);
    5.54 +    } catch (e) {
    5.55 +        if (e instanceof feedParser.ParserError ||
    5.56 +                e instanceof feedParser.UnsupportedFeedTypeError) {
    5.57 +            // let the browser deal with non-well formed XML or XML documents
    5.58 +            // which are not supported Atom or RSS feeds
    5.59 +            return inputText;
    5.60 +        }
    5.61 +        throw e;
    5.62 +    }
    5.63 +    console.log(`parsed feed ${url}:\n`, feed);
    5.64 +
    5.65 +    // render the preview document
    5.66 +    let feedPreviewDocument = new DOMParser()
    5.67 +            .parseFromString(await fetchingFeedPreview, 'text/html');
    5.68 +    renderFeedPreview(feedPreviewDocument, feed);
    5.69 +
    5.70 +    return new XMLSerializer().serializeToString(feedPreviewDocument);
    5.71 +}
    5.72 +
    5.73 +browser.webRequest.onHeadersReceived.addListener(details => {
    5.74 +    if (details.statusCode !== 200) {
    5.75 +        return {};
    5.76 +    }
    5.77 +
    5.78 +    let contentTypeIndex = details.responseHeaders.findIndex(header =>
    5.79 +            header.name.toLowerCase() === 'content-type' &&
    5.80 +            typeof header.value !== 'undefined');
    5.81 +    if (contentTypeIndex < 0) {
    5.82 +        // no Content-Type header found
    5.83 +        return {};
    5.84 +    }
    5.85 +    let headerValue = details.responseHeaders[contentTypeIndex].value
    5.86 +    let contentType = parseContentType(headerValue);
    5.87 +    // until content handlers become available to webextensions
    5.88 +    // (https://bugzilla.mozilla.org/show_bug.cgi?id=1457500) intercept all
    5.89 +    // responses and change the content type from application/atom+xml or
    5.90 +    // application/rss+xml to application/xml which will then be probed for
    5.91 +    // Atom or RSS content
    5.92 +    switch (contentType.mediaType) {
    5.93 +        case 'application/atom+xml':
    5.94 +        case 'application/rss+xml':
    5.95 +        case 'application/rdf+xml':
    5.96 +        case 'application/xml':
    5.97 +            break;
    5.98 +        default:
    5.99 +            // non-XML media type
   5.100 +            return {};
   5.101 +    }
   5.102 +    console.log(`response is an XML document\n`,
   5.103 +            `media type: ${contentType.mediaType}\n`,
   5.104 +            `charset: ${contentType.charset}`);
   5.105 +
   5.106 +    let decoder;
   5.107 +    try {
   5.108 +        decoder = new TextDecoder(contentType.charset);
   5.109 +    } catch (e) {
   5.110 +        if (e instanceof RangeError) {
   5.111 +            // unsupported charset
   5.112 +            return {};
   5.113 +        } else {
   5.114 +            throw e;
   5.115 +        }
   5.116 +    }
   5.117 +    let encoder = new TextEncoder();
   5.118 +    let inputText = '';
   5.119 +    let filter = browser.webRequest.filterResponseData(details.requestId);
   5.120 +    filter.addEventListener('data', ev => {
   5.121 +        inputText += decoder.decode(ev.data, {stream: true});
   5.122 +    });
   5.123 +    filter.addEventListener('stop', async ev => {
   5.124 +        let result = await handleFeed(inputText, details.url);
   5.125 +        filter.write(encoder.encode(result));
   5.126 +        filter.close();
   5.127 +    });
   5.128 +
   5.129 +    details.responseHeaders[contentTypeIndex] = {
   5.130 +        name: 'Content-Type',
   5.131 +        value: `application/xml;charset=${contentType.charset}`
   5.132 +    };
   5.133 +
   5.134 +    return {responseHeaders: details.responseHeaders};
   5.135 +},
   5.136 +        {urls: ['http://*/*', 'https://*/*'], types: ['main_frame']},
   5.137 +        ['blocking', 'responseHeaders']);
   5.138 +
   5.139 +browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
   5.140 +    let tab = sender.tab;
   5.141 +    if (typeof tab !== 'undefined') {
   5.142 +        // content script sending feeds
   5.143 +        tabsFeeds.set(tab.id, request);
   5.144 +        browser.pageAction.show(tab.id);
   5.145 +    } else {
   5.146 +        // popup querying feeds
   5.147 +        sendResponse(tabsFeeds.get(request));
   5.148 +    }
   5.149 +});
   5.150 +
   5.151 +browser.tabs.onUpdated.addListener((id, changeInfo, tab) => {
   5.152 +    if (typeof changeInfo.url === 'undefined') {
   5.153 +        // filter out updates which do not change the URL
   5.154 +        return;
   5.155 +    }
   5.156 +
   5.157 +    // hide the page action when the URL changes since it is no longer valid,
   5.158 +    // it will be shown again if the content script detects a feed
   5.159 +    browser.pageAction.hide(tab.id);
   5.160 +});
   5.161 +
   5.162 +browser.tabs.onRemoved.addListener((tabId, removeInfo) => {
   5.163 +    tabsFeeds.delete(tabId);
   5.164 +});
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/js/feed-parser.js	Thu Nov 08 16:30:34 2018 +0100
     6.3 @@ -0,0 +1,538 @@
     6.4 +/*
     6.5 + * Copyright (C) 2018 Guido Berhoerster <guido+feed-preview@berhoerster.name>
     6.6 + *
     6.7 + * This Source Code Form is subject to the terms of the Mozilla Public
     6.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     6.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    6.10 + */
    6.11 +
    6.12 +'use strict';
    6.13 +
    6.14 +export const XMLNS = {
    6.15 +    ATOM10: 'http://www.w3.org/2005/Atom',
    6.16 +    RSS09: 'http://my.netscape.com/rdf/simple/0.9/'
    6.17 +}
    6.18 +const ALLOWED_LINK_PROTOCOLS = new Set(['http:', 'https:', 'ftp:']);
    6.19 +
    6.20 +function encodeXML(str) {
    6.21 +    return str.replace(/[<>&'"]/g, c => {
    6.22 +        switch (c) {
    6.23 +            case '<': return '&lt;';
    6.24 +            case '>': return '&gt;';
    6.25 +            case '&': return '&amp;';
    6.26 +            case '\'': return '&apos;';
    6.27 +            case '"': return '&quot;';
    6.28 +        }
    6.29 +    });
    6.30 +}
    6.31 +
    6.32 +function parseDate(s) {
    6.33 +    let date = new Date(s);
    6.34 +
    6.35 +    return isNaN(date) ? new Date(0) : date;
    6.36 +}
    6.37 +
    6.38 +function parseURL(text, baseURL = '') {
    6.39 +    let url;
    6.40 +
    6.41 +    try {
    6.42 +        url = new URL(text, baseURL);
    6.43 +    } catch (e) {
    6.44 +        return null;
    6.45 +    }
    6.46 +    if (!ALLOWED_LINK_PROTOCOLS.has(url.protocol)) {
    6.47 +        return null;
    6.48 +    }
    6.49 +
    6.50 +    return url;
    6.51 +}
    6.52 +
    6.53 +function feedNSResolver(prefix) {
    6.54 +    switch (prefix) {
    6.55 +        case 'atom':
    6.56 +            return XMLNS.ATOM10;
    6.57 +        case 'rss':
    6.58 +            return XMLNS.RSS09;
    6.59 +    }
    6.60 +    return null;
    6.61 +}
    6.62 +
    6.63 +function feedQueryXPath(feedDocument, scopeElement, xpathQuery) {
    6.64 +    return feedDocument.evaluate(xpathQuery, scopeElement, feedNSResolver,
    6.65 +            XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    6.66 +}
    6.67 +
    6.68 +function feedQueryXPathAll(feedDocument, scopeElement, xpathQuery) {
    6.69 +    let result = feedDocument.evaluate(xpathQuery, scopeElement, feedNSResolver,
    6.70 +            XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
    6.71 +    let nodes = [];
    6.72 +    for (let node = result.iterateNext(); node !== null;
    6.73 +            node = result.iterateNext()) {
    6.74 +        nodes.push(node);
    6.75 +    }
    6.76 +
    6.77 +    return nodes;
    6.78 +}
    6.79 +
    6.80 +export class ParserError extends Error {
    6.81 +    constructor() {
    6.82 +        super(...arguments);
    6.83 +        this.name = this.constructor.name;
    6.84 +    }
    6.85 +}
    6.86 +
    6.87 +export class UnsupportedFeedTypeError extends Error {
    6.88 +    constructor(message = 'Document is not a supported feed', ...params) {
    6.89 +        super(message, ...params);
    6.90 +        this.name = this.constructor.name;
    6.91 +    }
    6.92 +}
    6.93 +
    6.94 +export class ProtocolError extends Error {
    6.95 +    constructor(url, status, statusText, ...params) {
    6.96 +        let message = `Protocol error: Transfer of ${url} failed with: ` +
    6.97 +                `${status} ${statusText}`
    6.98 +        super(message, ...params);
    6.99 +        this.name = this.constructor.name;
   6.100 +        this.url = url;
   6.101 +        this.status = status;
   6.102 +        this.statusText = statusText;
   6.103 +    }
   6.104 +}
   6.105 +
   6.106 +class FeedLogo {
   6.107 +    constructor(url, {title = ''} = {}) {
   6.108 +        this.url = url;
   6.109 +        this.title = title;
   6.110 +    }
   6.111 +}
   6.112 +
   6.113 +class FeedEntryFile {
   6.114 +    constructor(url, {type = browser.i18n.getMessage('defaultFileType'),
   6.115 +            size = 0} = {}) {
   6.116 +        this.filename = undefined;
   6.117 +        this._url = undefined;
   6.118 +        this.url = url;
   6.119 +        this.type = type;
   6.120 +        this.size = size;
   6.121 +    }
   6.122 +
   6.123 +    set url(url) {
   6.124 +        this._url = url;
   6.125 +        let filename = url.pathname.split('/').pop();
   6.126 +        this.filename = filename !== '' ? filename :
   6.127 +                browser.i18n.getMessage('defaultFileName');
   6.128 +    }
   6.129 +
   6.130 +    get url() {
   6.131 +        return this._url;
   6.132 +    }
   6.133 +}
   6.134 +
   6.135 +class FeedEntry {
   6.136 +    constructor({title = browser.i18n.getMessage('defaultFeedEntryTitle'),
   6.137 +            link = undefined, date = new Date(0), content = '',
   6.138 +            files = []} = {}) {
   6.139 +        this.title = title;
   6.140 +        this.link = link;
   6.141 +        this.date = date;
   6.142 +        this._content = undefined;
   6.143 +        this.content = content;
   6.144 +        this.files = files;
   6.145 +    }
   6.146 +
   6.147 +    normalizeContent(text) {
   6.148 +        if (typeof text === 'undefined') {
   6.149 +            return
   6.150 +        }
   6.151 +
   6.152 +        let contentDocument = document.implementation.createHTMLDocument();
   6.153 +        let parsedDocument = new DOMParser().parseFromString(text, 'text/html');
   6.154 +        contentDocument.body = contentDocument.adoptNode(parsedDocument.body);
   6.155 +        return new XMLSerializer().serializeToString(contentDocument);
   6.156 +    }
   6.157 +
   6.158 +    set content(content) {
   6.159 +        this._content = this.normalizeContent(content);
   6.160 +    }
   6.161 +
   6.162 +    get content() {
   6.163 +        return this._content;
   6.164 +    }
   6.165 +}
   6.166 +
   6.167 +class Feed {
   6.168 +    constructor(url, {title = browser.i18n.getMessage('defaultFeedTitle'),
   6.169 +            subtitle = '', logo, entries = []} = {}) {
   6.170 +        this.url = url;
   6.171 +        this.title = title;
   6.172 +        this.subtitle = subtitle;
   6.173 +        this.logo = logo;
   6.174 +        this.entries = entries;
   6.175 +    }
   6.176 +}
   6.177 +
   6.178 +export class FeedParser {
   6.179 +    static probeFeed(feedDocument) {
   6.180 +        let documentElement = feedDocument.documentElement;
   6.181 +        if (documentElement.nodeName === 'feed' &&
   6.182 +                documentElement.namespaceURI === XMLNS.ATOM10) {
   6.183 +            let version = documentElement.getAttribute('version');
   6.184 +            if (version === null) {
   6.185 +                version = '1.0';
   6.186 +            }
   6.187 +            if (version === '1.0') {
   6.188 +                return ['atom', version];
   6.189 +            }
   6.190 +        } else if (documentElement.nodeName === 'rss') {
   6.191 +            let version = documentElement.getAttribute('version');
   6.192 +            switch (version) {
   6.193 +                case '0.90':
   6.194 +                case '0.91':
   6.195 +                case '0.92':
   6.196 +                case '0.93':
   6.197 +                case '0.94':
   6.198 +                case '2.0':
   6.199 +                    return ['rss', version];
   6.200 +            }
   6.201 +        } else if (documentElement.localName.toLowerCase() === 'rdf' &&
   6.202 +                documentElement.getAttribute('xmlns') === XMLNS.RSS09) {
   6.203 +            return ['rss', '0.9'];
   6.204 +        }
   6.205 +
   6.206 +        return [undefined, undefined];
   6.207 +    }
   6.208 +
   6.209 +    constructor() {
   6.210 +        this.url = undefined;
   6.211 +        this.document = undefined;
   6.212 +    }
   6.213 +
   6.214 +    parseAtomLogo(logoElement) {
   6.215 +        let url = parseURL(logoElement.textContent.trim(), this.url);
   6.216 +        if (url === null) {
   6.217 +            throw new TypeError('invalid URL in <logo> element');
   6.218 +        }
   6.219 +        return new FeedLogo(url);
   6.220 +    }
   6.221 +
   6.222 +    parseAtomEntry(entryElement) {
   6.223 +        let title;
   6.224 +        let link;
   6.225 +        let date;
   6.226 +        let content;
   6.227 +        let titleElement = feedQueryXPath(this.document, entryElement,
   6.228 +                './atom:title');
   6.229 +        if (titleElement !== null) {
   6.230 +            title = titleElement.textContent.trim();
   6.231 +        }
   6.232 +
   6.233 +        let linkElement = feedQueryXPath(this.document, entryElement,
   6.234 +                './atom:link[@href][@rel="alternate"]');
   6.235 +        if (linkElement !== null) {
   6.236 +            link = parseURL(linkElement.getAttribute('href'), this.url);
   6.237 +        }
   6.238 +
   6.239 +        let updatedElement = feedQueryXPath(this.document, entryElement,
   6.240 +                './atom:updated');
   6.241 +        if (updatedElement !== null) {
   6.242 +            date = parseDate(updatedElement.textContent);
   6.243 +        }
   6.244 +
   6.245 +        let contentElement = feedQueryXPath(this.document, entryElement,
   6.246 +                './atom:content');
   6.247 +        if (contentElement === null) {
   6.248 +            contentElement = feedQueryXPath(this.document, entryElement,
   6.249 +                    './atom:summary');
   6.250 +        }
   6.251 +        if (contentElement !== null) {
   6.252 +            let contentType = contentElement.getAttribute('type');
   6.253 +            if (contentType === null) {
   6.254 +                contentType = 'text';
   6.255 +            }
   6.256 +            contentType = contentType.toLowerCase();
   6.257 +            if (contentType === 'xhtml') {
   6.258 +                content = contentElement.innerHTML;
   6.259 +            } else if (contentType === 'html') {
   6.260 +                content = contentElement.textContent;
   6.261 +            } else {
   6.262 +                let encodedContent =
   6.263 +                        encodeXML(contentElement.textContent.trim());
   6.264 +                content = `<pre>${encodedContent}</pre>`;
   6.265 +            }
   6.266 +        }
   6.267 +
   6.268 +        return new FeedEntry({title, link, date, content});
   6.269 +    }
   6.270 +
   6.271 +    parseAtomFeed() {
   6.272 +        let title;
   6.273 +        let subtitle;
   6.274 +        let logo;
   6.275 +        let entries = [];
   6.276 +        let documentElement = this.document.documentElement;
   6.277 +
   6.278 +        let titleElement = feedQueryXPath(this.document, documentElement,
   6.279 +                './atom:title');
   6.280 +        if (titleElement !== null) {
   6.281 +            title = titleElement.textContent.trim();
   6.282 +        }
   6.283 +
   6.284 +        let subtitleElement = feedQueryXPath(this.document, documentElement,
   6.285 +                './atom:subtitle');
   6.286 +        if (subtitleElement !== null) {
   6.287 +            subtitle = subtitleElement.textContent.trim();
   6.288 +        }
   6.289 +
   6.290 +        let logoElement = feedQueryXPath(this.document, documentElement,
   6.291 +                './atom:logo');
   6.292 +        if (logoElement !== null) {
   6.293 +            try {
   6.294 +                logo = this.parseAtomLogo(logoElement);
   6.295 +            } catch (e) {
   6.296 +                if (!(e instanceof TypeError)) {
   6.297 +                    throw e;
   6.298 +                }
   6.299 +            }
   6.300 +        }
   6.301 +
   6.302 +        let entryElements = feedQueryXPathAll(this.document, documentElement,
   6.303 +                './atom:entry');
   6.304 +        for (let entryElement of entryElements) {
   6.305 +            entries.push(this.parseAtomEntry(entryElement));
   6.306 +        }
   6.307 +
   6.308 +        return new Feed(this.url, {title, subtitle, logo, entries});
   6.309 +    }
   6.310 +
   6.311 +    parseRSS1Logo(imageElement) {
   6.312 +        let title;
   6.313 +        let urlElement = feedQueryXPath(this.document, imageElement,
   6.314 +                './rss:url');
   6.315 +        if (urlElement === null) {
   6.316 +            throw new TypeError('missing <url> element in <logo> element');
   6.317 +        }
   6.318 +        let url = parseURL(urlElement.textContent.trim(), this.url);
   6.319 +        if (url === null) {
   6.320 +            throw new TypeError('invalid URL in <logo> element');
   6.321 +        }
   6.322 +
   6.323 +        let titleElement = feedQueryXPath(this.document, imageElement,
   6.324 +                './rss:title');
   6.325 +        if (titleElement !== null) {
   6.326 +            title = titleElement.textContent.trim();
   6.327 +        }
   6.328 +
   6.329 +        return new FeedLogo(url, {title});
   6.330 +    }
   6.331 +
   6.332 +    parseRSS1Entry(itemElement) {
   6.333 +        let title;
   6.334 +        let link;
   6.335 +        let titleElement = feedQueryXPath(this.document, itemElement,
   6.336 +                './rss:title');
   6.337 +        if (titleElement !== null) {
   6.338 +            title = titleElement.textContent;
   6.339 +        }
   6.340 +
   6.341 +        let linkElement = feedQueryXPath(this.document, itemElement,
   6.342 +                './rss:link');
   6.343 +        if (linkElement !== null) {
   6.344 +            link = parseURL(linkElement.textContent, this.url);
   6.345 +        }
   6.346 +
   6.347 +        return new FeedEntry({title, link});
   6.348 +    }
   6.349 +
   6.350 +    parseRSS1Feed() {
   6.351 +        let title;
   6.352 +        let subtitle;
   6.353 +        let logo;
   6.354 +        let entries = [];
   6.355 +        let documentElement = this.document.documentElement;
   6.356 +        let titleElement = feedQueryXPath(this.document, documentElement,
   6.357 +                './rss:channel/rss:title');
   6.358 +        if (titleElement !== null) {
   6.359 +            title = titleElement.textContent;
   6.360 +        }
   6.361 +
   6.362 +        let descriptionElement = feedQueryXPath(this.document, documentElement,
   6.363 +                './channel/description');
   6.364 +        if (descriptionElement !== null) {
   6.365 +            subtitle = descriptionElement.textContent;
   6.366 +        }
   6.367 +
   6.368 +        let imageElement = feedQueryXPath(this.document, documentElement,
   6.369 +                './rss:image');
   6.370 +        if (imageElement !== null) {
   6.371 +            try {
   6.372 +                logo = this.parseRSS1Logo(imageElement);
   6.373 +            } catch (e) {
   6.374 +                if (!(e instanceof TypeError)) {
   6.375 +                    throw e;
   6.376 +                }
   6.377 +            }
   6.378 +        }
   6.379 +
   6.380 +        let itemElements = feedQueryXPathAll(this.document, documentElement,
   6.381 +                './rss:item');
   6.382 +        for (let itemElement of itemElements) {
   6.383 +            let entry = this.parseRSS1Entry(itemElement);
   6.384 +            if (typeof entry !== 'undefined') {
   6.385 +                entries.push(entry);
   6.386 +            }
   6.387 +        }
   6.388 +
   6.389 +        return new Feed(this.url, {title, subtitle, logo, entries});
   6.390 +    }
   6.391 +
   6.392 +    parseRSS2Logo(imageElement) {
   6.393 +        let title;
   6.394 +        let urlElement = feedQueryXPath(this.document, imageElement, './url');
   6.395 +        if (urlElement === null) {
   6.396 +            throw new TypeError('missing <url> element in <logo> element');
   6.397 +        }
   6.398 +        let url = parseURL(urlElement.textContent.trim(), this.url);
   6.399 +        if (url === null) {
   6.400 +            throw new TypeError('invalid URL in <logo> element');
   6.401 +        }
   6.402 +
   6.403 +        let titleElement = feedQueryXPath(this.document, imageElement,
   6.404 +                './title');
   6.405 +        if (titleElement !== null) {
   6.406 +            title = titleElement.textContent.trim();
   6.407 +        }
   6.408 +
   6.409 +        return new FeedLogo(url, {title});
   6.410 +    }
   6.411 +
   6.412 +    parseRSS2EntryFile(enclosureElement) {
   6.413 +        let type;
   6.414 +        let size;
   6.415 +        let url = parseURL(enclosureElement.getAttribute('url'), this.url);
   6.416 +        if (url === null) {
   6.417 +            throw new TypeError('invalid URL in <enclosure> element');
   6.418 +        }
   6.419 +
   6.420 +        let typeAttribute = enclosureElement.getAttribute('type');
   6.421 +        if (typeAttribute !== null) {
   6.422 +            type = typeAttribute;
   6.423 +        }
   6.424 +
   6.425 +        let length = parseInt(enclosureElement.getAttribute('length'),
   6.426 +                10);
   6.427 +        if (!isNaN(length)) {
   6.428 +            size = length;
   6.429 +        }
   6.430 +
   6.431 +        return new FeedEntryFile(url, {type, size});
   6.432 +    }
   6.433 +
   6.434 +    parseRSS2Entry(itemElement) {
   6.435 +        let title;
   6.436 +        let link;
   6.437 +        let date;
   6.438 +        let content;
   6.439 +        let files = [];
   6.440 +        let titleElement = feedQueryXPath(this.document, itemElement,
   6.441 +                './title');
   6.442 +        if (titleElement !== null) {
   6.443 +            title = titleElement.textContent;
   6.444 +        }
   6.445 +
   6.446 +        let linkElement = feedQueryXPath(this.document, itemElement, './link');
   6.447 +        if (linkElement !== null) {
   6.448 +            link = parseURL(linkElement.textContent, this.url);
   6.449 +        }
   6.450 +
   6.451 +        let pubDateElement = feedQueryXPath(this.document, itemElement,
   6.452 +                './pubDate');
   6.453 +        if (pubDateElement !== null) {
   6.454 +            date = parseDate(pubDateElement.textContent);
   6.455 +        }
   6.456 +
   6.457 +        let descriptionElement = feedQueryXPath(this.document, itemElement,
   6.458 +                './description');
   6.459 +        if (descriptionElement !== null) {
   6.460 +            content = descriptionElement.textContent.trim();
   6.461 +        }
   6.462 +
   6.463 +        for (let enclosureElement of
   6.464 +                feedQueryXPathAll(this.document, itemElement, './enclosure')) {
   6.465 +            try {
   6.466 +                let entryFile = this.parseRSS2EntryFile(enclosureElement);
   6.467 +                files.push(entryFile);
   6.468 +            } catch (e) {
   6.469 +                if (!(e instanceof TypeError)) {
   6.470 +                    throw e;
   6.471 +                }
   6.472 +            }
   6.473 +        }
   6.474 +
   6.475 +        return new FeedEntry({title, link, date, content, files});
   6.476 +    }
   6.477 +
   6.478 +    parseRSS2Feed() {
   6.479 +        let title;
   6.480 +        let subtitle;
   6.481 +        let logo;
   6.482 +        let entries = [];
   6.483 +        let documentElement = this.document.documentElement;
   6.484 +        let titleElement = feedQueryXPath(this.document, documentElement,
   6.485 +                './channel/title');
   6.486 +        if (titleElement !== null) {
   6.487 +            title = titleElement.textContent;
   6.488 +        }
   6.489 +
   6.490 +        let descriptionElement = feedQueryXPath(this.document, documentElement,
   6.491 +                './channel/description');
   6.492 +        if (descriptionElement !== null) {
   6.493 +            subtitle = descriptionElement.textContent;
   6.494 +        }
   6.495 +
   6.496 +        let imageElement = feedQueryXPath(this.document, documentElement,
   6.497 +                './channel/image');
   6.498 +        if (imageElement !== null) {
   6.499 +            try {
   6.500 +                logo = this.parseRSS2Logo(imageElement);
   6.501 +            } catch (e) {
   6.502 +                if (!(e instanceof TypeError)) {
   6.503 +                    throw e;
   6.504 +                }
   6.505 +            }
   6.506 +        }
   6.507 +
   6.508 +        let itemElements = feedQueryXPathAll(this.document, documentElement,
   6.509 +                './channel/item');
   6.510 +        for (let itemElement of itemElements) {
   6.511 +            let entry = this.parseRSS2Entry(itemElement);
   6.512 +            if (typeof entry !== 'undefined') {
   6.513 +                entries.push(entry);
   6.514 +            }
   6.515 +        }
   6.516 +
   6.517 +        return new Feed(this.url, {title, subtitle, logo, entries});
   6.518 +    }
   6.519 +
   6.520 +    parseFromString(xmlString, url) {
   6.521 +        this.url = url;
   6.522 +        this.document = new DOMParser().parseFromString(xmlString,
   6.523 +                'application/xml');
   6.524 +        if (this.document.documentElement.nodeName.toLowerCase() ===
   6.525 +                'parsererror') {
   6.526 +            throw new ParserError(this.document.documentElement.textContent);
   6.527 +        }
   6.528 +
   6.529 +        let [type, version] = this.constructor.probeFeed(this.document);
   6.530 +        if (type === 'atom') {
   6.531 +            return this.parseAtomFeed();
   6.532 +        } else if (type === 'rss') {
   6.533 +            if (version === '0.9') {
   6.534 +                return this.parseRSS1Feed();
   6.535 +            } else {
   6.536 +                return this.parseRSS2Feed();
   6.537 +            }
   6.538 +        }
   6.539 +        throw new UnsupportedFeedTypeError();
   6.540 +    }
   6.541 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/js/feed-preview.js	Thu Nov 08 16:30:34 2018 +0100
     7.3 @@ -0,0 +1,124 @@
     7.4 +/*
     7.5 + * Copyright (C) 2018 Guido Berhoerster <guido+feed-preview@berhoerster.name>
     7.6 + *
     7.7 + * This Source Code Form is subject to the terms of the Mozilla Public
     7.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     7.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7.10 + */
    7.11 +
    7.12 +'use strict';
    7.13 +
    7.14 +export function renderFeedPreview(feedPreviewDocument, feed) {
    7.15 +    // inject XSL stylesheet which transforms XHTML to HTML allowing the use of
    7.16 +    // the HTML DOM
    7.17 +    let xslFilename = browser.runtime.getURL('web_resources/xhtml-to-html.xsl');
    7.18 +    let xmlStylesheetNode =
    7.19 +            feedPreviewDocument.createProcessingInstruction('xml-stylesheet',
    7.20 +            `type="application/xslt+xml" href="${xslFilename}"`);
    7.21 +    feedPreviewDocument.firstChild.after(xmlStylesheetNode);
    7.22 +
    7.23 +    feedPreviewDocument.querySelector('link[rel=stylesheet]').href =
    7.24 +            browser.runtime.getURL('web_resources/style/feed-preview.css');
    7.25 +
    7.26 +    feedPreviewDocument.querySelector('title').textContent = feed.title;
    7.27 +    feedPreviewDocument.querySelector('#feed-title').textContent = feed.title;
    7.28 +    feedPreviewDocument.querySelector('#feed-subtitle').textContent =
    7.29 +            feed.subtitle;
    7.30 +
    7.31 +    if (typeof feed.logo !== 'undefined') {
    7.32 +        let feedLogoTemplate =
    7.33 +                feedPreviewDocument.querySelector('#feed-logo-template');
    7.34 +        let logoNode = feedPreviewDocument.importNode(feedLogoTemplate.content,
    7.35 +                true);
    7.36 +        let imgElement = logoNode.querySelector('#feed-logo');
    7.37 +        imgElement.setAttribute('src', feed.logo.url);
    7.38 +        imgElement.setAttribute('alt', feed.logo.title);
    7.39 +        feedPreviewDocument.querySelector('#feed-header').prepend(logoNode);
    7.40 +    }
    7.41 +
    7.42 +    let entryTemplateElement =
    7.43 +            feedPreviewDocument.querySelector('#entry-template');
    7.44 +    let entryTitleTemplateElement =
    7.45 +            feedPreviewDocument.querySelector('#entry-title-template');
    7.46 +    let entryTitleLinkedTemplateElement =
    7.47 +            feedPreviewDocument.querySelector('#entry-title-linked-template');
    7.48 +    let entryFileListTemplateElement =
    7.49 +            feedPreviewDocument.querySelector('#entry-files-list-template');
    7.50 +    let entryFileTemplateElement =
    7.51 +            feedPreviewDocument.querySelector('#entry-file-template');
    7.52 +    if (feed.entries.length === 0) {
    7.53 +        let hintTemplateElement =
    7.54 +                previewDocument.querySelector('#no-entries-hint-template');
    7.55 +        let hintNode = previewDocument.importNode(hintTemplateElement.content,
    7.56 +                true);
    7.57 +        hintNode.querySelector("#no-entries-hint").textContent =
    7.58 +            browser.i18n.getMessage('noEntriesHint');
    7.59 +
    7.60 +        previewDocument.body.append(hintNode);
    7.61 +    }
    7.62 +    for (let entry of feed.entries) {
    7.63 +        let entryNode =
    7.64 +                feedPreviewDocument.importNode(entryTemplateElement.content,
    7.65 +                true);
    7.66 +        let titleElement;
    7.67 +        let titleNode;
    7.68 +
    7.69 +        if (typeof entry.link !== 'undefined') {
    7.70 +            titleNode = feedPreviewDocument
    7.71 +                    .importNode(entryTitleLinkedTemplateElement.content, true);
    7.72 +            titleElement = titleNode.querySelector('.entry-link');
    7.73 +            titleElement.href = entry.link;
    7.74 +            titleElement.title = entry.title;
    7.75 +        } else {
    7.76 +            titleNode = feedPreviewDocument
    7.77 +                    .importNode(entryTitleTemplateElement.content, true);
    7.78 +            titleElement = titleNode.querySelector('.entry-title');
    7.79 +        }
    7.80 +        titleElement.textContent = entry.title;
    7.81 +        entryNode.querySelector('.entry-header').prepend(titleNode);
    7.82 +
    7.83 +        let timeElement = entryNode.querySelector('.entry-date > time');
    7.84 +        timeElement.textContent = entry.date.toLocaleString();
    7.85 +
    7.86 +        let contentElement = entryNode.querySelector('.entry-content');
    7.87 +        let contentDocument = new DOMParser().parseFromString(entry.content,
    7.88 +                'text/html');
    7.89 +        let stylesheetElement = contentDocument.createElement('link');
    7.90 +        stylesheetElement.rel = 'stylesheet';
    7.91 +        stylesheetElement.href =
    7.92 +                browser.runtime.getURL('web_resources/style/entry-content.css');
    7.93 +        contentDocument.head.appendChild(stylesheetElement);
    7.94 +        contentElement.srcdoc = new XMLSerializer()
    7.95 +                .serializeToString(contentDocument);
    7.96 +        contentElement.title = entry.title;
    7.97 +
    7.98 +        if (entry.files.length > 0) {
    7.99 +            let fileListNode = feedPreviewDocument
   7.100 +                    .importNode(entryFileListTemplateElement.content, true);
   7.101 +            fileListNode.querySelector('.entry-files-title').textContent =
   7.102 +                    browser.i18n.getMessage('filesTitle');
   7.103 +            let fileListElement =
   7.104 +                    fileListNode.querySelector('.entry-files-list');
   7.105 +
   7.106 +            for (let file of entry.files) {
   7.107 +                let fileNode = feedPreviewDocument
   7.108 +                        .importNode(entryFileTemplateElement.content, true);
   7.109 +
   7.110 +                let fileLinkElement =
   7.111 +                        fileNode.querySelector('.entry-file-link');
   7.112 +                fileLinkElement.href = file.url;
   7.113 +                fileLinkElement.title = file.filename;
   7.114 +                fileLinkElement.textContent = file.filename;
   7.115 +
   7.116 +                fileNode.querySelector('.entry-file-info').textContent =
   7.117 +                        `(${file.type}, ${file.size} bytes)`;
   7.118 +
   7.119 +                fileListElement.appendChild(fileNode);
   7.120 +            }
   7.121 +
   7.122 +            entryNode.querySelector('.entry').append(fileListNode);
   7.123 +        }
   7.124 +
   7.125 +        feedPreviewDocument.body.append(entryNode);
   7.126 +    }
   7.127 +}
     8.1 --- a/manifest.json.in	Sun Nov 04 10:03:05 2018 +0100
     8.2 +++ b/manifest.json.in	Thu Nov 08 16:30:34 2018 +0100
     8.3 @@ -24,24 +24,18 @@
     8.4          "webRequestBlocking"
     8.5      ],
     8.6      "background": {
     8.7 -        "scripts": [ "background.js" ]
     8.8 +        "page": "background.html"
     8.9      },
    8.10      "content_scripts": [
    8.11          {
    8.12              "matches": [ "http://*/*", "https://*/*", "file:///*" ],
    8.13 -            "js": [
    8.14 -                "content_scripts/feed-probe.js",
    8.15 -                "content_scripts/feed-preview.js"
    8.16 -            ]
    8.17 +            "js": [ "content_scripts/feed-probe.js" ]
    8.18          }
    8.19      ],
    8.20      "web_accessible_resources": [
    8.21 -        "web_resources/feed-preview.xhtml",
    8.22 -        "web_resources/arrow.svg",
    8.23 -        "web_resources/style/common.css",
    8.24 -        "web_resources/style/entry-content.css",
    8.25 -        "web_resources/style/feed-preview.css",
    8.26 -        "web_resources/style/photon-colors.css"
    8.27 +        "web_resources/xhtml-to-html.xsl",
    8.28 +        "web_resources/images/arrow.svg",
    8.29 +        "web_resources/style/*.css"
    8.30      ],
    8.31      "page_action": {
    8.32          "browser_style": true,
     9.1 --- a/web_resources/feed-preview.xhtml	Sun Nov 04 10:03:05 2018 +0100
     9.2 +++ b/web_resources/feed-preview.xhtml	Thu Nov 08 16:30:34 2018 +0100
     9.3 @@ -1,3 +1,5 @@
     9.4 +<?xml version="1.0" encoding="UTF-8"?>
     9.5 +<!DOCTYPE html>
     9.6  <html xmlns="http://www.w3.org/1999/xhtml">
     9.7    <head>
     9.8      <meta charset="utf-8"/>
     9.9 @@ -9,50 +11,49 @@
    9.10     file, You can obtain one at http://mozilla.org/MPL/2.0/.
    9.11  -->
    9.12      <meta name="viewport" content="width=device-width, initial-scale=1"/>
    9.13 -    <base href=""/>
    9.14 -    <link rel="stylesheet" href="style/feed-preview.css"/>
    9.15 +    <link rel="stylesheet" href=""/>
    9.16      <title></title>
    9.17    </head>
    9.18    <body>
    9.19 -  <template id="feed-logo-template">
    9.20 -    <img id="feed-logo" src="" alt=""/>
    9.21 -  </template>
    9.22 -  <template id="entry-template">
    9.23 -    <article>
    9.24 -      <details class="entry">
    9.25 -        <summary>
    9.26 -          <header class="entry-header">
    9.27 -            <p class="entry-date"><time></time></p>
    9.28 -          </header>
    9.29 -        </summary>
    9.30 -        <iframe class="entry-content" srcdoc="" title="" sandbox=""
    9.31 -        width="800" height="360"/>
    9.32 -      </details>
    9.33 -    </article>
    9.34 -  </template>
    9.35 -  <template id="entry-title-template">
    9.36 -    <h1 class="entry-title"></h1>
    9.37 -  </template>
    9.38 -  <template id="entry-title-linked-template">
    9.39 -    <h1 class="entry-title"><a class="entry-link" href="" title=""></a></h1>
    9.40 -  </template>
    9.41 -  <template id="entry-files-list-template">
    9.42 -    <footer class="entry-files">
    9.43 -      <h2 class="entry-files-title"></h2>
    9.44 -      <ul class="entry-files-list">
    9.45 -      </ul>
    9.46 -    </footer>
    9.47 -  </template>
    9.48 -  <template id="no-entries-hint-template">
    9.49 -    <p id="no-entries-hint"></p>
    9.50 -  </template>
    9.51 -  <template id="entry-file-template">
    9.52 -    <li class="entry-file"><a class="entry-file-link" href="" title=""></a>
    9.53 -    <span class="entry-file-info"></span></li>
    9.54 -  </template>
    9.55 -  <header id="feed-header">
    9.56 -    <h1 id="feed-title"></h1>
    9.57 -    <p id="feed-subtitle"></p>
    9.58 -  </header>
    9.59 +    <template id="feed-logo-template">
    9.60 +      <img id="feed-logo" src="" alt=""/>
    9.61 +    </template>
    9.62 +    <template id="entry-template">
    9.63 +      <article>
    9.64 +        <details class="entry">
    9.65 +          <summary>
    9.66 +            <header class="entry-header">
    9.67 +              <p class="entry-date"><time></time></p>
    9.68 +            </header>
    9.69 +          </summary>
    9.70 +          <iframe class="entry-content" srcdoc="" title="" sandbox=""
    9.71 +          width="800" height="360"></iframe>
    9.72 +        </details>
    9.73 +      </article>
    9.74 +    </template>
    9.75 +    <template id="entry-title-template">
    9.76 +      <h1 class="entry-title"></h1>
    9.77 +    </template>
    9.78 +    <template id="entry-title-linked-template">
    9.79 +      <h1 class="entry-title"><a class="entry-link" href="" title=""></a></h1>
    9.80 +    </template>
    9.81 +    <template id="entry-files-list-template">
    9.82 +      <footer class="entry-files">
    9.83 +        <h2 class="entry-files-title"></h2>
    9.84 +        <ul class="entry-files-list">
    9.85 +        </ul>
    9.86 +      </footer>
    9.87 +    </template>
    9.88 +    <template id="no-entries-hint-template">
    9.89 +      <p id="no-entries-hint"></p>
    9.90 +    </template>
    9.91 +    <template id="entry-file-template">
    9.92 +      <li class="entry-file"><a class="entry-file-link" href="" title=""></a>
    9.93 +      <span class="entry-file-info"></span></li>
    9.94 +    </template>
    9.95 +    <header id="feed-header">
    9.96 +      <h1 id="feed-title"></h1>
    9.97 +      <p id="feed-subtitle"></p>
    9.98 +    </header>
    9.99    </body>
   9.100  </html>
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/web_resources/xhtml-to-html.xsl	Thu Nov 08 16:30:34 2018 +0100
    10.3 @@ -0,0 +1,17 @@
    10.4 +<?xml version="1.0" encoding="UTF-8"?>
    10.5 +<!--
    10.6 +   Copyright (C) 2018 Guido Berhoerster <guido+feed-preview@berhoerster.name>
    10.7 +
    10.8 +   This Source Code Form is subject to the terms of the Mozilla Public
    10.9 +   License, v. 2.0. If a copy of the MPL was not distributed with this
   10.10 +   file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10.11 +-->
   10.12 +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   10.13 +  <xsl:output method="html" doctype-system="about:legacy-compat"
   10.14 +  encoding="UTF-8"/>
   10.15 +  <xsl:template match="@*|node()">
   10.16 +    <xsl:copy>
   10.17 +      <xsl:apply-templates select="@*|node()"/>
   10.18 +    </xsl:copy>
   10.19 +  </xsl:template>
   10.20 +</xsl:stylesheet>