Replies: 3 comments 1 reply
-
Duplicate of https://github.com/orgs/remarkjs/discussions/1183 |
Beta Was this translation helpful? Give feedback.
-
To resolve the issue of newlines causing errors in react-pdf, you can wrap the text content of each paragraph within Here's an example of how you can modify your code: import React from 'react';
import ReactMarkdown from 'react-markdown';
import { Text } from 'react-pdf';
const MarkdownToPdf = ({ markdownContent }) => {
const renderers = {
paragraph: ({ children }) => <Text>{children}</Text>,
// Add more custom renderers for other Markdown elements if needed
};
return (
<>
<ReactMarkdown components={renderers} children={markdownContent} />
</>
);
};
export default MarkdownToPdf; In this example, we define a custom renderer for the You can add more custom renderers for other Markdown elements as needed, following the same pattern. Note: Make sure you have the correct import for the I hope this resolves the issue! Let me know if you need further assistance. |
Beta Was this translation helpful? Give feedback.
-
I'm having the same issue. I got components renderers to work with paragraph like @wb-ts said. const renderers = {
p: ({ children }) => <Text>{children}</Text>,
// Add more custom renderers for other Markdown elements if needed
}; But in the warnings I get the error like @pd2xts
The markdown looks like this:
So there are many Something like this const renderers = {
p: ({ children }) => <Text>{children}</Text>,
"*": ({ children }) => <Text>{children}</Text>,
}; |
Beta Was this translation helpful? Give feedback.
-
I am using react-markdown to convert markdown into JSX accepted by react-pdf using the
components
prop.This works beautifully, except that it react-pdf complaining about the newlines that appear to remain in the JSX but unwrapped by any component. In React PDF, all text including newlines must be wrapped in a component otherwise it is unhappy.
I get lots of errors like this:
I can't wrap the whole output in a Text component as although it resolves this issue it then is not formatted correctly.
Beta Was this translation helpful? Give feedback.
All reactions