mjml-parser-xml
Advanced tools
Comparing version 4.1.0-beta.3 to 4.1.0-beta.4
@@ -61,6 +61,2 @@ 'use strict'; | ||
var _addCDATASection = require('./helpers/addCDATASection'); | ||
var _addCDATASection2 = _interopRequireDefault(_addCDATASection); | ||
var _setEmptyAttributes = require('./helpers/setEmptyAttributes'); | ||
@@ -83,2 +79,6 @@ | ||
var isSelfClosing = function isSelfClosing(indexes, parser) { | ||
return indexes.startIndex === parser.startIndex && indexes.endIndex === parser.endIndex; | ||
}; | ||
function MJMLParser(xml) { | ||
@@ -101,3 +101,3 @@ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var CDATASections = (0, _flow2.default)((0, _filter2.default)(function (component) { | ||
var endingTags = (0, _flow2.default)((0, _filter2.default)(function (component) { | ||
return component.endingTag; | ||
@@ -110,9 +110,7 @@ }), (0, _map2.default)(function (component) { | ||
var safeXml = xml; | ||
safeXml = (0, _addCDATASection2.default)(CDATASections, safeXml); | ||
var mjml = null; | ||
var cur = null; | ||
var inInclude = !!includedIn.length; | ||
var inEndingTag = 0; | ||
var currentEndingTagIndexes = { startIndex: 0, endIndex: 0 }; | ||
@@ -122,3 +120,3 @@ var findTag = function findTag(tagName, tree) { | ||
}; | ||
var lineIndexes = indexesForNewLine(safeXml); | ||
var lineIndexes = indexesForNewLine(xml); | ||
@@ -204,3 +202,19 @@ var handleInclude = function handleInclude(file, line) { | ||
onopentag: function onopentag(name, attrs) { | ||
// eslint-disable-line consistent-return | ||
var isAnEndingTag = endingTags.indexOf(name) !== -1; | ||
if (inEndingTag > 0) { | ||
if (isAnEndingTag) inEndingTag += 1; | ||
return; | ||
} | ||
if (isAnEndingTag) { | ||
inEndingTag += 1; | ||
if (inEndingTag === 1) { | ||
// we're entering endingTag | ||
currentEndingTagIndexes.startIndex = parser.startIndex; | ||
currentEndingTagIndexes.endIndex = parser.endIndex; | ||
} | ||
} | ||
var line = (0, _findLastIndex2.default)(lineIndexes, function (i) { | ||
@@ -212,3 +226,4 @@ return i <= parser.startIndex; | ||
inInclude = true; | ||
return handleInclude(decodeURIComponent(attrs.path), line); | ||
handleInclude(decodeURIComponent(attrs.path), line); | ||
return; | ||
} | ||
@@ -240,3 +255,18 @@ | ||
}, | ||
onclosetag: function onclosetag() { | ||
onclosetag: function onclosetag(name) { | ||
if (endingTags.indexOf(name) !== -1) { | ||
inEndingTag -= 1; | ||
if (!inEndingTag) { | ||
// we're getting out of endingTag | ||
// if self-closing tag we don't get the content | ||
if (!isSelfClosing(currentEndingTagIndexes, parser)) { | ||
var val = xml.substring(currentEndingTagIndexes.endIndex + 1, parser.startIndex).trim(); | ||
if (val) cur.content = val; | ||
} | ||
} | ||
} | ||
if (inEndingTag > 0) return; | ||
if (inInclude) { | ||
@@ -249,13 +279,11 @@ inInclude = false; | ||
ontext: function ontext(text) { | ||
if (!text) { | ||
return; | ||
} | ||
if (inEndingTag > 0) return; | ||
var val = ('' + (cur && cur.content || '') + text).trim(); | ||
if (val) { | ||
cur.content = val; | ||
if (text && text.trim() && cur) { | ||
cur.content = ('' + (cur && cur.content || '') + text.trim()).trim(); | ||
} | ||
}, | ||
oncomment: function oncomment(data) { | ||
if (inEndingTag > 0) return; | ||
if (cur && keepComments) { | ||
@@ -277,3 +305,3 @@ cur.children.push({ | ||
parser.write(safeXml); | ||
parser.write(xml); | ||
parser.end(); | ||
@@ -280,0 +308,0 @@ |
{ | ||
"name": "mjml-parser-xml", | ||
"description": "mjml-parser-xml", | ||
"version": "4.1.0-beta.3", | ||
"version": "4.1.0-beta.4", | ||
"main": "lib/index.js", | ||
@@ -27,5 +27,5 @@ "repository": { | ||
"chai": "^4.1.1", | ||
"mjml": "^4.1.0-beta.3", | ||
"mjml-core": "^4.1.0-beta.3" | ||
"mjml": "^4.1.0-beta.4", | ||
"mjml-core": "^4.1.0-beta.4" | ||
} | ||
} |
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
20361
346