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
DEV: addPrettyTextAdditionalOptions plugin API #15727
DEV: addPrettyTextAdditionalOptions plugin API #15727
Conversation
When writing markdown rules and features, additional options not part of the main options payload may be needed for the rule. Rules cannot access things like the Site or current User objects which can have serialized data which may be useful when rendering markdown rules. ``` const site = api.container.lookup("site:main"); api.addPrettyTextAdditionalOptions({ someSiteOption: site.some_option }) ``` These options are passed down to several of the markdown helper functions created by discourse-markdown-it extensions, such as registerPlugin and registerOptions, and can be accessed like so: ``` opts.discourse.additionalOptions.someSiteOption ``` These options are held in a separate additionalOptions namespace because they are _not_ meant to override the core pretty-text options. ----- The main motivation for adding this is the chat plugin, which stores `chat_pretty_text_features` and `chat_pretty_text_markdown_rules` on the Site object via additions to the serializer, and the Site object is not accessible to import via markdown rules (either through Site.current() or through container.lookup)
addPrettyTextOptions("pluginA", { someOption: "test" }); | ||
addPrettyTextOptions("pluginB", { doorNumberTwo: "other thing" }); | ||
const prettyText = createPrettyText(); | ||
assert.equal( |
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.
assert.equal( | |
assert.strictEqual( |
prettyText.opts.discourse.additionalOptions.pluginA.someOption, | ||
"test" | ||
); | ||
assert.equal( |
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.
assert.equal( | |
assert.strictEqual( |
### Added | ||
- Adds `addPrettyTextAdditionalOptions`. When writing markdown rules and features, | ||
additional options not part of the main options payload may be needed for the rule. | ||
Rules cannot access things like the Site or current User objects which can have |
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.
I think current User is part of the options so perhaps we should omit the current User objects?
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.
Ah yes I see, we can leave that out.
O nevermind, I tried this and everything exploded on the server side. It looks like this plugin API we're adding is on the client side, how will we handle the server side which does the cooking too? |
@tgxworld no, see:
I wouldn't need this if I could just do that :) |
Ah damn this is a problem, I didn't realise that the text.js part is client side only, will have a think 🤔 |
Not the right solution, will open another PR |
When writing markdown rules and features, additional options not part of
the main options payload may be needed for the rule. Rules cannot access
things like the Site or current User objects which can have serialized data
which may be useful when rendering markdown rules.
These options are passed down to several of the markdown helper functions
created by discourse-markdown-it extensions, such as registerPlugin and registerOptions,
and can be accessed like so:
These options are held in a separate additionalOptions namespace because
they are not meant to override the core pretty-text options.
The main motivation for adding this is the chat plugin, which stores
chat_pretty_text_features
andchat_pretty_text_markdown_rules
onthe Site object via additions to the serializer, and the Site object is
not accessible to import via markdown rules (either through
Site.current() or through container.lookup)