Skip to content

Commit dc63a9f

Browse files
authored
Merge pull request #149 from alanhamlett/main
Also pass shouldRender the match result
2 parents 9f7a66a + e512a04 commit dc63a9f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/renderers/regex/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ export const createRegexRenderer = (
2222
| [
2323
regex: RegExp,
2424
style: StyleOrRender,
25-
shouldRender?: (matchedText: string) => boolean,
25+
shouldRender?: (matchedText: string, matchResult: RegExpExecArray) => boolean,
2626
]
2727
)[]
2828
): Renderer => {
2929
const allStyles = matchers.map(([, style]) => style);
3030

3131
return (value) => {
3232
const [indexSet, startToStyleMap, endToStyleMap] = matchers.reduce(
33-
(acc, [matcher, style, shouldRender]) => {
34-
execReg(matcher, value, shouldRender).forEach((m) => {
33+
(acc, [regex, style, shouldRender]) => {
34+
execReg(regex, value, shouldRender).forEach((m) => {
3535
const start = m.index;
3636
const end = m.index + m[0]!.length;
3737

src/renderers/regex/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
export const execReg = (
55
reg: RegExp,
66
text: string,
7-
shouldRender?: (matchedText: string) => boolean
7+
shouldRender?: (matchedText: string, matchResult: RegExpExecArray) => boolean
88
): RegExpExecArray[] => {
99
const results: RegExpExecArray[] = [];
1010
let match: RegExpExecArray | null = null;
1111
while ((match = reg.exec(text))) {
12-
if (shouldRender && !shouldRender(text)) {
12+
if (shouldRender && !shouldRender(text, match)) {
1313
continue;
1414
}
1515
results.push(match);

0 commit comments

Comments
 (0)