React-markdown: Feature request: Option to skip parsing of disallowed nodes

Created on 29 Nov 2017  路  8Comments  路  Source: remarkjs/react-markdown

With the following code, nothing is rendered as the listItem node is not included in allowedTypes.

const source = `- hello`
<Markdown source={source} allowedTypes={['paragraph', 'emphasis', 'strong']} />

It would be nice to have an option to render any disallowed nodes with its markdown intact (ie. - hello). Using unwrapDisallowed doesn't quite get what I'm after as the markdown code is not included (ie. hello).

馃憖 areexternal 馃檵 typquestion

Most helpful comment

@ajbeaven @sibartlett Try using the remark-disable-tokenizers plugin to ignore specific tokens:

import remarkDisableTokenizers from "remark-disable-tokenizers";

<ReactMarkdown
  plugins={[
    [
      remarkDisableTokenizers,
      { block: ["list"] }
    ]
  ]}>
  {markdownContent}
</ReactMarkdown>

All 8 comments

What is the HTML output you would expect from this?

Sorry, that may not have been clear. I expect the HTML output to be - hello.

I would really appreciate this behaviour too.

If I disallow nodes, I expect the text to be rendered just as the user typed.

Looks like this would be possible by deleting a tokenizer from the remark parser at runtime: https://github.com/remarkjs/remark/tree/master/packages/remark-parse#turning-off-a-tokenizer

If you want help with this, I could submit a PR.

Always happy to receive contributions!

@ajbeaven @sibartlett Try using the remark-disable-tokenizers plugin to ignore specific tokens:

import remarkDisableTokenizers from "remark-disable-tokenizers";

<ReactMarkdown
  plugins={[
    [
      remarkDisableTokenizers,
      { block: ["list"] }
    ]
  ]}>
  {markdownContent}
</ReactMarkdown>

The answer is indeed to use plugins

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LinusU picture LinusU  路  3Comments

ghost picture ghost  路  4Comments

guilhermecastro-hotmart picture guilhermecastro-hotmart  路  3Comments

dekryptic picture dekryptic  路  3Comments

ScarellaDev picture ScarellaDev  路  3Comments