-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add function to allow users to register their own parser hooks #46
Conversation
@santhoshtr any thoughts? |
This looks like a good idea to me. Your PR make sense too. This is more or less in alignment with the extend option available in jquery.i18n(https://github.com/wikimedia/jquery.i18n#extending-the-parser). Could you please add some test too? Also, documentation(README.md) |
A simple contrived example would be: - banana.registerParserPlugin('foobar', nodes => nodes[0] === 'foo' ? nodes[1]: nodes[2]) Which makes - banana.i18n('{{foobar:foo|first|second') --> 'first' - banana.i18n('{{foobar:bar|first|second') --> 'second' This can be used practically for a lot of purposes, particularly for operations that require some data to be available which can be fetched from the client script. For example on mediawiki sites, a client script could add a hook for formatting dates using the month names fetched from MediaWiki API. Let me know what you think about this. Another less explicit way of allowing these hooks would be to export the BananaEmitter class, so that clients can directly modify its prototype.
Done: updated documentation (adapted from jquery-i18n documentation), added tests and typescript type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general looks good. I left some minor comments. Also, the master version just migrated to github workflows. So please make sure CI is passing. Thanks for working on this
A simple contrived example would be:
Which makes
This can be used practically for a lot of purposes, particularly for operations that require some data to be available which can be fetched from the client script. For example on mediawiki sites, a client script could add a hook for formatting dates using the month names fetched from MediaWiki API.
Let me know what you think about this. Another less explicit way of allowing these hooks would be to export the BananaEmitter class, so that clients can directly modify its prototype.