mirror of
https://github.com/alexadam/save-as-ebook.git
synced 2025-09-14 11:19:43 +00:00
fix for MathML not rendered correctly; Include style menu option not saved
This commit is contained in:
parent
8a8db5c1db
commit
77d622d460
3 changed files with 42 additions and 7 deletions
|
@ -10,8 +10,13 @@ var allowedTags = [
|
||||||
'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr',
|
'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr',
|
||||||
'math', 'maction', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot',
|
'math', 'maction', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot',
|
||||||
'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'msgroup', 'mlongdiv', 'mscarries',
|
'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'msgroup', 'mlongdiv', 'mscarries',
|
||||||
'mscarry', 'mstack'
|
'mscarry', 'mstack', 'semantics'
|
||||||
];
|
];
|
||||||
|
var mathMLTags = [
|
||||||
|
'math', 'maction', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot',
|
||||||
|
'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'msgroup', 'mlongdiv', 'mscarries',
|
||||||
|
'mscarry', 'mstack', 'semantics'
|
||||||
|
]
|
||||||
var cssClassesToTmpIds = {};
|
var cssClassesToTmpIds = {};
|
||||||
var tmpIdsToNewCss = {};
|
var tmpIdsToNewCss = {};
|
||||||
// src: https://idpf.github.io/a11y-guidelines/content/style/reference.html
|
// src: https://idpf.github.io/a11y-guidelines/content/style/reference.html
|
||||||
|
@ -34,10 +39,14 @@ function getImageSrc(srcTxt) {
|
||||||
if (srcTxt === '') {
|
if (srcTxt === '') {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
var isB64Img = isBase64Img(srcTxt);
|
|
||||||
var fileExtension = getFileExtension(srcTxt);
|
var fileExtension = getFileExtension(srcTxt);
|
||||||
|
if (fileExtension === '') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
var newImgFileName = 'img-' + (Math.floor(Math.random()*1000000*Math.random()*100000)) + '.' + fileExtension;
|
var newImgFileName = 'img-' + (Math.floor(Math.random()*1000000*Math.random()*100000)) + '.' + fileExtension;
|
||||||
|
|
||||||
|
var isB64Img = isBase64Img(srcTxt);
|
||||||
if (isB64Img) {
|
if (isB64Img) {
|
||||||
extractedImages.push({
|
extractedImages.push({
|
||||||
filename: newImgFileName, // TODO name
|
filename: newImgFileName, // TODO name
|
||||||
|
@ -197,14 +206,21 @@ function sanitize(rawContentString) {
|
||||||
|
|
||||||
if (tag === 'img') {
|
if (tag === 'img') {
|
||||||
var tmpAttrsTxt = '';
|
var tmpAttrsTxt = '';
|
||||||
|
let tmpSrc = ''
|
||||||
for (var i = 0; i < attrs.length; i++) {
|
for (var i = 0; i < attrs.length; i++) {
|
||||||
if (attrs[i].name === 'src') {
|
if (attrs[i].name === 'src') {
|
||||||
tmpAttrsTxt += ' src="' + getImageSrc(attrs[i].value) + '"';
|
tmpSrc = getImageSrc(attrs[i].value)
|
||||||
|
tmpAttrsTxt += ' src="' + tmpSrc + '"';
|
||||||
} else if (attrs[i].name === 'data-class') {
|
} else if (attrs[i].name === 'data-class') {
|
||||||
tmpAttrsTxt += ' class="' + attrs[i].value + '"';
|
tmpAttrsTxt += ' class="' + attrs[i].value + '"';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastFragment = tmpAttrsTxt.length === 0 ? '<img></img>' : '<img ' + tmpAttrsTxt + ' alt=""></img>';
|
if (tmpSrc === '') {
|
||||||
|
// ignore imgs without source
|
||||||
|
lastFragment = ''
|
||||||
|
} else {
|
||||||
|
lastFragment = tmpAttrsTxt.length === 0 ? '<img></img>' : '<img ' + tmpAttrsTxt + ' alt=""></img>';
|
||||||
|
}
|
||||||
} else if (tag === 'a') {
|
} else if (tag === 'a') {
|
||||||
var tmpAttrsTxt = '';
|
var tmpAttrsTxt = '';
|
||||||
for (var i = 0; i < attrs.length; i++) {
|
for (var i = 0; i < attrs.length; i++) {
|
||||||
|
@ -223,6 +239,15 @@ function sanitize(rawContentString) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastFragment = '<' + tag + ' ' + tmpAttrsTxt + '></' + tag + '>';
|
lastFragment = '<' + tag + ' ' + tmpAttrsTxt + '></' + tag + '>';
|
||||||
|
} else if (tag === 'math') {
|
||||||
|
var tmpAttrsTxt = '';
|
||||||
|
tmpAttrsTxt += ' xmlns="http://www.w3.org/1998/Math/MathML"';
|
||||||
|
for (var i = 0; i < attrs.length; i++) {
|
||||||
|
if (attrs[i].name === 'alttext') {
|
||||||
|
tmpAttrsTxt += ' alttext="' + attrs[i].value + '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastFragment = '<' + tag + ' ' + tmpAttrsTxt + '>';
|
||||||
} else {
|
} else {
|
||||||
var tmpAttrsTxt = '';
|
var tmpAttrsTxt = '';
|
||||||
for (var i = 0; i < attrs.length; i++) {
|
for (var i = 0; i < attrs.length; i++) {
|
||||||
|
@ -328,6 +353,10 @@ function extractCss(appliedStyles, callback) {
|
||||||
if (response.includeStyle) {
|
if (response.includeStyle) {
|
||||||
$('body').find('*').each(function (i, pre) {
|
$('body').find('*').each(function (i, pre) {
|
||||||
var $pre = $(pre);
|
var $pre = $(pre);
|
||||||
|
|
||||||
|
if (allowedTags.indexOf(pre.tagName.toLowerCase()) < 0) return;
|
||||||
|
if (mathMLTags.indexOf(pre.tagName.toLowerCase()) > -1) return;
|
||||||
|
|
||||||
if (!$pre.is(':visible')) {
|
if (!$pre.is(':visible')) {
|
||||||
$pre.replaceWith('');
|
$pre.replaceWith('');
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -102,7 +102,11 @@ chrome.runtime.sendMessage({
|
||||||
|
|
||||||
document.getElementById('includeStyleCheck').onclick = function () {
|
document.getElementById('includeStyleCheck').onclick = function () {
|
||||||
var includeStyleCheck = document.getElementById('includeStyleCheck');
|
var includeStyleCheck = document.getElementById('includeStyleCheck');
|
||||||
setIncludeStyle(includeStyleCheck.checked);
|
chrome.runtime.sendMessage({
|
||||||
|
type: "set include style",
|
||||||
|
includeStyle: includeStyleCheck.checked
|
||||||
|
}, function(response) {
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("editStyles").onclick = function() {
|
document.getElementById("editStyles").onclick = function() {
|
||||||
|
|
|
@ -134,8 +134,10 @@ function getFileExtension(fileName) {
|
||||||
tmpFileName = 'jpeg';
|
tmpFileName = 'jpeg';
|
||||||
} else if (tmpFileName === 'svg+xml') {
|
} else if (tmpFileName === 'svg+xml') {
|
||||||
tmpFileName = 'svg';
|
tmpFileName = 'svg';
|
||||||
} else if (tmpFileName.trim() === '') {
|
}
|
||||||
tmpFileName = '';
|
|
||||||
|
if (['png', 'gif', 'jpeg', 'svg'].indexOf(tmpFileName.trim()) < 0) {
|
||||||
|
return ''
|
||||||
}
|
}
|
||||||
return tmpFileName;
|
return tmpFileName;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue