Merge branch 'master' into feature/176-CamelCaseTokens

This commit is contained in:
Simon Cambier
2023-03-02 19:53:05 +01:00
6 changed files with 22 additions and 10 deletions

View File

@@ -27,7 +27,12 @@ export function highlighter(str: string): string {
}
export function highlighterGroups(...args: any[]) {
if (args[1] && args[2])
if (
args[1] !== null &&
args[1] !== undefined &&
args[2] !== null &&
args[2] !== undefined
)
return `${args[1]}<span class="${highlightClass}">${args[2]}</span>`
return '&lt;no content&gt;'
}
@@ -63,8 +68,9 @@ export function wait(ms: number): Promise<void> {
}
// https://stackoverflow.com/a/3561711
// but we enclose special chars in brackets to avoid them being interpreted as regex
export function escapeRegex(str: string): string {
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, '[$&]')
}
/**
@@ -88,7 +94,7 @@ export function stringsToRegex(strings: string[]): RegExp {
// Default word split is not applied if the user uses the cm-chs-patch plugin
const joined =
'(' +
(getChsSegmenter() ? '' : SPACE_OR_PUNCTUATION.source) +
(getChsSegmenter() ? '' : `^|${SPACE_OR_PUNCTUATION.source}`) +
')' +
'(' +
strings.map(s => escapeRegex(s)).join('|') +