@@ -7,7 +7,7 @@ import type { PatternSet, SuperscriptConfig } from './types'
7
7
/**
8
8
* Create regex patterns based on configuration
9
9
*/
10
- export function createPatterns ( config : SuperscriptConfig ) : PatternSet {
10
+ export function createPatterns ( _config : SuperscriptConfig ) : PatternSet {
11
11
return {
12
12
// Matches ™, (TM), or standalone TM
13
13
trademark : / ™ | \( T M \) | \b T M \b / g,
@@ -26,7 +26,7 @@ export function createPatterns(config: SuperscriptConfig): PatternSet {
26
26
27
27
// Matches math superscript notation: x^2, x^n, x^{expr}
28
28
// Pattern: /(?<=^|[\s=+\-*/().,\d]|[a-z])([a-zA-Z])\^(\d+|[a-zA-Z]|\{[^}]+\ })/g
29
- //
29
+ //
30
30
// Breakdown:
31
31
// - (?<=...) - Positive lookbehind to ensure proper context
32
32
// - ^|[\s=+\-*/().,\d] - After start of string, whitespace, operators, or digits
@@ -47,7 +47,7 @@ export function createPatterns(config: SuperscriptConfig): PatternSet {
47
47
// Examples that DON'T MATCH:
48
48
// - "file^name" - 'e' is after 'l' but we still match (limitation)
49
49
// - "MAX^2" - 'X' is after uppercase 'A' (blocked by lookbehind)
50
- mathSuper : / (?< = ^ | [ \s = + \- * / ( ) . , \d ] | [ a - z ] ) ( [ a - z A - Z ] ) \^ ( \d + | [ a - z A - Z ] | \{ [ ^ } ] + \} ) / g,
50
+ mathSuper : / (?< = ^ | [ \s = + \- * / ( ) . , \d a - z ] ) ( [ a - z A - Z ] ) \^ ( \d + | [ a - z A - Z ] | \{ [ ^ } ] + \} ) / g,
51
51
52
52
// Matches math subscript notation: x_1, x_n, x_{expr}
53
53
// Pattern: /(?<=^|[\s=+\-*/().,])([a-zA-Z])_(\d+|[a-zA-Z]|\{[^}]+\ })/g
@@ -70,7 +70,7 @@ export function createPatterns(config: SuperscriptConfig): PatternSet {
70
70
// - "file_name" - 'e' is after letter 'l' (blocked by lookbehind)
71
71
// - "some_var" - 'e' is after letter 'm' (blocked by lookbehind)
72
72
// - "log_2" - 'g' is after letter 'o' (blocked by lookbehind)
73
- mathSub : / (?< = ^ | [ \s = + \- * / ( ) . , ] ) ( [ a - z A - Z ] ) _ ( \d + | [ a - z A - Z ] | \{ [ ^ } ] + \} ) / g ,
73
+ mathSub : / (?< = ^ | [ \s = + \- * / ( ) . , ] ) ( [ a - z ] ) _ ( \d + | [ a - z ] | \{ [ ^ } ] + \} ) / gi ,
74
74
}
75
75
}
76
76
@@ -97,12 +97,12 @@ export function createCombinedPattern(patterns: PatternSet, config: SuperscriptC
97
97
export const PatternMatchers = {
98
98
isTrademark : ( text : string ) : boolean => / ^ (?: ™ | \( T M \) | T M ) $ / . test ( text ) ,
99
99
isRegistered : ( text : string ) : boolean => / ^ (?: ® | \( R \) ) $ / . test ( text ) ,
100
- isCopyright : ( text : string ) : boolean => / (?: © | \( C \) ) / . test ( text ) ,
100
+ isCopyright : ( text : string ) : boolean => / © | \( C \) / . test ( text ) ,
101
101
isOrdinal : ( text : string ) : boolean => / ^ \d + (?: s t | n d | r d | t h ) $ / . test ( text ) ,
102
102
isChemicalElement : ( text : string ) : boolean => / ^ [ A - Z ] [ a - z ] ? \d + $ / . test ( text ) ,
103
103
isChemicalParentheses : ( text : string ) : boolean => / ^ \) \d + $ / . test ( text ) ,
104
- isMathSuperscript : ( text : string ) : boolean => / ^ [ a - z A - Z ] \^ / . test ( text ) ,
105
- isMathSubscript : ( text : string ) : boolean => / ^ [ a - z A - Z ] _ / . test ( text ) ,
104
+ isMathSuperscript : ( text : string ) : boolean => / ^ [ a - z ] \^ / i . test ( text ) ,
105
+ isMathSubscript : ( text : string ) : boolean => / ^ [ a - z ] _ / i . test ( text ) ,
106
106
}
107
107
108
108
/**
@@ -128,24 +128,24 @@ export const PatternExtractors = {
128
128
return text . substring ( 1 ) . replace ( / [ { } ] / g, '' )
129
129
} ,
130
130
131
- extractMathWithVariable : ( text : string ) : { variable : string ; script : string } | null => {
131
+ extractMathWithVariable : ( text : string ) : { variable : string , script : string } | null => {
132
132
// Handle x^2, x_n, x^{10}, x_{n+1} etc.
133
- const superMatch = text . match ( / ^ ( [ a - z A - Z ] ) \^ ( .+ ) $ / )
133
+ const superMatch = text . match ( / ^ ( [ a - z ] ) \^ ( .+ ) $ / i )
134
134
if ( superMatch ) {
135
135
return {
136
136
variable : superMatch [ 1 ] ,
137
137
script : superMatch [ 2 ] . replace ( / [ { } ] / g, '' ) ,
138
138
}
139
139
}
140
-
141
- const subMatch = text . match ( / ^ ( [ a - z A - Z ] ) _ ( .+ ) $ / )
140
+
141
+ const subMatch = text . match ( / ^ ( [ a - z ] ) _ ( .+ ) $ / i )
142
142
if ( subMatch ) {
143
143
return {
144
144
variable : subMatch [ 1 ] ,
145
145
script : subMatch [ 2 ] . replace ( / [ { } ] / g, '' ) ,
146
146
}
147
147
}
148
-
148
+
149
149
return null
150
150
} ,
151
151
}
0 commit comments