contentful / rich-text

Libraries for handling and rendering Rich Text 📄
MIT License
549 stars 109 forks source link

[rich-text-plain-text-renderer] Allow custom render nodes to be provided like Rich Text Html Renderer #660

Open localpcguy opened 2 months ago

localpcguy commented 2 months ago

Feature Request: Allow custom render nodes to be provided like Rich Text Html Renderer. Use the same syntax as the RichTextHtmlRenderer does.

By allowing custom render nodes to be passed, users can handle things like embedded entries (see #161) as well as allowing for custom output for items such as links where both the text and uri would likely be desired.

An example:

A link could look something like this:

const customTextRenderNode = {
  renderNode: {
    [INLINES.HYPERLINK]: (node, next) => `${next(node.content)}: ${node.data.uri}\n`,
  },
};

And be called like this:

const renderedText = documentToPlainTextString(richTextDocument, null, customTextRenderNode);
z0al commented 2 months ago

Hey @localpcguy , that sounds like a good idea. Is that something you are willing to submit a PR for?

localpcguy commented 1 month ago

Sure, I can take a stab at it