Next.js Discord

Discord Forum

Custom CMS Rich Text Handling (HTML + DOMPurify) — Best Practices Without Third-Party CMS?

Unanswered
Almond stone wasp posted this in #help-forum
Open in Discord
Almond stone waspOP
I'm building a custom CMS for a news-style site using Next.js, without using third-party CMS tools like Sanity. My content field needs to support rich text formatting such as headings, lists, links, blockquotes, and code blocks. Currently, I'm storing HTML in the database and rendering it on the frontend using isomorphic DOMPurify to sanitize the content before displaying it. I'm using a renderer component that allows specific tags (headings, lists, blockquotes, links, etc.) and outputs the sanitized HTML using dangerouslySetInnerHTML.

So far, this setup works and I’m not getting errors, but I’m trying to figure out the best long-term structure for this kind of system. I haven’t integrated a rich text editor yet, and I'm considering whether I should continue storing HTML or switch to JSON or Markdown instead.

My questions are:
-In a custom Next.js CMS, do you usually store rich text as HTML, JSON, or Markdown?
-What rich text editor do you recommend for this kind of setup?
-Are there any best practices for handling structured content like blockquotes and formatted text in the long term?

1 Reply

@Almond stone wasp I'm building a custom CMS for a news-style site using Next.js, without using third-party CMS tools like Sanity. My content field needs to support rich text formatting such as headings, lists, links, blockquotes, and code blocks. Currently, I'm storing HTML in the database and rendering it on the frontend using isomorphic DOMPurify to sanitize the content before displaying it. I'm using a renderer component that allows specific tags (headings, lists, blockquotes, links, etc.) and outputs the sanitized HTML using dangerouslySetInnerHTML. So far, this setup works and I’m not getting errors, but I’m trying to figure out the best long-term structure for this kind of system. I haven’t integrated a rich text editor yet, and I'm considering whether I should continue storing HTML or switch to JSON or Markdown instead. My questions are: -In a custom Next.js CMS, do you usually store rich text as HTML, JSON, or Markdown? -What rich text editor do you recommend for this kind of setup? -Are there any best practices for handling structured content like blockquotes and formatted text in the long term?
-In a custom Next.js CMS, do you usually store rich text as HTML, JSON, or Markdown?
markdown is the way to go
-What rich text editor do you recommend for this kind of setup?
I like to use tiptap. Its easy to setup, less code and highly configurable
-Are there any best practices for handling structured content like blockquotes and formatted text in the long term?
yes: markdown