Comparing version 2.0.0-beta.2 to 2.0.0-beta.3
@@ -621,2 +621,3 @@ var extracter = require('./extracter'); | ||
_code.add('main', '_formatterOptions.isConditionTrue = null;\n'); | ||
_code.add('main', '_formatterOptions.isAndOperator = null;\n'); | ||
_code.add('main', '_formatterOptions.isHidden = null;\n'); | ||
@@ -623,0 +624,0 @@ _code.add('main', '_formatterOptions.parentsData = ['+_dataObj+', '+_objParentNames.join(',')+'];\n'); |
@@ -538,3 +538,3 @@ var parser = require('./parser'); | ||
var _conditionalBlockDetected = []; | ||
var _emptyParts = []; | ||
var _newParts = []; | ||
for (var i = 0; i < _xmlParts.length; i++) { | ||
@@ -548,3 +548,3 @@ var _part = _xmlParts[i]; | ||
var _lastFormatter = _formatters[_nbFormatters - 1]; | ||
if (_lastFormatter.indexOf('showBegin') !== -1 || _lastFormatter.indexOf('hideBegin') !== -1) { // TODO show hide, TODO return error if not last | ||
if (_lastFormatter.indexOf('showBegin') !== -1 || _lastFormatter.indexOf('hideBegin') !== -1) { // TODO return error if not last | ||
_conditionalBlockDetected.push(_part); | ||
@@ -554,18 +554,21 @@ } | ||
var _beginPart = _conditionalBlockDetected.pop(); | ||
var _newPos = parser.findSafeConditionalBlockPosition(xml, _beginPart.pos, _part.pos); | ||
_beginPart.pos = _newPos[0] - 0.1; | ||
_part.pos = _newPos[1] - 0.2; | ||
_emptyParts.push({ | ||
obj : _beginPart.obj, | ||
formatters : [], | ||
pos : _beginPart.pos - 0.1, | ||
}); | ||
_emptyParts.push({ | ||
obj : _part.obj, | ||
formatters : [], | ||
pos : _part.pos + 0.1, | ||
}); | ||
var _safeXMLBlocks = parser.findSafeConditionalBlockPosition(xml, _beginPart.pos, _part.pos); | ||
// TODO manage when nothing can be removed | ||
if (_safeXMLBlocks.length > 0) { | ||
_newParts.push({ obj : _beginPart.obj, formatters : [], pos : _safeXMLBlocks[0][0] - 0.2 }); | ||
_beginPart.pos = _safeXMLBlocks[0][0] - 0.1; | ||
_part.pos = _safeXMLBlocks[0][1] - 0.2; | ||
_newParts.push({ obj : _beginPart.obj, formatters : [], pos : _safeXMLBlocks[0][1] - 0.1 }); | ||
for (var j = 1; j < _safeXMLBlocks.length; j++) { | ||
var _safeXMLBlock = _safeXMLBlocks[j]; | ||
// generate empty part before everything to avoid breaking XML with arrays | ||
_newParts.push({ obj : _beginPart.obj, formatters : [] , pos : _safeXMLBlock[0] - 0.2 }); | ||
_newParts.push({ attr : _beginPart.attr, obj : _beginPart.obj, formatters : _beginPart.formatters, pos : _safeXMLBlock[0] - 0.1 }); | ||
_newParts.push({ attr : _beginPart.attr, obj : _beginPart.obj, formatters : _part.formatters , pos : _safeXMLBlock[1] - 0.2 }); | ||
_newParts.push({ obj : _beginPart.obj, formatters : [] , pos : _safeXMLBlock[1] - 0.1 }); | ||
} | ||
} | ||
} | ||
} | ||
descriptor[_objName].xmlParts = descriptor[_objName].xmlParts.concat(_emptyParts); | ||
descriptor[_objName].xmlParts = descriptor[_objName].xmlParts.concat(_newParts); | ||
} | ||
@@ -572,0 +575,0 @@ } |
@@ -579,5 +579,5 @@ var helper = require('./helper'); | ||
// edge case: when there is not XML tag, return directly | ||
// edge case: when there is no XML tags, return directly | ||
if (_tag === null || _tag.index >= endSearchIndex) { | ||
return [startSearchIndex, endSearchIndex]; | ||
return [[startSearchIndex, endSearchIndex, 0]]; | ||
} | ||
@@ -606,3 +606,12 @@ | ||
} | ||
if (_newCandidate !== null && _lastCandidate !== null && (_lastCandidate[0] > _newCandidate[0] || _newCandidate[0] <= _lastCandidate[1] && _newCandidate[2] === _lastCandidate[2] ) ) { | ||
// merge wirth previous detected XML part | ||
if ( _newCandidate !== null | ||
&& _lastCandidate !== null | ||
// when the new XML part is nested in the previous one | ||
&& (_lastCandidate[0] > _newCandidate[0] | ||
// when the new XML part is adjacent or overlaps with the previous part, and is at the same depth | ||
|| _newCandidate[2] === _lastCandidate[2] | ||
&& _newCandidate[0] <= _lastCandidate[1] | ||
) | ||
) { | ||
_lastCandidate[0] = Math.min(_newCandidate[0], _lastCandidate[0]); | ||
@@ -629,33 +638,29 @@ _lastCandidate[1] = _newCandidate[1]; | ||
} | ||
// tarling non XML char | ||
if (_tag !== null && _lastTagEndingPos < _tag.index && _lastCandidate[2] === _currentXMLDepth) { | ||
_lastCandidate[1] = Math.min(_tag.index, endSearchIndex); | ||
// include trailing non XML char, same depth | ||
if (_tag !== null && _lastTagEndingPos < _tag.index) { | ||
var _newEndingTag = Math.min(_tag.index, endSearchIndex); | ||
if (_lastCandidate[2] === _currentXMLDepth) { | ||
_lastCandidate[1] = _newEndingTag; | ||
} | ||
else { | ||
if (_newEndingTag > _lastTagEndingPos) { | ||
_validCandidates.push([_lastTagEndingPos, _newEndingTag, _currentXMLDepth]); | ||
} | ||
} | ||
} | ||
var _minimalXmlDepth = Infinity; | ||
var _largest = 0; | ||
var _chosenCandidate = null; | ||
_lastCandidate = null; | ||
var _newCandidates = []; | ||
for (var i = 0; i < _validCandidates.length; i++) { | ||
var _validCandidate = _validCandidates[i]; | ||
if (_validCandidate[2] < _minimalXmlDepth) { | ||
_minimalXmlDepth = _validCandidate[2]; | ||
_chosenCandidate = _validCandidate; | ||
// merge consecutive valid XML-part | ||
if (_lastCandidate !== null && _validCandidate[2] === _lastCandidate[2] && _validCandidate[0] <= _lastCandidate[1]) { | ||
_lastCandidate[1] = _validCandidate[1]; | ||
} | ||
else if (_validCandidate[2] === _minimalXmlDepth) { | ||
// merge consecutive valid XML-part | ||
if (_validCandidate[0] <= _chosenCandidate[1]) { | ||
_chosenCandidate[1] = _validCandidate[1]; | ||
} | ||
// or choose the longest XML string | ||
else { | ||
var _dist = _validCandidate[1] - _validCandidate[0]; | ||
if (_dist > _largest) { | ||
_largest = _dist; | ||
_chosenCandidate = _validCandidate; | ||
} | ||
} | ||
else { | ||
_newCandidates.push(_validCandidate); | ||
_lastCandidate = _validCandidate; | ||
} | ||
} | ||
return _chosenCandidate.slice(0,2); | ||
return _newCandidates; | ||
} | ||
@@ -662,0 +667,0 @@ |
{ | ||
"name": "carbone", | ||
"description": "Fast, Simple and Powerful report generator. Injects JSON and produces PDF, DOCX, XLSX, ODT, PPTX, ODS, ...!", | ||
"version": "2.0.0-beta.2", | ||
"version": "2.0.0-beta.3", | ||
"bin": "bin/carbone", | ||
@@ -6,0 +6,0 @@ "main": "./lib", |
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
408121
7426