diff --git a/lib/parse-template.js b/lib/parse-template.js index ed201b5..442f68c 100644 --- a/lib/parse-template.js +++ b/lib/parse-template.js @@ -17,7 +17,9 @@ module.exports = (handledTags, baseTemplatesCacheSize) => { Promise.resolve().then(() => { const templateCutter = new TemplateCutter(); - const cuttedBaseTemplate = templateCutter.cut(baseTemplate); + const cuttedBaseTemplate = templateCutter.cut( + templateCutter.remove(baseTemplate) + ); const chunks = transform.applyTransforms( cuttedBaseTemplate, diff --git a/lib/template-cutter.js b/lib/template-cutter.js index c2c11e2..4be4f0b 100644 --- a/lib/template-cutter.js +++ b/lib/template-cutter.js @@ -4,6 +4,8 @@ const MARKED_PARTS_TO_IGNORE = /.*?/gims; const IGNORED_PART_WITH_INDEX = //gm; +const MARKED_PARTS_TO_REMOVE = + /.*?/gims; function replaceIgnorePart(ignoredPartIndex) { return ``; @@ -31,6 +33,20 @@ class TemplateCutter { }); } + /** + * Remove base templates special parts which marked with the help of special HTML comments: + * and + * before and after a content which you want to remove before parsing + * + * @example
{ 'TailorX can not find an ignored part 100 of the current template during restoring!' ); }); + + it('should remove marked parts from the base template', () => { + const baseTemplate = + '' + + '' + + '' + + '' + + '' + + ' ' + + '' + + '' + + '
' + + '' + + '
' + + '' + + '
' + + '' + + '
' + + '' + + ''; + + const expectedTemplate = + '' + + '' + + '' + + '' + + '' + + ' ' + + '' + + '
' + + '' + + '
' + + '' + + ''; + + const result = templateCutter.remove(baseTemplate); + assert.equal(result, expectedTemplate); + }); });