diff --git a/assets/mustache-tidy.js b/assets/mustache-tidy.js index c38d678..a30a95f 100644 --- a/assets/mustache-tidy.js +++ b/assets/mustache-tidy.js @@ -1089,6 +1089,8 @@ var endsWithTag = utils.endsWithTag; var log = debug.log; var regs = { spaces: new RegExp('\\s+', 'g'), + startSpaces: new RegExp('^\\s* '), + endSpaces: new RegExp(' \\s*$'), tagName: new RegExp('(?:[^"\']+|"[^"]+"|\'[^\']+\')', 'g'), tag: new RegExp('\\{\\{\\s*([#^/])([^}]*)\\}\\}', 'g') }; @@ -1202,7 +1204,7 @@ function mustacheTidy(html, options) { // Perform tidy on single text DOM node function tidyTextNode(node, level) { - node.nodeValue = node.nodeValue.trim(); + node.nodeValue = smartTrim(node.nodeValue); // Remove empty text nodes if (!node.nodeValue.length && node.parentElement) { @@ -1389,6 +1391,20 @@ function mustacheTidy(html, options) { opened.node = closed.node = null; } + + // Trim text, leaving single start and ending spaces + function smartTrim(text) { + var hasStartSpace = !!regs.startSpaces.exec(text); + var hasEndSpace = !!regs.endSpaces.exec(text); + + text = text.trim(); + if (!text.length) return ''; + + if (hasStartSpace) text = ' ' + text; + if (hasEndSpace) text = text + ' '; + + return text; + } } diff --git a/assets/mustache-tidy.min.js b/assets/mustache-tidy.min.js index d4435c1..4bf2377 100644 --- a/assets/mustache-tidy.min.js +++ b/assets/mustache-tidy.min.js @@ -1 +1 @@ -var mustacheTidy=function(e){function n(t){if(o[t])return o[t].exports;var d=o[t]={i:t,l:!1,exports:{}};return e[t].call(d.exports,d,d.exports,n),d.l=!0,d.exports}var o={};return n.m=e,n.c=o,n.i=function(e){return e},n.d=function(e,o,t){n.o(e,o)||Object.defineProperty(e,o,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(o,"a",o),o},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n(n.s=10)}([function(e,n,o){var t=o(3);if(t.isFrontEnd)e.exports={jsdom:null,Node:Node};else{var d=o(!function(){var e=new Error('Cannot find module "jsdom"');throw e.code="MODULE_NOT_FOUND",e}());d.defaultDocumentFeatures={FetchExternalResources:!1,ProcessExternalResources:!1};var l=o(!function(){var e=new Error('Cannot find module "jsdom/lib/jsdom/living/generated/Node.js"');throw e.code="MODULE_NOT_FOUND",e}());e.exports={jsdom:d.jsdom,Node:l.expose.Window.Node}}},function(e,n,o){function t(e){g=e}function d(){if(g.debug){if(a.isFrontEnd)return console.log.apply(console,arguments);for(var e=Array.prototype.slice.apply(arguments),n=0;n\n",r=e.childNodes;t++;for(var a=0;a\n"}function o(e){return e?r(" ",4*e):""}if(g.debug){var t=n(e);d("result html: "),d(t)}}function i(e,n){function o(e){var n=e.node,o=n.nodeValue,t=e.index,l=e.tag.length;n.nodeValue=o.substring(0,t+1)+"#"+o.substr(t+2,l-4)+"#"+o.substring(t-1+l),d("replace ->",o,"<- with ->",n.nodeValue)}if(g.debug){var t=null;for(var l in e){t=e[l];for(var i=0;i=n.level?(v("-------------- extend tag both ways starting from closed"),i(e,n,!0),l(e,n)):(v("-------------- extend tag both ways starting from opened"),l(e,n,!0),i(e,n))}function l(e,n,o){v("-------------- extend tag forward");var t=e.level,d=e.node,l=null;for(!e.node.nextSibling&&c(e)||(l=g(n.tag),e.node.parentElement.appendChild(l));;)if(t--,d=d.parentElement,d.nextSibling){if(u(e,t),d.parentElement.insertBefore(e.node,d.nextSibling),o?d.parentElement.contains(n.node):t<=n.level)break;l=g(n.tag),d.parentElement.appendChild(l)}}function i(e,n,o){v("-------------- extend tag back");var t=n.level,d=n.node.parentElement,l=null;for(!n.node.previousSibling&&p(n)||(l=g(e.tag),d.insertBefore(l,d.firstChild)),d=n.node;;)if(t--,d=d.parentElement,d.previousSibling){if(u(n,t),d.parentElement.insertBefore(n.node,d),o?d.parentElement.contains(e.node):t<=e.level)break;l=g(e.tag),d.parentElement.insertBefore(l,d.parentElement.firstChild)}}var r=o(0),a=o(2),s=o(1),u=a.updateTextNodeData,g=a.createTextNode,p=a.startsWithTag,c=a.endsWithTag,f=r.Node,v=s.log;e.exports={init:t,extendSeparatedTagParts:d,extendTagForward:l,extendTagBack:i}},function(e,n,o){function t(e){u.init(e),s.init(e)}function d(e){e.opened.node&&e.closed&&i(e.opened)&&(h("-- fix table tag: ",e),l(e.opened,e.closed))}function l(e,n){function o(t){if(t.nodeType===v.ELEMENT_NODE&&t.firstChild)if(x[t.nodeName])t.insertBefore(f(e.tag),t.firstChild),t.appendChild(f(n.tag));else for(var d=0;d=0);var d=t.opened.node&&t.opened.name===e.opened.name&&t.opened.type===e.opened.type;if(!d)return null;var l=!1;if(e.opened.node.previousSibling===t.closed.node)l=v(e.opened)&&h(t.closed);else if(e.opened.node===t.closed.node){var i=t.closed.node.nodeValue.substring(t.closed.index,e.opened.index);l=i.trim().length===t.closed.tag.length}return l?t:null}function i(e,n){x("-- merge with:",n),v(e.opened)&&h(e.opened)?e.opened.node.parentElement.removeChild(e.opened.node):u(e.opened,!0),v(n.closed)&&h(n.closed)?n.closed.node.parentElement.removeChild(n.closed.node):u(n.closed,!0);for(var o in e.closed)n.closed[o]=e.closed[o];return e.opened.node=null,e.closed.node=null,n.opened.improveKey}function r(e){for(var n=e.opened.level;s(e);)a(e);var o=e.opened.level,t=n!==o;if(T[o]||(T[o]=[]),t){var d=T[n];if(d&&d.length){var l=d[d.length-1];l===e&&d.pop()}T[o].push(e)}else{var i=T[n].length,l=i?T[n][i-1]:null;l&&l===e||T[n].push(e)}return t}function a(e){var n=e.opened,o=e.closed,t=n.node.parentElement,d=t.parentElement;h(n)||u(n),d.insertBefore(n.node,t),v(o)||u(o),t.nextSibling?d.insertBefore(o.node,t.nextSibling):d.appendChild(o.node),n.level--,o.level--}function s(e){var n=e.opened,o=e.closed,t=n.node.parentElement;return t&&t!==E&&t.parentElement&&v(n)&&h(o)&&!n.node.previousSibling&&!o.node.nextSibling}function u(e,n){var o=e.node.nodeValue;e.node.nodeValue=o.substring(0,e.index)+m(" ",e.tag.length)+o.substring(e.index+e.tag.length),N.push(e.node),n||f(e)}var g=o(0),p=o(2),c=o(1),f=(g.Node,p.updateTextNodeData),v=p.startsWithTag,h=p.endsWithTag,m=p.repeatString,x=c.log,E=null,b=[],T={},N=[],y=null;e.exports={init:t,run:d}},function(e,n,o){function t(e){v.init(e),f.init(e),y=[]}function d(e,n){N("closing tag is in ancestor node of opening tag"),m(e)&&!E(e.node.previousSibling)?(N("--------------- move opened tag up outside"),s(e,n.level)):x(e)&&!E(e.node.nextSibling)&&(N("--------------- move opened tag up inside"),u(e,n.level)),e.level!==n.level&&m(n)&&n.node.previousSibling.contains(e.node)&&(N("--------------- move closed tag down inside"),a(n,e.level,e.node))}function l(e,n){N("closed tag is contained inside open"),x(n)&&!b(n.node.nextSibling)?(N("--------------- move closed tag up outside"),u(n,e.level)):m(n)&&!E(n.node.previousSibling)&&(N("--------------- move closed tag up inside"),s(n,e.level)),e.level!==n.level&&x(e)&&e.node.nextSibling.contains(n.node)&&(N("--------------- move opened tag down inside"),r(e,n.level,n.node))}function i(e,n){N("opening and closing tags are not in ancestor nodes of each other"),m(e)&&!E(e.node.previousSibling)?(N("--------------- move opened tag up outside"),s(e,n.level,n.node)):x(e)&&!E(e.node.nextSibling)&&(N("--------------- move opened tag up inside"),u(e,n.level,n.node)),x(n)&&!b(n.node.nextSibling)?(N("--------------- move closed tag up outside"),u(n,e.level,e.node)):m(n)&&!E(n.node.previousSibling)&&(N("--------------- move closed tag up inside"),s(n,e.level,e.node))}function r(e,n,o){for(var t=e.node.nextSibling;e.leveln||o&&!t.parentElement.contains(o))&&!E(t.previousSibling));e.node.nodeValue.length!==e.tag.length&&(p(e),h(e)),t.parentElement.insertBefore(e.node,t)}function u(e,n,o){var t=e.node;do e.level--,t=t.parentElement;while((e.level>n||o&&!t.parentElement.contains(o))&&!b(t.nextSibling));e.node.nodeValue.length!==e.tag.length&&(p(e),h(e));var d=t.parentElement,l=t.nextSibling;l?d.insertBefore(e.node,l):d.appendChild(e.node)}function g(){for(var e=null;e=y.pop();)e.node.nodeValue=e.node.nodeValue.replace(e.placeholder,"")}function p(e){var n=e.node.nodeValue,o=e.tag.length,t="{#"+T("_",o-4)+"#}";e.node.nodeValue=n.substring(0,e.index)+t+n.substring(e.index+o),y.push({node:e.node,placeholder:t})}var c=o(0),f=o(2),v=o(1),h=f.updateTextNodeData,m=f.startsWithTag,x=f.endsWithTag,E=f.isDataElement,b=f.isFullDataElement,T=f.repeatString,N=(c.Node,v.log),y=[];e.exports={init:t,handleCaseClosedIsAncestor:d,handleCaseOpenedIsAncestor:l,handleCaseSeparateTrees:i,removePlaceholders:g}},function(e,n,o){function t(e){r.init(e),s=e.root}function d(e,n,o){var t=e.node,i=t.parentElement,r="both"===o?e.tag+n.tag:e.tag,a=!i||i===s||!i.parentElement||i.childNodes.length>1||!u[i.nodeName];if(!a){var g=r===t.nodeValue.trim();if(!g&&"both"===o){var p=t.nodeValue,c=p.substring(0,e.index)+p.substring(e.index+e.tag.length,n.index)+p.substring(n.index+n.tag.length);g=!c.trim().length}if(g&&(i.parentElement.replaceChild(t,i),e.level--,!t.parentElement.children.length)){var f=l(e,n,o);o=f?"both":o,d(e,n,o)}}}function l(e,n,o){for(var t=e.node,d=e.node,l="both"===o,i=[];;){if(t=t.previousSibling,!t||t.nodeType!==a.TEXT_NODE)break;if(t===n.node)l=!0,e.index+=t.nodeValue.length,e.node.nodeValue=t.nodeValue+e.node.nodeValue,n.node=e.node;else if(t.nodeValue.trim().length)break;i.push(t)}for(;;){if(d=d.nextSibling,!d||d.nodeType!==a.TEXT_NODE)break;if(d===n.node)l=!0,n.index+=e.node.nodeValue.length,e.node.nodeValue=e.node.nodeValue+d.nodeValue,n.node=e.node;else if(d.nodeValue.trim().length)break;i.push(d)}for(var r=e.node.parentElement,s=0;s\n",r=e.childNodes;o++;for(var a=0;a\n"}function t(e){return e?r(" ",4*e):""}if(p.debug){var o=n(e);d("result html: "),d(o)}}function i(e,n){function t(e){var n=e.node,t=n.nodeValue,o=e.index,l=e.tag.length;n.nodeValue=t.substring(0,o+1)+"#"+t.substr(o+2,l-4)+"#"+t.substring(o-1+l),d("replace ->",t,"<- with ->",n.nodeValue)}if(p.debug){var o=null;for(var l in e){o=e[l];for(var i=0;i=n.level?(v("-------------- extend tag both ways starting from closed"),i(e,n,!0),l(e,n)):(v("-------------- extend tag both ways starting from opened"),l(e,n,!0),i(e,n))}function l(e,n,t){v("-------------- extend tag forward");var o=e.level,d=e.node,l=null;for(!e.node.nextSibling&&c(e)||(l=p(n.tag),e.node.parentElement.appendChild(l));;)if(o--,d=d.parentElement,d.nextSibling){if(u(e,o),d.parentElement.insertBefore(e.node,d.nextSibling),t?d.parentElement.contains(n.node):o<=n.level)break;l=p(n.tag),d.parentElement.appendChild(l)}}function i(e,n,t){v("-------------- extend tag back");var o=n.level,d=n.node.parentElement,l=null;for(!n.node.previousSibling&&g(n)||(l=p(e.tag),d.insertBefore(l,d.firstChild)),d=n.node;;)if(o--,d=d.parentElement,d.previousSibling){if(u(n,o),d.parentElement.insertBefore(n.node,d),t?d.parentElement.contains(e.node):o<=e.level)break;l=p(e.tag),d.parentElement.insertBefore(l,d.parentElement.firstChild)}}var r=t(0),a=t(2),s=t(1),u=a.updateTextNodeData,p=a.createTextNode,g=a.startsWithTag,c=a.endsWithTag,f=r.Node,v=s.log;e.exports={init:o,extendSeparatedTagParts:d,extendTagForward:l,extendTagBack:i}},function(e,n,t){function o(e){u.init(e),s.init(e)}function d(e){e.opened.node&&e.closed&&i(e.opened)&&(h("-- fix table tag: ",e),l(e.opened,e.closed))}function l(e,n){function t(o){if(o.nodeType===v.ELEMENT_NODE&&o.firstChild)if(x[o.nodeName])o.insertBefore(f(e.tag),o.firstChild),o.appendChild(f(n.tag));else for(var d=0;d=0);var d=o.opened.node&&o.opened.name===e.opened.name&&o.opened.type===e.opened.type;if(!d)return null;var l=!1;if(e.opened.node.previousSibling===o.closed.node)l=v(e.opened)&&h(o.closed);else if(e.opened.node===o.closed.node){var i=o.closed.node.nodeValue.substring(o.closed.index,e.opened.index);l=i.trim().length===o.closed.tag.length}return l?o:null}function i(e,n){x("-- merge with:",n),v(e.opened)&&h(e.opened)?e.opened.node.parentElement.removeChild(e.opened.node):u(e.opened,!0),v(n.closed)&&h(n.closed)?n.closed.node.parentElement.removeChild(n.closed.node):u(n.closed,!0);for(var t in e.closed)n.closed[t]=e.closed[t];return e.opened.node=null,e.closed.node=null,n.opened.improveKey}function r(e){for(var n=e.opened.level;s(e);)a(e);var t=e.opened.level,o=n!==t;if(T[t]||(T[t]=[]),o){var d=T[n];if(d&&d.length){var l=d[d.length-1];l===e&&d.pop()}T[t].push(e)}else{var i=T[n].length,l=i?T[n][i-1]:null;l&&l===e||T[n].push(e)}return o}function a(e){var n=e.opened,t=e.closed,o=n.node.parentElement,d=o.parentElement;h(n)||u(n),d.insertBefore(n.node,o),v(t)||u(t),o.nextSibling?d.insertBefore(t.node,o.nextSibling):d.appendChild(t.node),n.level--,t.level--}function s(e){var n=e.opened,t=e.closed,o=n.node.parentElement;return o&&o!==E&&o.parentElement&&v(n)&&h(t)&&!n.node.previousSibling&&!t.node.nextSibling}function u(e,n){var t=e.node.nodeValue;e.node.nodeValue=t.substring(0,e.index)+m(" ",e.tag.length)+t.substring(e.index+e.tag.length),N.push(e.node),n||f(e)}var p=t(0),g=t(2),c=t(1),f=(p.Node,g.updateTextNodeData),v=g.startsWithTag,h=g.endsWithTag,m=g.repeatString,x=c.log,E=null,b=[],T={},N=[],y=null;e.exports={init:o,run:d}},function(e,n,t){function o(e){v.init(e),f.init(e),y=[]}function d(e,n){N("closing tag is in ancestor node of opening tag"),m(e)&&!E(e.node.previousSibling)?(N("--------------- move opened tag up outside"),s(e,n.level)):x(e)&&!E(e.node.nextSibling)&&(N("--------------- move opened tag up inside"),u(e,n.level)),e.level!==n.level&&m(n)&&n.node.previousSibling.contains(e.node)&&(N("--------------- move closed tag down inside"),a(n,e.level,e.node))}function l(e,n){N("closed tag is contained inside open"),x(n)&&!b(n.node.nextSibling)?(N("--------------- move closed tag up outside"),u(n,e.level)):m(n)&&!E(n.node.previousSibling)&&(N("--------------- move closed tag up inside"),s(n,e.level)),e.level!==n.level&&x(e)&&e.node.nextSibling.contains(n.node)&&(N("--------------- move opened tag down inside"),r(e,n.level,n.node))}function i(e,n){N("opening and closing tags are not in ancestor nodes of each other"),m(e)&&!E(e.node.previousSibling)?(N("--------------- move opened tag up outside"),s(e,n.level,n.node)):x(e)&&!E(e.node.nextSibling)&&(N("--------------- move opened tag up inside"),u(e,n.level,n.node)),x(n)&&!b(n.node.nextSibling)?(N("--------------- move closed tag up outside"),u(n,e.level,e.node)):m(n)&&!E(n.node.previousSibling)&&(N("--------------- move closed tag up inside"),s(n,e.level,e.node))}function r(e,n,t){for(var o=e.node.nextSibling;e.leveln||t&&!o.parentElement.contains(t))&&!E(o.previousSibling));e.node.nodeValue.length!==e.tag.length&&(g(e),h(e)),o.parentElement.insertBefore(e.node,o)}function u(e,n,t){var o=e.node;do e.level--,o=o.parentElement;while((e.level>n||t&&!o.parentElement.contains(t))&&!b(o.nextSibling));e.node.nodeValue.length!==e.tag.length&&(g(e),h(e));var d=o.parentElement,l=o.nextSibling;l?d.insertBefore(e.node,l):d.appendChild(e.node)}function p(){for(var e=null;e=y.pop();)e.node.nodeValue=e.node.nodeValue.replace(e.placeholder,"")}function g(e){var n=e.node.nodeValue,t=e.tag.length,o="{#"+T("_",t-4)+"#}";e.node.nodeValue=n.substring(0,e.index)+o+n.substring(e.index+t),y.push({node:e.node,placeholder:o})}var c=t(0),f=t(2),v=t(1),h=f.updateTextNodeData,m=f.startsWithTag,x=f.endsWithTag,E=f.isDataElement,b=f.isFullDataElement,T=f.repeatString,N=(c.Node,v.log),y=[];e.exports={init:o,handleCaseClosedIsAncestor:d,handleCaseOpenedIsAncestor:l,handleCaseSeparateTrees:i,removePlaceholders:p}},function(e,n,t){function o(e){r.init(e),s=e.root}function d(e,n,t){var o=e.node,i=o.parentElement,r="both"===t?e.tag+n.tag:e.tag,a=!i||i===s||!i.parentElement||i.childNodes.length>1||!u[i.nodeName];if(!a){var p=r===o.nodeValue.trim();if(!p&&"both"===t){var g=o.nodeValue,c=g.substring(0,e.index)+g.substring(e.index+e.tag.length,n.index)+g.substring(n.index+n.tag.length);p=!c.trim().length}if(p&&(i.parentElement.replaceChild(o,i),e.level--,!o.parentElement.children.length)){var f=l(e,n,t);t=f?"both":t,d(e,n,t)}}}function l(e,n,t){for(var o=e.node,d=e.node,l="both"===t,i=[];;){if(o=o.previousSibling,!o||o.nodeType!==a.TEXT_NODE)break;if(o===n.node)l=!0,e.index+=o.nodeValue.length,e.node.nodeValue=o.nodeValue+e.node.nodeValue,n.node=e.node;else if(o.nodeValue.trim().length)break;i.push(o)}for(;;){if(d=d.nextSibling,!d||d.nodeType!==a.TEXT_NODE)break;if(d===n.node)l=!0,n.index+=e.node.nodeValue.length,e.node.nodeValue=e.node.nodeValue+d.nodeValue,n.node=e.node;else if(d.nodeValue.trim().length)break;i.push(d)}for(var r=e.node.parentElement,s=0;sData'); + expect(result).toBe('
Data
'); }); it('should not handle single opening tag', function() { @@ -20,7 +20,7 @@ describe('Basic html processing', function() { `; var result = tidy(input); - expect(result).toBe('
{{#tag}}
'); + expect(result).toBe('
{{#tag}}
'); }); it('should not handle single closing tag', function() { @@ -31,7 +31,7 @@ describe('Basic html processing', function() { `; var result = tidy(input); - expect(result).toBe('
{{/tag}}
'); + expect(result).toBe('
{{/tag}}
'); }); it('should correctly handle input edge cases', function() { @@ -71,4 +71,35 @@ describe('Basic html processing', function() { result = tidy(input); expect(result).toBe('data'); }); + + it('should correctly handle   tags', function() { + var input = ` +
+ {{ foo  }} +

+ Data + {{  #bar  }} + Data +

+ Data + {{ /bar }} +
+ `; + + var result = tidy(input); + expect(result).toBe( + '
' + + ' {{ foo  }} ' + + '

' + + 'Data' + + ' {{  #bar  }} ' + + 'Data' + + '{{ /bar }}' + + '

' + + '{{  #bar  }}' + + 'Data' + + ' {{ /bar }} ' + + '
' + ); + }); }); diff --git a/spec/extend-tags-spec.js b/spec/extend-tags-spec.js index 12281cc..8cfe478 100644 --- a/spec/extend-tags-spec.js +++ b/spec/extend-tags-spec.js @@ -27,7 +27,7 @@ describe('Extending tags', function() { '
' + '
' + '
' + - 'Data{{#tag}}Data' + + ' Data{{#tag}}Data ' + '{{/tag}}' + '
' + '{{#tag}}' + @@ -43,7 +43,7 @@ describe('Extending tags', function() { '{{#tag}}' + 'Data' + 'Data' + - '{{/tag}}' + + ' {{/tag}} ' + '
' ); }); @@ -71,7 +71,7 @@ describe('Extending tags', function() { var result = tidy(input); expect(result).toBe( '
' + - '{{#tag}}' + + ' {{#tag}} ' + 'Data' + 'Data' + '{{/tag}}' + @@ -87,7 +87,7 @@ describe('Extending tags', function() { '{{/tag}}' + '
' + '{{#tag}}' + - 'Data{{/tag}}Data' + + ' Data{{/tag}}Data ' + '
' + '
' + '
' + @@ -131,7 +131,7 @@ describe('Extending tags', function() { '
' + '
' + '
' + - 'Data{{#tag}}Data' + + ' Data{{#tag}}Data ' + '{{/tag}}' + '
' + '{{#tag}}' + @@ -160,7 +160,7 @@ describe('Extending tags', function() { '{{/tag}}' + '
' + '{{#tag}}' + - 'Data{{/tag}}Data' + + ' Data{{/tag}}Data ' + '
' + '
' + '
' + @@ -202,7 +202,7 @@ describe('Extending tags', function() { '
' + '
' + '
' + - 'Data{{#tag}}Data' + + ' Data{{#tag}}Data ' + '{{/tag}}' + '
' + '{{#tag}}' + @@ -227,7 +227,7 @@ describe('Extending tags', function() { '{{/tag}}' + '
' + '{{#tag}}' + - 'Data{{/tag}}Data' + + ' Data{{/tag}}Data ' + '
' + '
' + '
' + diff --git a/spec/fix-table-tags-spec.js b/spec/fix-table-tags-spec.js index 390cec3..963d17e 100644 --- a/spec/fix-table-tags-spec.js +++ b/spec/fix-table-tags-spec.js @@ -1,6 +1,6 @@ var tidy = require('../'); -describe('Extending tags', function() { +describe('Fixing table tags', function() { it('should fix table tags, when opening tag is out of table, and closing is inside table', function() { var input = ` {{^tag}} @@ -37,7 +37,7 @@ describe('Extending tags', function() { var result = tidy(input); expect(result).toBe( - '{{^tag}}' + + '{{^tag}} ' + '
Data
' + '
Data
' + '{{/tag}}' + @@ -141,7 +141,7 @@ describe('Extending tags', function() { '{{^tag}}' + '
Data
' + '
Data
' + - '{{/tag}}' + ' {{/tag}} ' ); }); @@ -191,7 +191,7 @@ describe('Extending tags', function() { 'Data' + '' + '' + - 'Data' + + ' Data ' + '{{^tag}}' + 'Data' + '{{/tag}}' + diff --git a/spec/improve-tags-spec.js b/spec/improve-tags-spec.js index 29d0792..3c1b67b 100644 --- a/spec/improve-tags-spec.js +++ b/spec/improve-tags-spec.js @@ -24,7 +24,7 @@ describe('Improving tags', function() { var result = tidy(input); expect(result).toBe( '
' + - '{{^outer}}' + + ' {{^outer}} ' + '{{#foo}}' + '{{^bar}}' + '{{#tag}}' + @@ -38,8 +38,8 @@ describe('Improving tags', function() { '{{/tag}}' + '{{/}}' + '{{/foo}}' + - '{{/}}' + - 'Data' + + ' {{/}} ' + + ' Data ' + '
' ); }); @@ -71,7 +71,7 @@ describe('Improving tags', function() { '' + '' + '{{/tag}}' + - 'Data' + + ' Data ' + '' ); }); @@ -140,7 +140,7 @@ describe('Improving tags', function() { '
' + '
' + '
' + - '{{^tag}}Data 1{{/tag}}{{#tag}}Data 2{{/tag}}' + + ' {{^tag}}Data 1{{/tag}}{{#tag}}Data 2{{/tag}} ' + '
' + '
' + '
' @@ -163,7 +163,7 @@ describe('Improving tags', function() { '
' + '
' + '
' + - '{{#tag}}Data 1{{/tag}}{{#foo}}Data 2{{/foo}}' + + ' {{#tag}}Data 1{{/tag}}{{#foo}}Data 2{{/foo}} ' + '
' + '
' + '
' diff --git a/spec/move-tags-spec.js b/spec/move-tags-spec.js index 28da776..17d4f20 100644 --- a/spec/move-tags-spec.js +++ b/spec/move-tags-spec.js @@ -23,7 +23,7 @@ describe('Moving tags', function() { '' + '' + '' + - '{{/tag}}' + ' {{/tag}} ' ); }); @@ -41,7 +41,7 @@ describe('Moving tags', function() { var result = tidy(input); expect(result).toBe( - '{{#tag}}' + + ' {{#tag}} ' + '
' + '
' + '
' + @@ -70,7 +70,7 @@ describe('Moving tags', function() { expect(result).toBe( '
' + '
' + - 'Data{{#tag}}' + + ' Data {{#tag}}' + '
' + '

Data

' + '
' + @@ -101,7 +101,7 @@ describe('Moving tags', function() { '
' + '

Data

' + '
' + - '{{/tag}}Data' + + '{{/tag}} Data ' + '
' + '
' ); @@ -168,7 +168,7 @@ describe('Moving tags', function() { '
' + '
' + '{{#tag}}' + - 'Data' + + ' Data ' + '{{/tag}}' + '
' + '
' + diff --git a/spec/replace-empty-node-spec.js b/spec/replace-empty-node-spec.js index c2fc5d5..47681cd 100644 --- a/spec/replace-empty-node-spec.js +++ b/spec/replace-empty-node-spec.js @@ -24,7 +24,7 @@ describe('Replacing empty dom nodes with containing tags', function() { `; var result = tidy(input); - expect(result).toBe('{{#tag}}Data{{/tag}}'); + expect(result).toBe(' {{#tag}} Data{{/tag}} '); }); it('should recursively replace nodes for closing tag', function() { @@ -39,7 +39,7 @@ describe('Replacing empty dom nodes with containing tags', function() {
`; var result = tidy(input); - expect(result).toBe('{{#tag}}Data{{/tag}}'); + expect(result).toBe('{{#tag}}Data {{/tag}} '); }); it('should recursively replace nodes for opening and closing tags', function() { @@ -62,7 +62,7 @@ describe('Replacing empty dom nodes with containing tags', function() { `; var result = tidy(input); - expect(result).toBe('{{#tag}}Data{{/tag}}'); + expect(result).toBe(' {{#tag}} Data {{/tag}} '); }); it('should recursively replace nodes for opening tag, and then remove tags as empty', function() { @@ -75,16 +75,16 @@ describe('Replacing empty dom nodes with containing tags', function() {

- {{/tag}} Data + {{/tag}}Data `; var result = tidy(input); - expect(result).toBe('Data Data'); + expect(result).toBe('Data Data '); }); it('should recursively replace nodes for closing tag, and then remove tags as empty', function() { var input = ` - Data {{#tag}} + Data{{#tag}}

@@ -95,7 +95,7 @@ describe('Replacing empty dom nodes with containing tags', function() { Data `; var result = tidy(input); - expect(result).toBe('Data Data'); + expect(result).toBe('Data Data '); }); it('should recursively replace nodes for opening and closing tags, and then remove tags as empty', function() { @@ -178,7 +178,7 @@ describe('Replacing empty dom nodes with containing tags', function() { `; var result = tidy(input); - expect(result).toBe('

Data
'); + expect(result).toBe('
Data
'); }); it('should replace tag nodes, if tags data is in separate node', function() { @@ -213,7 +213,7 @@ describe('Replacing empty dom nodes with containing tags', function() { `; var result = tidy(input); - expect(result).toBe('
{{#tag}}
'); + expect(result).toBe('
{{#tag}}
'); }); it('should not replace single closing tag node', function() { @@ -224,7 +224,7 @@ describe('Replacing empty dom nodes with containing tags', function() { `; var result = tidy(input); - expect(result).toBe('
{{/tag}}
'); + expect(result).toBe('
{{/tag}}
'); }); it('should not replace nodes for wrongly closing tag', function() { @@ -244,7 +244,7 @@ describe('Replacing empty dom nodes with containing tags', function() { `; var result = tidy(input); - expect(result).toBe('
{{#tag}}
{{#tag2}}
{{/tag}}
{{/tag2}}'); + expect(result).toBe('
{{#tag}}
{{#tag2}}
{{/tag}}
{{/tag2}} '); }); it('should not replace opening tag node with data', function() { @@ -258,7 +258,7 @@ describe('Replacing empty dom nodes with containing tags', function() { `; var result = tidy(input); - expect(result).toBe('{{#tag}}
Data
{{/tag}}'); + expect(result).toBe('{{#tag}}
Data
{{/tag}} '); }); it('should not replace closing tag node with data', function() { @@ -272,7 +272,7 @@ describe('Replacing empty dom nodes with containing tags', function() { `; var result = tidy(input); - expect(result).toBe('{{#tag}}
Data
{{/tag}}'); + expect(result).toBe(' {{#tag}}
Data
{{/tag}}'); }); it('should not replace tags node with outer following data, but should remove tags as empty', function() { @@ -283,7 +283,7 @@ describe('Replacing empty dom nodes with containing tags', function() { `; var result = tidy(input); - expect(result).toBe('
Data
'); + expect(result).toBe('
Data
'); }); it('should not replace tags node with outer preciding data, but should remove tags as empty', function() { @@ -294,7 +294,7 @@ describe('Replacing empty dom nodes with containing tags', function() { `; var result = tidy(input); - expect(result).toBe('
Data
'); + expect(result).toBe('
Data
'); }); it('should recursively replace both tags nodes and root nodes untill common ancestor, if closing tag has shorthand form', function() { @@ -347,6 +347,6 @@ describe('Replacing empty dom nodes with containing tags', function() { `; var result = tidy(input); - expect(result).toBe('{{#tag}}{{/tag}}'); + expect(result).toBe('{{#tag}} {{/tag}} '); }); });