Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

richtext not rendering with defaultConverters

default discord avatar
joelcoreylast year
6

I have copied the richtext example from the template here:

https://github.com/payloadcms/payload/blob/main/templates/website/src/components/RichText/index.tsx

I have simplified it by only commenting out what I "don't need" currently.





And the block that uses the component:

// import { cn } from '@/utilities/ui'
import React from 'react'
import RichText from '@/components/RichText'

import type { ContentBlock as ContentBlockProps } from '@/payload-types'

// import { CMSLink } from '../../components/Link'

const Content: React.FC<ContentBlockProps> = (props) => {
  const { columns } = props

  const colsSpanClasses = {
    full: '12',
    half: '6',
    oneThird: '4',
    twoThirds: '8',
  }

  return (
    <div className="container my-16">
      <div className="grid grid-cols-4 lg:grid-cols-12 gap-y-8 gap-x-16">
        {columns &&
          columns.length > 0 &&
          columns.map((col, index) => {
            const { enableLink, link, richText, size } = col

            return (
              <div
                className={``}
                key={index}
              >
                {richText && <RichText data={richText} enableGutter={false} />}

                {/* {enableLink && <CMSLink {...link} />} */}
              </div>
            )
          })}
      </div>
    </div>
  )
}

export default Content


The data comes through to the website but is not converted.

  • default discord avatar
    flohhhlast year

    Using tailwind typography & prose on the container is one option


    https://github.com/tailwindlabs/tailwindcss-typography

    Example


        <article className="prose">
          <h1>{post.title}</h1>
          <RichText data={post.content} />
        </article>
  • default discord avatar
    joelcoreylast year

    It occurs to me that even after reading the documentation quite a few times, I really just don't get how it is supposed to work.



    ^ And that's on me. Not a complaint.

  • default discord avatar
    flohhhlast year

    it's just rendering plain content like:



    <h1>H1</h1>


    <ul>


    <li>this</li>


    <li>is</li>


    </ul>



    there's no styling on it



    tailwind typography

    prose

    class automatically applies opinionated styles to any child markdown elements



    i'm not sure what the alternative is to using tailwind's typography solution, i guess you would have to make a class yourself in css and style each type of element yourself (the tailwind solution is pretty nice looking and customizable)

  • default discord avatar
    joelcoreylast year

    That's interesting. I do use and enjoy Tailwind. But I could also pass custom blocks I guess? It seems like a lot of work for "richtext" that is not very rich.

  • default discord avatar
    flohhhlast year

    yes custom blocks have their own renderers i think, i'm not sure on the specifics of inline blocks yet



    its really not a lot of work, this would be the solution with the least "work"



    install tailwind typography plugin



    put

    className="prose"

    on the parent div of the post content



    this is example result

  • default discord avatar
    joelcoreylast year

    Nice. Okay, I will try this later after dropping kiddos off. Thank you!



    Yep. Confirmed this fixed my issue.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.