rich-text icon indicating copy to clipboard operation
rich-text copied to clipboard

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

Open localpcguy opened this issue 1 year ago • 4 comments

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);

localpcguy avatar Aug 23 '24 22:08 localpcguy

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

z0al avatar Aug 30 '24 15:08 z0al

Sure, I can take a stab at it

localpcguy avatar Sep 05 '24 21:09 localpcguy

Have not had time to work on this yet. I'm still interested in doing it, but also don't want to prevent someone else from jumping on it if they want to or need it.

localpcguy avatar Jan 31 '25 15:01 localpcguy

Taking a stab with a simple implementation using the following logic:

  • adding options as a third optional parameter, much like documentToHtmlString
  • checking to see if the desired renderNode is available and if so, using it from within the check to see if we are a block or inline object

I say simple because I do not see a need to define defaults for all renderers since this is ultimately rendering text.

skoch avatar Feb 10 '25 15:02 skoch