Support {{- and -}} for whitespace control.

With this PR it now matches the intended functionality; i.e., https://github.com/harttle/liquidjs/wiki/Whitespace-Control
This commit is contained in:
jaswrks
2017-08-03 06:06:35 -08:00
committed by GitHub
parent 6f82b914cb
commit 9f446ad024
+5 -5
View File
@@ -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')
}