React-markdown: Parse only nodeTypes and output remainder unchanged

Created on 3 Apr 2020  路  5Comments  路  Source: remarkjs/react-markdown

Hi! Weird request... Maybe.

I'd like to parse some text as markdown and only convert for paragraphs, leaving the remainder as is.

The text, in places, uses characters shared by markdown syntax, but I don't wish to parse them as such - just paragraphs.

allowedTypes={['text', 'paragraph']} achieves part of this but removes other nodes that match markdown syntax.

I'm unsure of exactly how plugins work and how I could use one to achieve this, if it's even possible.

I wrote a render helper to conditionally turn links into react-router Link components but this would require some sort of catch-all and again I'm unsure if the input would get to this point if it matched disallowed markdown syntax

馃憖 areexternal 馃檵 typquestion

Most helpful comment

I have exactly the same issue... basically looking for a "renderDisallowedTypesAsText" option.

All 5 comments

I have exactly the same issue... basically looking for a "renderDisallowedTypesAsText" option.

One more request for this feature here. We basically need to use markdown only for non-block elements (links, bold, _italics_, strike-through) but we don't want any other syntax to be processed or even removed. We're processing in a certain context text that is not meant to be multi-line. Hence, if the user types "> is the greater-than symbol" we want that to appear as is. Same for heading syntax, list item syntax, etc.

I started achieving this with custom renderers for most block element types. But for cases like list items, I have no way of knowing the character used (-, +, *). It worked for blockquote and heading though.

Instead of using allowedTypes I ended up using the remark-disable-tokenizers plugin, to set types that should be ignored by the underlaying markdown-parser.

See this comment for an example.

Indeed. I came here to say the same thing, as a colleague in our team also found out about this and suggested it. It worked like a charm for us.

using a remark plugin is the preferred solution, see https://github.com/remarkjs/react-markdown/issues/408#issuecomment-642512405

Was this page helpful?
0 / 5 - 0 ratings

Related issues

guilhermecastro-hotmart picture guilhermecastro-hotmart  路  3Comments

d0lb33 picture d0lb33  路  3Comments

pcvandamcb picture pcvandamcb  路  3Comments

wqh17101 picture wqh17101  路  3Comments

damianobarbati picture damianobarbati  路  3Comments