Replies: 2 comments
-
Hi! Right, so these are your options: a) write as JSX, b) move things to a component, c) some sort of That seems like enough options to me. For c):
Everything is “processed”. Not entirely sure what you mean by that word. This approach c) is the only one that would be a good fit for not processing: if there are static conditions, then you can write a plugin to drop the non-matching branch. Anyway, yeah, https://github.com/orgs/mdx-js/discussions/2276 holds up |
Beta Was this translation helpful? Give feedback.
-
Is there a standard plugin that implements
Sorry I was imprecise, I meant something closer to "evaluated" I think. What I mean is that if I do something like this...
...then if
One can write code to dodge this but it's clunky, and "if thing is available, use thing, otherwise don't" is an extraordinarily common pattern. Anyway, I politely disagree that the first two solutions (break out components, or use JSX) are acceptable for all use cases -- there are places where one really wants to preserve the flow of content while adding a conditional, but dropping to JSX is jarring and obnoxious -- but that's obviously subjective. Plugins are the usual answer for "I think this is important but you don't" so that's why I'm exploring this route... |
Beta Was this translation helpful? Give feedback.
-
Root problem: I want to write MDX content which has occasional conditional branches, like (pseudocode)
Logically, I'd want something like this
...but that doesn't work of course, you get "## Foo is true! So you can rely on foo." without MDX interpretation.
Now, I do know various ways to do this with MDX/JSX, like (untested)
But now within the conditional block we no longer have the benefit of MDX which is super sad. A different alternative is to make several MDX components, like
foo_true.mdx
:foo_false.mdx
:page.mdx
:...but that leads to a proliferation of little files. Or, I could do this:
But that seems like I'm re-inventing an if-statement which must be wrong?? Also it's not great because both branches are processed regardless of the condition, which can lead to errors. And this seems like a very basic thing one might want to do in content, so I imagine I'm just missing some idiom here??
Other references
Beta Was this translation helpful? Give feedback.
All reactions