Fix an creating duplicates mediatags in markdown preview

pull/1/head
yflory 7 years ago
parent 9060464f37
commit fef97ed60e

@ -45,9 +45,7 @@ define([
var src = '/blob/' + hexFileName.slice(0,2) + '/' + hexFileName; var src = '/blob/' + hexFileName.slice(0,2) + '/' + hexFileName;
var mt = '<media-tag src="' + src + '" data-crypto-key="cryptpad:' + parsed.hashData.key + '">'; var mt = '<media-tag src="' + src + '" data-crypto-key="cryptpad:' + parsed.hashData.key + '">';
if (mediaMap[src]) { if (mediaMap[src]) {
mediaMap[src].forEach(function (n) { mt += mediaMap[src];
mt += n.outerHTML;
});
} }
mt += '</media-tag>'; mt += '</media-tag>';
return mt; return mt;
@ -168,11 +166,7 @@ define([
var unsafe_newHtmlFixed = newHtml.replace(pattern, function (all, tag, src) { var unsafe_newHtmlFixed = newHtml.replace(pattern, function (all, tag, src) {
var mt = tag; var mt = tag;
if (mediaMap[src]) { if (mediaMap[src]) { mt += mediaMap[src]; }
mediaMap[src].forEach(function (n) {
mt += n.outerHTML;
});
}
return mt + '</media-tag>'; return mt + '</media-tag>';
}); });
@ -193,9 +187,11 @@ define([
var observer = new MutationObserver(function(mutations) { var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) { mutations.forEach(function(mutation) {
if (mutation.type === 'childList') { if (mutation.type === 'childList') {
//console.log(el.outerHTML); var list_values = [].slice.call(mutation.target.children)
var list_values = [].slice.call(el.children); .map(function (el) { return el.outerHTML })
mediaMap[el.getAttribute('src')] = list_values; .join('');
mediaMap[mutation.target.getAttribute('src')] = list_values;
observer.disconnect();
} }
}); });
}); });

Loading…
Cancel
Save