Skip to content

Commit a6d1fd6

Browse files
authored
fix: number regex (#41)
1 parent 0b6765b commit a6d1fd6

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

index.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ describe('unicode', () => {
7070
.toBe("[string]'34'[clear]")
7171
})
7272

73+
it('alphanumeric', () => {
74+
expect(hlUni('(f1)'))
75+
.toBe('[bracket]([clear]f1[bracket])[clear]')
76+
})
77+
7378
it('functions', () => {
7479
expect(hlUni('COUNT(`id`)'))
7580
.toBe('[function]COUNT[clear][bracket]([clear][string]`id`[clear][bracket])[clear]')
@@ -132,6 +137,11 @@ describe('html', () => {
132137
.toBe("<span class=\"sql-hl-string\">'34'</span>")
133138
})
134139

140+
it('alphanumeric', () => {
141+
expect(hlHtml('(f1)'))
142+
.toBe('<span class="sql-hl-bracket">(</span>f1<span class="sql-hl-bracket">)</span>')
143+
})
144+
135145
it('functions', () => {
136146
expect(hlHtml('COUNT(`id`)'))
137147
.toBe('<span class="sql-hl-function">COUNT</span><span class="sql-hl-bracket">(</span><span class="sql-hl-string">`id`</span><span class="sql-hl-bracket">)</span>')

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const highlighters = [
3535
},
3636
{
3737
name: 'number',
38-
regex: /(\d+(?:\.\d+)?)/g
38+
regex: /((?<![a-zA-z])\d+(?:\.\d+)?)/g
3939
},
4040
{
4141
name: 'string',

test/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ console.log(highlight("SELECT COUNT(id), `id`, `username` FROM `users` WHERE `em
1414
console.log(highlight('SELECT id FROM users'))
1515

1616
console.log(highlight('WITH t1 AS (SELECT data_point FROM tablename) SELECT data_point FROM t1;'))
17+
console.log(highlight('SELECT f1, f20b, f3a, -1, 1, "1", 1.00 FROM t1;'))
1718

1819
console.log(highlight('SELECT id FROM listings WHERE status = \'not available\''))
1920
console.log(highlight('SELECT id FROM listings WHERE status = "not available"'))

0 commit comments

Comments
 (0)