mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-17 05:10:40 -07:00
fix: handle windows newlines on newline_to_br and strip_newlines
This commit is contained in:
+1
-1
@@ -28,7 +28,7 @@ export function escape_once (str: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function newline_to_br (v: string) {
|
export function newline_to_br (v: string) {
|
||||||
return stringify(v).replace(/\n/g, '<br />\n')
|
return stringify(v).replace(/\r?\n/gm, '<br />\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function strip_html (v: string) {
|
export function strip_html (v: string) {
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ export function strip (v: string, chars?: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function strip_newlines (v: string) {
|
export function strip_newlines (v: string) {
|
||||||
return stringify(v).replace(/\n/g, '')
|
return stringify(v).replace(/\r?\n/gm, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function capitalize (str: string) {
|
export function capitalize (str: string) {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ describe('filters/html', function () {
|
|||||||
it('should support string_with_newlines', function () {
|
it('should support string_with_newlines', function () {
|
||||||
const src = '{% capture string_with_newlines %}\n' +
|
const src = '{% capture string_with_newlines %}\n' +
|
||||||
'Hello\n' +
|
'Hello\n' +
|
||||||
'there\n' +
|
'there\r\n' +
|
||||||
'{% endcapture %}' +
|
'{% endcapture %}' +
|
||||||
'{{ string_with_newlines | newline_to_br }}'
|
'{{ string_with_newlines | newline_to_br }}'
|
||||||
const dst = '<br />\n' +
|
const dst = '<br />\n' +
|
||||||
|
|||||||
@@ -137,6 +137,12 @@ describe('filters/string', function () {
|
|||||||
'{{ string_with_newlines | strip_newlines }}',
|
'{{ string_with_newlines | strip_newlines }}',
|
||||||
'Hellothere')
|
'Hellothere')
|
||||||
})
|
})
|
||||||
|
it('should support strip_newlines on Windows newlines ', function () {
|
||||||
|
return test('{% capture string_with_newlines %}\n' +
|
||||||
|
'Hello\r\nthere\n{% endcapture %}' +
|
||||||
|
'{{ string_with_newlines | strip_newlines }}',
|
||||||
|
'Hellothere')
|
||||||
|
})
|
||||||
describe('truncate', function () {
|
describe('truncate', function () {
|
||||||
it('should truncate when string too long', function () {
|
it('should truncate when string too long', function () {
|
||||||
return test('{{ "Ground control to Major Tom." | truncate: 20 }}',
|
return test('{{ "Ground control to Major Tom." | truncate: 20 }}',
|
||||||
|
|||||||
Reference in New Issue
Block a user