-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Serialize back a textDirective to its original form? #12
Comments
There is something else: For example, you could have a Here we’re talking about docusaurus as the “end target” of the components in markdown. Primarly, I think you should warn about components you don’t handle. You’re raising this issue here, With rendering, you might mean by MDX? Or you are using something else as the final result ( Finally, everything with directives happens with plugins: you can handle You can do that. Here’s some pseudo code I wrote off the top of my head to show a way to go about it: export default function somePlainTextDirectives(options) {
const names = (options || {}).names || []
return function (tree) {
visit(tree, function (node, index parent) {
if (parent && typeof index === 'number' && node.type === 'textDirective' && names.includes(node.name)) {
const xxx = toMarkdown(node, {
extensions: [directiveToMarkdown()]
})
parent.children[index] = {type: 'text', value: xxx}
}
})
}
} |
Hi! Thanks for reaching out! Because we treat issues as our backlog, we close issues that are questions since they don’t represent a task to be completed. See our support docs for how and where to ask questions. Thanks, |
Thanks @wooorm and sorry for the late reply.
Yes that seems like a reasonable solution.
Agree on that, it's just that I didn't really know where else I could open this issue 😅
Yes that's the idea. I think most users will only be affected by this behavior for text directives because it's relatively common to use However I was mostly wondering:
|
So we implemented the warning plugin here: facebook/docusaurus#9394 We only serialize back the "simple text directives" like |
Initial checklist
Problem
Users sometimes need to use
:textDirective
in their content, without the intent of creating a textDirective.Some examples found in the React-Native website:
:Invent
,:attr
and:boolean
being now parsed as textDirective, this leads to these content requiring to be refactored so that they keep being displayed as before turning directives on.Otherwise this is what happens:
Of course we can escape
\:
or use the HTML code:
, but we can only do so if we notice the visual regression in the first place, that is quite easy to miss for large content sites ;) I only caught these little issues because I use an automated visual regression workflow.Solution
I don't really have a solution, and not even sure it's the correct repo to discuss this, but:
This:
Is rendered as:
If we could make it render as
A :test
instead, I think it would be much less likely to produce the unintended side effects described above.Alternatives
This can probably be fixed in userland by writing a remark plugin that transforms unhandled textDirective nodes:
to
I wanted to open this issue to discuss if it's a good idea, and if it makes sense to generalize this so that others can benefit from this behavior change?
The text was updated successfully, but these errors were encountered: