Skip to content

Commit

Permalink
Fix inliner overwriting custom styles
Browse files Browse the repository at this point in the history
Fixes voidlabs#231
Also added removal code for data-mce-style to fix voidlabs#230
  • Loading branch information
bago committed Nov 11, 2016
1 parent d35dae3 commit ed38839
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/js/ext/inliner.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ var inlineDocument = require("juice/lib/inline")({}).inlineDocument;

var inlinerPlugin = function(vm) {
vm.inline = function(doc) {
// tinymce may have added style attributes to elements that will also have global styles to be inlined
$('[style]:not([replacedstyle])', doc).each(function(index, el) {
var $el = $(el);
$el.attr('replacedstyle', $el.attr('style'));
});

var style = [];
$('style[data-inline="true"]', doc).each(function(index, element) {
var content = $(element).html();
Expand Down
3 changes: 2 additions & 1 deletion src/js/viewmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ function initializeEditor(content, blockDefs, thumbPathConverter, galleryUrl) {
ko.applyBindings(viewModel, frameEl);

ko.cleanNode(frameEl);

if (viewModel.inline) viewModel.inline(frameEl.contentWindow.document);

// Obsolete method didn't work on IE11 when using "HTML5 doctype":
Expand All @@ -476,7 +477,7 @@ function initializeEditor(content, blockDefs, thumbPathConverter, galleryUrl) {
// Remove data-bind/data-block attributes
content = content.replace(/ data-bind="[^"]*"/gm, '');
// Remove trash leftover by TinyMCE
content = content.replace(/ data-mce-(href|src)="[^"]*"/gm, '');
content = content.replace(/ data-mce-(href|src|style)="[^"]*"/gm, '');

// Replace "replacedstyle" to "style" attributes (chrome puts replacedstyle after style)
content = content.replace(/ style="[^"]*"([^>]*) replaced(style="[^"]*")/gm, '$1 $2');
Expand Down

0 comments on commit ed38839

Please sign in to comment.