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
Ability to specify a custom text renderer/component removed in v6.0.0 #618
Comments
Hi, this has been discussed and answered in this discussion: remarkjs/remark#700. Let us know if anything is still unclear. Closing as this is a duplicate question: #609 @ChristianMurphy @wooorm perhaps we can update the docs as this seems to be a recurring issue? |
I just found that issue. Apologies for the duplicate issue. Can the CHANGELOG for 6.0.0 perhaps be updated to indicate this though? That would make things a lot easier, since it seems several people are having the same challenge in upgrading. |
Also, discussion 700 proposes that the |
No, not every |
But why don’t you pass |
Okay, then is there a way to re-create the old functionality of providing a custom renderer for text nodes? The solution in remarkjs/remark#700 doesn't seem to apply in my case, since the problem being solved there was a syntax problem, so using a plugin to modify the syntax tree doesn't seem appropriate here. I'm interested in modifying the rendering of the existing syntax tree, not modifying the tree. Though if I need to modify the syntax tree to get the old behavior, I can do that as a hack. I just looked through all the |
I am essentially passing I did some testing, and, for instance, in versions prior to 6.0, the |
Why not use Material UI heading components that will also include roboto? 🤷♂️ |
I feel like you're missing the point. We can go through each of the changes—which I'm already doing—and fix each one. The point though is that before version 6.0 there was the ability to override the rendering of every text node with a single override. In 6.0, this functionality was removed and there is no easy way to replace the functionality. Yes, there are solutions to each of the problems. I am currently going through and fixing them. But it requires knowing the implementation details of For instance, overriding For now, though, just having a list of which elements have their text node children wrapped in a It would be helpful in the future to add the old functionality back into this library. |
It requires knowing how markdown works. CommonMark prescribes how markdown maps to HTML. How CommonMark maps markdown to HTML is highly unlikely to ever change.
Some
Not going to happen. This change happened exactly to move away from custom APIs to what is standardized. |
in the changelog https://github.com/remarkjs/react-markdown/blob/main/changelog.md#change-renderers-to-components under "Show conversion table" this is noted.
How so?
This isn't
I agree that more documentation and discussion around how to migrate away from |
It may be the If Note that I am not asking to go back to the entire old API. I am asking for a single piece of the old functionality, that of being able to override the rendering for text nodes, be restored, or an alternate solution provided. HTML has the concept of text nodes just like markdown, so I don't see what the issue is. All that is required is the ability to override the rendered/component for text nodes, in addition to the other HTML node types that can be overridden by |
Again and the AST https://astexplorer.net/#/gist/38518decbafcee98ee1e8256fa383430/89ee2bdd76bb531f169aad7df6bf8382dd7f7d61 matches the CommonMark reference https://spec.commonmark.org/dingus/?text=*%20list%0A*%20item |
Okay, I see the difference now. I was reading the spec for converting Markdown -> HTML, and then was looking at the AST and interpreting it as the render tree, since it used the same render types as pre-6.0.0. But I see that the AST is then further transformed before being mapped into HTML. Can you explain why a custom renderer cannot be provided for the (And I recognize the "text" node may be an AST text node or an HTML text node—unless you're saying there is some intermediate form that doesn't have text nodes, but has all the other nodes). |
While technically |
Thanks. I read through the motivation before I upgraded to start doing my testing. It makes sense to me. Where I disagree is that adding a solution to transform While That all said, I'm not tied to the specific solution of passing a But you said there were better solutions. If there are others, please share. So far I've heard nothing but that I should learn exactly how the AST is parsed and rendered in CommonMark / While doable, that's clearly a hack, when this used to be able to be done with a single override where the intent of the override was clear. It also goes against the spirit of 6.0.0 to make usage of this library simpler. |
Without a suitable alternative solution, I created my own. I added a I submitted it via PR #619, in case it will be useful for others. I'm happy to make changes if you have suggestions. Or, if this solution doesn't work for you, feel free to close the PR. I switched my codebase to using this fork, which solved my remaining upgrade problems to v6.0.0. |
An alternative would be to create a rehype plugin https://unifiedjs.com/learn/guide/create-a-plugin I'm open to a A consideration I've been thinking through, and it's not specific just to |
My mental model for those is that the HAST has three types of transformation:
The transformations for attributes and content get applied first, then those get passed into the |
A concrete example of what a rehype/hast plugin that solves this problem looks like |
For anyone who is looking for similar use case, like accessing each |
Subject of the issue
Previous versions of
react-markdown
had the ability to provide a custom text renderer (for example, to filter the text or wrap all text in a Material UITypography
element). This functionality appears to have been removed in version 6.0.0, with no mention in the changelog or release notes.The only way I figured it out was noting there was no mapping for the old
text
render in this conversion chart and then searching through the code to find that references to the old text renderer were removed.At a minimum, it would be convenient if the removal of this functionality was documented somewhere (this issue may provide that). But it would also be great to have this functionality back.
Old behavior
In 5.x and prior, a custom renderer could be provided via the
text
renderer that would apply to all text nodes:Expected behavior
A mapping would exist for the
components
to provide the same functionality that was available in previous versions, where all text nodes were rendered with the custom renderer:Actual behavior
There is no way to override the rendering of text nodes anymore.
The text was updated successfully, but these errors were encountered: