Created
September 26, 2016 14:13
-
-
Save Daylon/cb80b252a912875224eeaedfa560ee63 to your computer and use it in GitHub Desktop.
MJML postrender fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
var removeCDATA = exports.removeCDATA = function removeCDATA(str) { | |
return str.replace(/(?:<!-{0,2}\[CDATA\[){1,2}([^]*?)(?:\]\]-{0,2}>?){1,2}/gm, '$1'); | |
}; | |
var fixLegacyAttrs = exports.fixLegacyAttrs = function fixLegacyAttrs($) { | |
var legacyAttrs = ['align', 'valign', 'bgcolor', 'border', 'background']; | |
// https://github.com/facebook/react/issues/140 ... | |
// server side workaround to allow custom tags. | |
legacyAttrs.forEach(function (attr) { | |
var dataAttr = 'data-legacy-' + attr; | |
$('[' + dataAttr + ']').each(function () { | |
$(this).attr(attr, $(this).attr(dataAttr)); | |
$(this).removeAttr(dataAttr); | |
}); | |
}); | |
return $; | |
}; |
Before/after
/<!--\[CDATA\[([^]*?)\]\]-->/gm
/(?:<!-{0,2}\[CDATA\[){1,2}([^]*?)(?:\]\]-{0,2}>?){1,2}/gm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some component may be parsed twice, seeing their content twice embedded between CDATA tags, e.g.
… Which, once it gets through
postrender
will still have one remaining CDATA or]]
artefact.The key is to collect both regular CDATA tags and multiple concatenation. At the time of writing, I didn't find any case with more than two consecutive CDATAs.