Skip to content

Commit 58b683d

Browse files
authored
Merge pull request #12 from hyperz111/handle-newline
2 parents 80c3727 + 7c1401c commit 58b683d

4 files changed

Lines changed: 10 additions & 2 deletions

File tree

index.browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function createColorize(colors = {}) {
22
let MARKS = Object.keys(colors).toString().replace(/,/g, '|')
33
let RE_BLOCK = new RegExp(
4-
`\\{((?:${MARKS})(?:\\.(?:${MARKS}))*?)\\s|(\\})|(.[^{}]*)`,
4+
`\\{((?:${MARKS})(?:\\.(?:${MARKS}))*?)\\s|(\\})|([\\s\\S][^{}]*)`,
55
'gi'
66
)
77

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function createColorize(colors = {}) {
22
let MARKS = Object.keys(colors).toString().replace(/,/g, '|')
33
let RE_BLOCK = new RegExp(
4-
`\\{((?:${MARKS})(?:\\.(?:${MARKS}))*?)\\s|(\\})|(.[^{}]*)`,
4+
`\\{((?:${MARKS})(?:\\.(?:${MARKS}))*?)\\s|(\\})|([\\s\\S][^{}]*)`,
55
'gi'
66
)
77

tests/browser.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ test('correctly parse escape in parameters', () => {
7878
assert.equal(colorize`{red ${string}}`, '\\')
7979
})
8080

81+
test('correctly parse newline escapes after template', () => {
82+
assert.equal(colorize`Hello {red there}\nafter`, 'Hello there\nafter')
83+
})
84+
8185
test('correctly parses unicode/hex escapes', () => {
8286
assert.equal(
8387
colorize`\u0078ylophones are fo\x78y! {magenta.inverse \u0078ylophones are fo\x78y!}`,

tests/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ test('correctly parse newline escapes', () => {
8080
assert.equal(colorize`Hello\nthere!`, 'Hello\nthere!')
8181
})
8282

83+
test('correctly parse newline escapes after template', () => {
84+
assert.equal(colorize`Hello {red there}\nafter`, 'Hello ' + pc.red('there') + '\nafter')
85+
})
86+
8387
test('correctly parse escape in parameters', () => {
8488
const string = '\\'
8589
assert.equal(colorize`{red ${string}}`, pc.red('\\'))

0 commit comments

Comments
 (0)