Skip to content
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

Option to provide a custom component as wrapper / pass className to wrapper? #596

Open
WillNeve opened this issue Jul 27, 2024 · 1 comment

Comments

@WillNeve
Copy link

Option to provide a custom component as wrapper / pass className to wrapper?

I apologise in advance if this is covered in the docs but I could not find it

  • Is there an ability to provide a custom component as the wrapper instead of a base element type like options={{ wrapper: 'div' }}?
  • ... Or to provide a className for the existing wrapper element?
@YogiDhingani
Copy link

@WillNeve

  • Yes, you can provide a custom component as a wrapper.
  • Since you are defining the custom component, you have complete control over the wrapper. You can add all the attributes you want, such as className, id, etc.

Example:

import Markdown from 'markdown-to-jsx';

type CustomElementProps = {
    children: React.ReactNode;
};

const CustomElement = ({ children }: CustomElementProps) => {
    return <section className="section-class"> {children} </section>;
};

const answer = `# A first-level heading 
## A second-level heading 
### A third-level heading`;

function App() {
    return (
        <Markdown
            options={{
                wrapper: CustomElement,
            }}
        >
            {answer}
        </Markdown>
    );
}

export default App;

Output:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants