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

how to render content as article page after edit ? #456

Open
thunderwin opened this issue Oct 21, 2024 · 4 comments
Open

how to render content as article page after edit ? #456

thunderwin opened this issue Oct 21, 2024 · 4 comments

Comments

@thunderwin
Copy link

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

@ByeongminLee
Copy link

Here’s the method I used

  1. You can retrieve the JSON as an HTML-formatted string like this
    How to render JSON types into HTML elements? #313 (comment)

  2. 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>
  );
}
  1. 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>
  1. result
    스크린샷 2024-10-27 오후 6 17 47

@keyproco
Copy link

keyproco commented Nov 2, 2024

I think there is a better way to do that by using <EditorContent />, to avoid XSS vulnerabiilites and HTML conversion is done internally.

@zeiflonte
Copy link

@keyproco Could you elaborate on how to use <EditorContent /> for rendering?

@Zain-ul-din
Copy link

is there any way to do it on the server-side?

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

5 participants