mirror of
https://github.com/harttle/liquidjs.git
synced 2026-10-03 09:05:14 -07:00
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:
+5
-5
@@ -9,7 +9,7 @@ function parse (html, filepath, options) {
|
|||||||
html = whiteSpaceCtrl(html, options)
|
html = whiteSpaceCtrl(html, options)
|
||||||
|
|
||||||
var tokens = []
|
var tokens = []
|
||||||
var syntax = /({%-?([\s\S]*?)-?%})|({{([\s\S]*?)}})/g
|
var syntax = /({%-?([\s\S]*?)-?%})|({{-?([\s\S]*?)-?}})/g
|
||||||
var result, htmlFragment, token
|
var result, htmlFragment, token
|
||||||
var lastMatchEnd = 0
|
var lastMatchEnd = 0
|
||||||
var lastMatchBegin = -1
|
var lastMatchBegin = -1
|
||||||
@@ -82,13 +82,13 @@ function parse (html, filepath, options) {
|
|||||||
function whiteSpaceCtrl (html, options) {
|
function whiteSpaceCtrl (html, options) {
|
||||||
options = options || {}
|
options = options || {}
|
||||||
if (options.trim_left) {
|
if (options.trim_left) {
|
||||||
html = html.replace(/{%-?/g, '{%-')
|
html = html.replace(/({[{%])-?/g, '$1-')
|
||||||
}
|
}
|
||||||
if (options.trim_right) {
|
if (options.trim_right) {
|
||||||
html = html.replace(/-?%}/g, '-%}')
|
html = html.replace(/-?([%}]})/g, '-$1')
|
||||||
}
|
}
|
||||||
var rLeft = options.greedy ? /\s+({%-)/g : /[\t\r ]*({%-)/g
|
var rLeft = options.greedy ? /\s+({[{%]-)/g : /[\t\r ]*({[{%]-)/g
|
||||||
var rRight = options.greedy ? /(-%})\s+/g : /(-%})[\t\r ]*\n?/g
|
var rRight = options.greedy ? /(-[%}]})\s+/g : /(-[%}]})[\t\r ]*\n?/g
|
||||||
return html.replace(rLeft, '$1').replace(rRight, '$1')
|
return html.replace(rLeft, '$1').replace(rRight, '$1')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user