mjml-react
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -10,3 +10,4 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
import { renderToJSON } from './utils/render-to-json'; | ||
export { render, renderToMjml, renderToJSON }; | ||
import { renderToJSON2 } from './utils/render-to-json2'; | ||
export { render, renderToMjml, renderToJSON, renderToJSON2 }; | ||
export { Mjml } from './mjml'; | ||
@@ -13,0 +14,0 @@ export { MjmlAccordion } from './mjml-accordion'; |
@@ -8,3 +8,3 @@ var _excluded = ["children", "dangerouslySetInnerHTML"]; | ||
import ReactDOMServer from 'react-dom/server'; | ||
var matchHtmlRegExp = /["'&<>$]/; | ||
import { noop, escapeTextForBrowser, trimContent } from './render-utils'; | ||
var reconciler = ReactReconciler({ | ||
@@ -114,81 +114,2 @@ supportsMutation: true, | ||
})); | ||
} | ||
function escapeHtml(string) { | ||
var str = '' + string; | ||
var match = matchHtmlRegExp.exec(str); | ||
if (!match) { | ||
return str; | ||
} | ||
var escape; | ||
var html = ''; | ||
var index; | ||
var lastIndex = 0; | ||
for (index = match.index; index < str.length; index++) { | ||
switch (str.charCodeAt(index)) { | ||
case 34: | ||
// " | ||
escape = '"'; | ||
break; | ||
case 36: | ||
// $ | ||
escape = '$'; | ||
break; | ||
case 38: | ||
// & | ||
escape = '&'; | ||
break; | ||
case 39: | ||
// ' | ||
escape = '''; // modified from escape-html; used to be ''' | ||
break; | ||
case 60: | ||
// < | ||
escape = '<'; | ||
break; | ||
case 62: | ||
// > | ||
escape = '>'; | ||
break; | ||
default: | ||
continue; | ||
} | ||
if (lastIndex !== index) { | ||
html += str.substring(lastIndex, index); | ||
} | ||
lastIndex = index + 1; | ||
html += escape; | ||
} | ||
return lastIndex !== index ? html + str.substring(lastIndex, index) : html; | ||
} | ||
function escapeTextForBrowser(text) { | ||
if (typeof text === 'boolean' || typeof text === 'number') { | ||
return '' + text; | ||
} | ||
return escapeHtml(text); | ||
} | ||
function noop() {} | ||
function trimContent(child) { | ||
if (child.content) { | ||
child.content = child.content.trim(); | ||
} else if (child.children) { | ||
child.children.forEach(trimContent); | ||
} | ||
} |
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import mjml2json from 'mjml2json'; | ||
import { renderToJSON, Mjml, MjmlStyle, MjmlBody, MjmlSection, MjmlColumn, MjmlImage, MjmlText, MjmlDivider, MjmlRaw, MjmlHead, MjmlButton, renderToMjml } from '../src'; | ||
import { renderToJSON, renderToJSON2, Mjml, MjmlStyle, MjmlBody, MjmlSection, MjmlColumn, MjmlImage, MjmlText, MjmlDivider, MjmlRaw, MjmlHead, MjmlButton, renderToMjml } from '../src'; | ||
import { MjmlComment, MjmlConditionalComment, MjmlTrackingPixel, MjmlYahooStyle } from '../extensions'; | ||
@@ -36,7 +36,9 @@ var useCases = [/*#__PURE__*/React.createElement(Mjml, null), /*#__PURE__*/React.createElement(Mjml, null, "content"), /*#__PURE__*/React.createElement(Mjml, null, /*#__PURE__*/React.createElement(MjmlRaw, null, "content")), /*#__PURE__*/React.createElement(Mjml, null, /*#__PURE__*/React.createElement(MjmlRaw, null, /*#__PURE__*/React.createElement("div", null, "content"))), /*#__PURE__*/React.createElement(Mjml, null, '<b />'), /*#__PURE__*/React.createElement(Mjml, null, /*#__PURE__*/React.createElement(MjmlHead, null, /*#__PURE__*/React.createElement(MjmlStyle, null, '.class {color: red;}'))), /*#__PURE__*/React.createElement(Mjml, null, /*#__PURE__*/React.createElement(MjmlBody, null, /*#__PURE__*/React.createElement(MjmlRaw, null, /*#__PURE__*/React.createElement("div", null, '<b/>'), /*#__PURE__*/React.createElement("p", null, "hello ' & world ")))), /*#__PURE__*/React.createElement(MjmlRaw, null, /*#__PURE__*/React.createElement("div", { | ||
spaceInBetween: " in between " | ||
}, ' ', "Hello World ! ", /*#__PURE__*/React.createElement("span", null, " Hello World ! "), ' ')]; | ||
}, ' ', "Hello World ! ", /*#__PURE__*/React.createElement("span", null, " Hello World ! "), ' '), /*#__PURE__*/React.createElement(MjmlRaw, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", null, "Nested Element")))]; | ||
useCases.forEach(function (tree, i) { | ||
it("should render usecase " + i, function () { | ||
var mjml = renderToMjml(tree); | ||
expect(mjml2json(mjml)).to.eql(renderToJSON(tree)); | ||
var base = mjml2json(mjml); | ||
expect(base).to.eql(renderToJSON(tree)); | ||
expect(base).to.eql(renderToJSON2(tree)); | ||
}); | ||
@@ -43,0 +45,0 @@ }); // it('measure times', () => { |
"use strict"; | ||
exports.__esModule = true; | ||
exports.MjmlHtml = exports.MjmlTrackingPixel = exports.MjmlYahooStyle = exports.MjmlConditionalComment = exports.MjmlComment = void 0; | ||
exports.MjmlYahooStyle = exports.MjmlTrackingPixel = exports.MjmlHtml = exports.MjmlConditionalComment = exports.MjmlComment = void 0; | ||
@@ -6,0 +6,0 @@ var _mjmlComment = require("./mjml-comment"); |
"use strict"; | ||
exports.__esModule = true; | ||
exports.MjmlWrapper = exports.MjmlTitle = exports.MjmlText = exports.MjmlTable = exports.MjmlStyle = exports.MjmlSpacer = exports.MjmlSocialElement = exports.MjmlSocial = exports.MjmlSection = exports.MjmlRaw = exports.MjmlPreview = exports.MjmlNavbarLink = exports.MjmlNavbar = exports.MjmlImage = exports.MjmlHero = exports.MjmlHead = exports.MjmlGroup = exports.MjmlFont = exports.MjmlDivider = exports.MjmlColumn = exports.MjmlClass = exports.MjmlCarouselImage = exports.MjmlCarousel = exports.MjmlButton = exports.MjmlBreakpoint = exports.MjmlBody = exports.MjmlAttributes = exports.MjmlAll = exports.MjmlAccordionTitle = exports.MjmlAccordionText = exports.MjmlAccordionElement = exports.MjmlAccordion = exports.Mjml = void 0; | ||
exports.render = render; | ||
exports.renderToMjml = renderToMjml; | ||
exports.MjmlWrapper = exports.MjmlTitle = exports.MjmlText = exports.MjmlTable = exports.MjmlStyle = exports.MjmlSpacer = exports.MjmlSocialElement = exports.MjmlSocial = exports.MjmlSection = exports.MjmlRaw = exports.MjmlPreview = exports.MjmlNavbarLink = exports.MjmlNavbar = exports.MjmlImage = exports.MjmlHero = exports.MjmlHead = exports.MjmlGroup = exports.MjmlFont = exports.MjmlDivider = exports.MjmlColumn = exports.MjmlClass = exports.MjmlCarouselImage = exports.MjmlCarousel = exports.MjmlButton = exports.MjmlBreakpoint = exports.MjmlBody = exports.MjmlAttributes = exports.MjmlAll = exports.MjmlAccordionTitle = exports.MjmlAccordionText = exports.MjmlAccordionElement = exports.MjmlAccordion = exports.Mjml = void 0; | ||
@@ -16,2 +16,6 @@ var _server = _interopRequireDefault(require("react-dom/server")); | ||
var _renderToJson2 = require("./utils/render-to-json2"); | ||
exports.renderToJSON2 = _renderToJson2.renderToJSON2; | ||
var _mjml2 = require("./mjml"); | ||
@@ -18,0 +22,0 @@ |
"use strict"; | ||
exports.__esModule = true; | ||
exports.addQueryParams = exports.getTextAlign = exports.toMobileFontSize = exports.useHttps = exports.fixConditionalComment = exports.namedEntityToHexCode = void 0; | ||
exports.useHttps = exports.toMobileFontSize = exports.namedEntityToHexCode = exports.getTextAlign = exports.fixConditionalComment = exports.addQueryParams = void 0; | ||
@@ -6,0 +6,0 @@ var _htmlEntities = require("./html-entities"); |
@@ -12,2 +12,4 @@ "use strict"; | ||
var _renderUtils = require("./render-utils"); | ||
var _excluded = ["children", "dangerouslySetInnerHTML"]; | ||
@@ -19,3 +21,2 @@ | ||
var matchHtmlRegExp = /["'&<>$]/; | ||
var reconciler = (0, _reactReconciler["default"])({ | ||
@@ -47,3 +48,3 @@ supportsMutation: true, | ||
if (typeof attrKey === 'string') { | ||
res.attributes[key] = escapeTextForBrowser(attrKey); | ||
res.attributes[key] = (0, _renderUtils.escapeTextForBrowser)(attrKey); | ||
} | ||
@@ -70,3 +71,3 @@ }); | ||
appendChildToContainer: function appendChildToContainer(container, child) { | ||
trimContent(child); | ||
(0, _renderUtils.trimContent)(child); | ||
container.resultObj = child; | ||
@@ -97,3 +98,3 @@ }, | ||
parent.content += escapeTextForBrowser(child); | ||
parent.content += (0, _renderUtils.escapeTextForBrowser)(child); | ||
} | ||
@@ -105,10 +106,10 @@ } else { | ||
}, | ||
prepareForCommit: noop, | ||
resetAfterCommit: noop, | ||
clearContainer: noop, | ||
appendChild: noop, | ||
finalizeInitialChildren: noop, | ||
getChildHostContext: noop, | ||
getRootHostContext: noop, | ||
shouldSetTextContent: noop | ||
prepareForCommit: _renderUtils.noop, | ||
resetAfterCommit: _renderUtils.noop, | ||
clearContainer: _renderUtils.noop, | ||
appendChild: _renderUtils.noop, | ||
finalizeInitialChildren: _renderUtils.noop, | ||
getChildHostContext: _renderUtils.noop, | ||
getRootHostContext: _renderUtils.noop, | ||
shouldSetTextContent: _renderUtils.noop | ||
}); | ||
@@ -130,81 +131,2 @@ | ||
})); | ||
} | ||
function escapeHtml(string) { | ||
var str = '' + string; | ||
var match = matchHtmlRegExp.exec(str); | ||
if (!match) { | ||
return str; | ||
} | ||
var escape; | ||
var html = ''; | ||
var index; | ||
var lastIndex = 0; | ||
for (index = match.index; index < str.length; index++) { | ||
switch (str.charCodeAt(index)) { | ||
case 34: | ||
// " | ||
escape = '"'; | ||
break; | ||
case 36: | ||
// $ | ||
escape = '$'; | ||
break; | ||
case 38: | ||
// & | ||
escape = '&'; | ||
break; | ||
case 39: | ||
// ' | ||
escape = '''; // modified from escape-html; used to be ''' | ||
break; | ||
case 60: | ||
// < | ||
escape = '<'; | ||
break; | ||
case 62: | ||
// > | ||
escape = '>'; | ||
break; | ||
default: | ||
continue; | ||
} | ||
if (lastIndex !== index) { | ||
html += str.substring(lastIndex, index); | ||
} | ||
lastIndex = index + 1; | ||
html += escape; | ||
} | ||
return lastIndex !== index ? html + str.substring(lastIndex, index) : html; | ||
} | ||
function escapeTextForBrowser(text) { | ||
if (typeof text === 'boolean' || typeof text === 'number') { | ||
return '' + text; | ||
} | ||
return escapeHtml(text); | ||
} | ||
function noop() {} | ||
function trimContent(child) { | ||
if (child.content) { | ||
child.content = child.content.trim(); | ||
} else if (child.children) { | ||
child.children.forEach(trimContent); | ||
} | ||
} |
@@ -45,7 +45,9 @@ "use strict"; | ||
spaceInBetween: " in between " | ||
}, ' ', "Hello World ! ", /*#__PURE__*/_react["default"].createElement("span", null, " Hello World ! "), ' ')]; | ||
}, ' ', "Hello World ! ", /*#__PURE__*/_react["default"].createElement("span", null, " Hello World ! "), ' '), /*#__PURE__*/_react["default"].createElement(_src.MjmlRaw, null, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", null, "Nested Element")))]; | ||
useCases.forEach(function (tree, i) { | ||
it("should render usecase " + i, function () { | ||
var mjml = (0, _src.renderToMjml)(tree); | ||
(0, _chai.expect)((0, _mjml2json["default"])(mjml)).to.eql((0, _src.renderToJSON)(tree)); | ||
var base = (0, _mjml2json["default"])(mjml); | ||
(0, _chai.expect)(base).to.eql((0, _src.renderToJSON)(tree)); | ||
(0, _chai.expect)(base).to.eql((0, _src.renderToJSON2)(tree)); | ||
}); | ||
@@ -52,0 +54,0 @@ }); // it('measure times', () => { |
@@ -1,1 +0,1 @@ | ||
{"name":"mjml-react","version":"2.0.0","license":"MIT","author":{"name":"Mantas Miliukas","email":"mantasm@wix.com"},"homepage":"https://github.com/wix-incubator/mjml-react","bugs":"https://github.com/wix-incubator/mjml-react/issues","main":"dist/src/index.js","files":["extensions.js","utils.js","dist"],"publishConfig":{"registry":"https://registry.npmjs.org/","versionBumpStrategy":"patch"},"scripts":{"start":"yoshi start","pretest":"yoshi build","test":"yoshi test --mocha","posttest":"yoshi lint"},"devDependencies":{"babel-plugin-transform-runtime":"~6.23.0","chai":"~4.1.0","mjml":"^4.6.3","mjml2json":"^1.0.1","puppeteer":"^1.4.0","react":"^17.0.0","react-dom":"^17.0.0","@wix/yoshi":"^4.186.0"},"peerDependencies":{"mjml":"^4.1.2","react":"^17.0.0","react-dom":"^17.0.0"},"yoshi":{"hmr":"auto"},"module":"dist/es/src/index.js","dependencies":{"@babel/runtime":"^7.14.6","babel-runtime":"~6.25.0","color":"^3.1.3","react-reconciler":"^0.26.1"},"babel":{"plugins":["transform-runtime"],"presets":["wix"]},"eslintConfig":{"extends":"yoshi","rules":{"quote-props":0,"indent":["error",2,{"SwitchCase":1,"ignoredNodes":["JSXElement","JSXElement *"]}]}},"gitHead":"7894e20e52db6340e8bad2cbb731f6a3f2430db4","repository":{"type":"git","url":"https://github.com/wix-incubator/mjml-react","directory":"."}} | ||
{"name":"mjml-react","version":"2.0.1","license":"MIT","author":{"name":"Mantas Miliukas","email":"mantasm@wix.com"},"homepage":"https://github.com/wix-incubator/mjml-react","bugs":"https://github.com/wix-incubator/mjml-react/issues","main":"dist/src/index.js","files":["extensions.js","utils.js","dist"],"publishConfig":{"registry":"https://registry.npmjs.org/","versionBumpStrategy":"patch"},"scripts":{"start":"yoshi start","pretest":"yoshi build","test":"yoshi test --mocha","posttest":"yoshi lint"},"devDependencies":{"babel-plugin-transform-runtime":"~6.23.0","chai":"~4.1.0","mjml":"^4.6.3","mjml2json":"^1.0.1","puppeteer":"^1.4.0","react":"^17.0.0","react-dom":"^17.0.0","@wix/yoshi":"^4.186.0"},"peerDependencies":{"mjml":"^4.1.2","react":"^17.0.0","react-dom":"^17.0.0"},"yoshi":{"hmr":"auto"},"module":"dist/es/src/index.js","dependencies":{"@babel/runtime":"^7.14.6","babel-runtime":"~6.25.0","color":"^3.1.3","react-reconciler":"^0.26.1"},"babel":{"plugins":["transform-runtime"],"presets":["wix"]},"eslintConfig":{"extends":"yoshi","rules":{"quote-props":0,"indent":["error",2,{"SwitchCase":1,"ignoredNodes":["JSXElement","JSXElement *"]}]}},"gitHead":"338135b3c53b0cd19075507e6158fa1072ef1ff3","repository":{"type":"git","url":"https://github.com/wix-incubator/mjml-react","directory":"."}} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
251173
119
4199