hygraph/rich-text

Import element fuctions to reuse on my own code

rbastiansch opened this issue · 3 comments

Hey, I'm usign @graphcms/rich-text-html-renderer and found a situation where I would like to reuse element functions to use directly on my code inside of custom renderers, currently it only export astToHtmlString function.

My use case:

import { astToHtmlString, Link } from '@graphcms/rich-text-html-renderer'

...
renderers: {
  a: (props) => {
    const condition = true
    return condition
      ? `<a data-condition="special-data">${props.children}</a>`
      : Link(props)
  }
}

With that I could import Link function and keep consistency with rich-text-html-renderer library without rewriting this function as a workaround.

Is today able to import thoses functions in another way or would be able to export together further?

PS: If it's okay to export those functions I could open a PR for that

Opened PR #107

This does make sense to include. I also had a similar use case.

I'll review your PR and publish it. Thanks, @rbastiansch!

Merged #107. I'll publish it soon