Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML to HTML tag fix. #136

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions js/Readium.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,39 @@ define(['readium_shared_js/globals', 'text!version.json', 'jquery', 'underscore'
contentDocumentHtml = contentDocumentHtml.replace(/<title>[\s]*<\/title>/g, '<title>TITLE</title>');
contentDocumentHtml = contentDocumentHtml.replace(/<title[\s]*\/>/g, '<title>TITLE</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(/^<([\S|\s]*?)\/>$/i)[1].split(' ');
var tagName = tokens[0];
if (validSelfClosingTags.indexOf(tagName) === -1) {
return '<' + tokens.join(' ') + '>' + '</' + tokens[0] + '>';
} else {
return tag;
}
};

contentDocumentHtml = contentDocumentHtml.replace(/<[\s]*[\S][\s]*[^>]*\/>/gi, replacementFunc);

return contentDocumentHtml;
};

Expand Down