-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Can't nest custom editor components #7180
Comments
@martinjagodic Is the stale label indicating that you plan to close this issue due to no activity? I'm still very much interested in this as I really need to have full support of MDX files to switch to decap-cms. |
@tobiasBora Yes, there seemed to be no interest from anyone else in this topic. This could be because the issue description has some inconsistencies. You talk about nesting custom widgets, but in the code, you specify a custom editor component, which is different. It appears that you want nested ECs, so please update the issue to make that clear. I edited the labels to keep this issue around. Would you be willing to contribute a pull request to improve this? |
I see, I was not really familiar with the naming I think, hence the confusion. I tried to fix the naming issue above, hopefully it is clearer.
I'm surprised nobody needs nested components, that seems to be a fairly basic feature, for instance when one wants to define a carousel of pictures, one need to embed inside a "carousel" component multiple pictures components, possibly with title attributes etc… How are people solving these issues?
I might try in the future yes (but right now I don't have much time), but since manually parsing HTML/MDX is not so easy, I think the ultimate solution would be to directly provide an additionally integration for HTML/MDX, for instance via https://github.com/syntax-tree/mdast-util-mdx (while letting the possibility to the user to provide support for additional languages not so easy to parse), but this might require a bit more thoughts on how to go from MDX syntax tree to EC and EC to MDX. |
We use nested ECs regularly, but it depends a bit on your SSG of choice. If you combine it with Hugo's shortcodes, it works very well. This is not well documented because it depends on the use case and the SSG, so you have to find regexes that work for you. Support for MDX is tracked in #7158. |
Ok, I meant nested EC with the same EC used inside the parent EC (so my example with photos does not apply, but the one with hidden content does). This simply cannot be parsed with regexp, similar to how regexp are unable to parse matched parenthesis, so I don't think it depends much on the used SSG.
Thanks, good to know! They mention custom formatters that should indeed be usable in this context (at the cost of rewritting a full formatter), which is a first step indeed, thanks. I'll see how far I can go starting from there. |
Describe the bug
If I define a custom editor component, I can only specify a regexp as a pattern, like
pattern: /^<details>$\s*?<summary>(.*?)<\/summary>\n\n(.*?)\n^<\/details>$/ms,
. But this will parse nested components poorly, for instance:Is not parsed correctly since the regexp will match the first
<detail>
with the first</detail>
, like in:Unfortunately, I don't think any regexp expression can work here, as an automata "cannot count"… so we should allow the user to use a true XML/MDX parser. So we could maybe provide two options, one with a very generic function that is just given the rest of the file to parse, and one easier function that is made for xml files that are the most common kind of data anyway.
To Reproduce
Add a custom editor component, I just used the one from the documentation:
Expected behavior
This should just parse correctly without any error
Screenshots
Applicable Versions:
CMS configuration
and the following configuration
Additional context
The text was updated successfully, but these errors were encountered: