Additional tagging with regexp- mutate model.two or post-process hook? #1086
-
I need to do some additional tagging and was wondering if there are pros/cons to mutating model.two by injecting my new regex into regexNormal versus adding a post-process compute hook that performs the additional tagging through Code examples: // Mutate regexNormal
const plugin = {
mutate: world => {
const additionalTags = [
[/^[\u00BC-\u00BE\u2150-\u215E]$/, 'Fraction', '¼'],
];
world.model.two.regexNormal =
world.model.two.regexNormal.concat(additionalTags);
},
}
// Post-process hook
const plugin = {
compute: {
postProcess: doc => {
doc.match('/[\u00BC-\u00BE\u2150-\u215E]/').tag('Fraction'); // support unicode fractions
},
},
hooks: ['postProcess'],
}; |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
this is very well done!! |
Beta Was this translation helpful? Give feedback.
-
also - please make a pr! these unicode fractions are really fun stuff |
Beta Was this translation helpful? Give feedback.
this is very well done!!
Either should work - my only fear is that our match parser won't parse the second one properly - haha.
Bravo for getting so far mutating things, can I add this do the docs?
cheers