hygraph / rich-text

A set of companion packages for Hygraph's Rich Text Field
MIT License
93 stars 18 forks source link

Import element fuctions to reuse on my own code #106

Closed rbastiansch closed 1 year ago

rbastiansch commented 1 year ago

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

rbastiansch commented 1 year ago

Opened PR https://github.com/hygraph/rich-text/pull/107

jpedroschmitz commented 1 year ago

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

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

jpedroschmitz commented 1 year ago

Merged #107. I'll publish it soon