From 979704289c278203042a394e13690c7e8e8f1d9b Mon Sep 17 00:00:00 2001 From: Michael Atwood Date: Mon, 29 Feb 2016 11:11:03 -0500 Subject: [PATCH 1/3] XML to HTML tag fix. * The method used to load the spine items into iframes for IE does not * (cannot?) maintain the content type. All documents end up being treated * as HTML. This breaks EPUBs (in particular the CFI generation) that leverage * XML since many self closed tags are invalid in HTML. * The 'fix'/hack for now is to parse the spine item and replace invalid * self closing tags with html valid closing tags. --- js/Readium.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/js/Readium.js b/js/Readium.js index 53c940a73..7a3846aad 100644 --- a/js/Readium.js +++ b/js/Readium.js @@ -64,6 +64,39 @@ define(['readium_shared_js/globals', 'text!version.json', 'jquery', 'underscore' contentDocumentHtml = contentDocumentHtml.replace(/[\s]*<\/title>/g, '<title>TITLE'); contentDocumentHtml = contentDocumentHtml.replace(//g, 'TITLE'); + // When using the IE iframe loader all documents are loaded as html. EPUBs are valid XML so self closing + // XML tags must be converted to html in order to not break the browser. + var validSelfClosingTags = [ + 'area', + 'base', + 'br', + 'col', + 'command', + 'embed', + 'hr', + 'img', + 'input', + 'keygen', + 'link', + 'meta', + 'param', + 'source', + 'track', + 'wbr' + ]; + + var replacementFunc = function (tag) { + var tokens = tag.match(/<(.*)\/>/i)[1].split(' '); + var tagName = tokens[0]; + if (validSelfClosingTags.indexOf(tagName) === -1) { + return '<' + tokens.join(' ') + '>' + ''; + } else { + return tag; + } + }; + + contentDocumentHtml = contentDocumentHtml.replace(/<[\s]*[\S][\s]*[^>]*\/>/gi, replacementFunc); + return contentDocumentHtml; }; From 0123c7e12d2e7e2f846c3c8ac6bc23d31b5151a5 Mon Sep 17 00:00:00 2001 From: Michael Atwood Date: Tue, 5 Apr 2016 13:48:51 -0400 Subject: [PATCH 2/3] Regex fix breaking with newlines. --- js/Readium.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/Readium.js b/js/Readium.js index 7a3846aad..73811bb39 100644 --- a/js/Readium.js +++ b/js/Readium.js @@ -86,7 +86,7 @@ define(['readium_shared_js/globals', 'text!version.json', 'jquery', 'underscore' ]; var replacementFunc = function (tag) { - var tokens = tag.match(/<(.*)\/>/i)[1].split(' '); + var tokens = tag.match(/^<([\S|\s]*?)\/>$/im)[1].split(' '); var tagName = tokens[0]; if (validSelfClosingTags.indexOf(tagName) === -1) { return '<' + tokens.join(' ') + '>' + ''; From 1447d74ae228dbef41e7f60a0751d17a764fb602 Mon Sep 17 00:00:00 2001 From: Michael Atwood Date: Tue, 5 Apr 2016 14:00:51 -0400 Subject: [PATCH 3/3] Removing 'm' option as it was not necessary. --- js/Readium.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/Readium.js b/js/Readium.js index 73811bb39..dec09be80 100644 --- a/js/Readium.js +++ b/js/Readium.js @@ -86,7 +86,7 @@ define(['readium_shared_js/globals', 'text!version.json', 'jquery', 'underscore' ]; var replacementFunc = function (tag) { - var tokens = tag.match(/^<([\S|\s]*?)\/>$/im)[1].split(' '); + var tokens = tag.match(/^<([\S|\s]*?)\/>$/i)[1].split(' '); var tagName = tokens[0]; if (validSelfClosingTags.indexOf(tagName) === -1) { return '<' + tokens.join(' ') + '>' + '';