From 9f446ad024bcdb15262bd8f2c1fccaad70420603 Mon Sep 17 00:00:00 2001 From: jaswrks Date: Thu, 3 Aug 2017 06:06:35 -0800 Subject: [PATCH] Support `{{-` and `-}}` for whitespace control. With this PR it now matches the intended functionality; i.e., https://github.com/harttle/liquidjs/wiki/Whitespace-Control --- src/tokenizer.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tokenizer.js b/src/tokenizer.js index e443ee0a9..7142f8317 100644 --- a/src/tokenizer.js +++ b/src/tokenizer.js @@ -9,7 +9,7 @@ function parse (html, filepath, options) { html = whiteSpaceCtrl(html, options) var tokens = [] - var syntax = /({%-?([\s\S]*?)-?%})|({{([\s\S]*?)}})/g + var syntax = /({%-?([\s\S]*?)-?%})|({{-?([\s\S]*?)-?}})/g var result, htmlFragment, token var lastMatchEnd = 0 var lastMatchBegin = -1 @@ -82,13 +82,13 @@ function parse (html, filepath, options) { function whiteSpaceCtrl (html, options) { options = options || {} if (options.trim_left) { - html = html.replace(/{%-?/g, '{%-') + html = html.replace(/({[{%])-?/g, '$1-') } if (options.trim_right) { - html = html.replace(/-?%}/g, '-%}') + html = html.replace(/-?([%}]})/g, '-$1') } - var rLeft = options.greedy ? /\s+({%-)/g : /[\t\r ]*({%-)/g - var rRight = options.greedy ? /(-%})\s+/g : /(-%})[\t\r ]*\n?/g + var rLeft = options.greedy ? /\s+({[{%]-)/g : /[\t\r ]*({[{%]-)/g + var rRight = options.greedy ? /(-[%}]})\s+/g : /(-[%}]})[\t\r ]*\n?/g return html.replace(rLeft, '$1').replace(rRight, '$1') }