Skip to content

Commit 750630d

Browse files
committed
added TextUtils.replaceRuby()
1 parent 1363f88 commit 750630d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/utils/text_utils.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
class TextUtils {
2+
3+
static readonly rubyRegex = /{RUBY_B#(.+?)}(.+?){RUBY_E#}/g;
4+
25
static removeRuby(text: string): string {
3-
return text.replace(/{RUBY_B#.+?}(.+?){RUBY_E#}/g, "$1");
6+
// same as this.replaceRuby(text, (match, base, ruby) => base);
7+
return text.replace(this.rubyRegex, "$2");
8+
}
9+
static replaceRuby(text: string, replacer: (match: string, base: string, ruby: string) => string): string {
10+
return text.replace(this.rubyRegex, (match, base, ruby) => replacer(match, base, ruby));
411
}
512
}
613

0 commit comments

Comments
 (0)