Open thunderwin opened 1 month ago
Here’s the method I used
You can retrieve the JSON as an HTML-formatted string like this https://github.com/steven-tey/novel/discussions/313#discussioncomment-8591476
Render the string obtained above as HTML
export default function ContentRenderer({ json }: { json: any }) {
const output = useMemo(() => {
return generateHTML(json, [
Bold,
BulletList,
Document,
Heading,
Link,
Paragraph,
ListItem,
Text,
]);
}, [json]);
return (
<pre>
<div dangerouslySetInnerHTML={{__html:output}}></div>
</pre>
);
}
By specifying the following className, you can define the style for the Novel editor
<div className="tiptap ProseMirror prose prose-lg dark:prose-invert prose-headings:font-title font-default focus:outline-none max-w-full">
<ContentRenderer json={value} />
</div>
result
I think there is a better way to do that by using <EditorContent />
, to avoid XSS vulnerabiilites and HTML conversion is done internally.
@keyproco Could you elaborate on how to use <EditorContent />
for rendering?
is there any way to do it on the server-side?
Describe the feature you'd like to request
how to render content as article page after edit ?
Describe the solution you'd like to see
the editing result is the JSON , now I need save it to the DB... my question is how to render it back to web page later and keep the format like i see in the editor?
Additional information
No response