mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
filter out background and font settings in internal paste
should fix https://anki.tenderapp.com/discussions/beta-testing/842-issue-when-copy-pasting-add-edit-and-browse-windows and https://anki.tenderapp.com/discussions/beta-testing/840-copy-paste-in-anki-editor-causes-copied-text-to-include-redundant-tags-which-is-deterimental-to-ux-when-using-night-mode-addon this change will of course prevent these attributes from being copied when they were manually included in the field instead of implicitly set on the parent - I don't see a good way to distinguish between the two cases
This commit is contained in:
parent
48405c0ee7
commit
4dbb87e4c1
1 changed files with 21 additions and 5 deletions
|
@ -312,16 +312,18 @@ function hideDupes() {
|
|||
}
|
||||
|
||||
var pasteHTML = function (html, internal) {
|
||||
if (!internal) {
|
||||
html = filterHTML(html);
|
||||
}
|
||||
html = filterHTML(html, internal);
|
||||
setFormat("inserthtml", html);
|
||||
};
|
||||
|
||||
var filterHTML = function (html) {
|
||||
var filterHTML = function (html, internal) {
|
||||
// wrap it in <top> as we aren't allowed to change top level elements
|
||||
var top = $.parseHTML("<ankitop>" + html + "</ankitop>")[0];
|
||||
filterNode(top);
|
||||
if (internal) {
|
||||
filterInternalNode(top);
|
||||
} else {
|
||||
filterNode(top);
|
||||
}
|
||||
var outHtml = top.innerHTML;
|
||||
//console.log(`input html: ${html}`);
|
||||
//console.log(`outpt html: ${outHtml}`);
|
||||
|
@ -366,6 +368,20 @@ function convertDivToNewline(node, isParagraph) {
|
|||
node.outerHTML = html;
|
||||
}
|
||||
|
||||
// filtering from another field
|
||||
var filterInternalNode = function (node) {
|
||||
if (node.tagName === "SPAN") {
|
||||
node.style.removeProperty("background-color");
|
||||
node.style.removeProperty("font-size");
|
||||
node.style.removeProperty("font-family");
|
||||
}
|
||||
// recurse
|
||||
for (i = 0; i < node.childNodes.length; i++) {
|
||||
filterInternalNode(node.childNodes[i]);
|
||||
}
|
||||
};
|
||||
|
||||
// filtering from external sources
|
||||
var filterNode = function (node) {
|
||||
// text node?
|
||||
if (node.nodeType === 3) {
|
||||
|
|
Loading…
Reference in a new issue