-
-
Notifications
You must be signed in to change notification settings - Fork 895
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
Code is wrapped in an exrea <pre> even with a custom component #820
Comments
Welcome @angrybacon! 👋
It's a bit hard to help because it's unclear what your end goal is. If you're looking for something else, please explain. |
This comment has been minimized.
This comment has been minimized.
I am already using this and their inline styles are applied to the <Markdown
...
disallowedElements={['pre']}
unwrapDisallowed
/> |
Does that mean that I should instead customize the |
Okay, you aren't in the example you shared, but I think I follow.
If you only want one level, one way or another you will need to unwrap.
You could do that too. |
I only meant to provide the most minimal context but after a good night's sleep I now see where my confusion comes from: within Markdown I can have inline code markup and code blocks. The former is content wrapped in Since I'm customizing the |
While I do follow, the way The issue here is that you aren't able to customize both inline code and code blocks separately, since |
You are welcome to use plugins to customize the output to your liking. https://unifiedjs.com/learn/ |
Because that wouldn't be semantically correct. The FWIW here is how I differentiate the 2 in my code: import { type Components } from 'react-markdown';
const Code: Components['code'] = ({ children, className = '', node }) => {
if (!node?.position || !children) {
console.error('Could not parse code node', node);
return <>{children}</>;
}
if (node.position.start.line === node.position.end.line) {
return <CodeInline>{children}</CodeInline>;
}
// NOTE Languages are passed down through the class name with `react-markdown`
const [, language] = className.split('-');
return <CodeBlock language={language || 'text'}>{children}</CodeBlock>;
}; Edit: I notice while posting this that GitHub doesn't use |
Initial checklist
Affected packages and versions
[email protected]
Link to runnable example
https://codesandbox.io/p/sandbox/react-markdown-820-m63fxn
Steps to reproduce
Expected behavior
A custom component for code blocks should replace the default
pre
wrapper.Actual behavior
My code block is wrapped in 2
pre
elements. This is relevant for cases like https://github.com/remarkjs/react-markdown?tab=readme-ov-file#use-custom-components-syntax-highlight where the horizontal scroll fromreact-syntax-highlighter
is broken as a result.Runtime
No response
Package manager
No response
OS
No response
Build and bundle tools
No response
The text was updated successfully, but these errors were encountered: