React-markdown: How to avoid <p> tag

Created on 7 Nov 2016  路  4Comments  路  Source: remarkjs/react-markdown

Hello,
There is a p tag always get enclosed when i use the markdown component which always disturbs my page layout. Can you please tell how to avoid that.

image

Most helpful comment

Sorry for not responding earlier, I've been a bit busy with life. You could set Paragraph as a disallowedTypes and set unwrapDisallowed to true. That'll make it a bit hard to handle newlines properly, though - not sure how you want to treat those? Example:

<Markdown
    source="Normally, this *sentence* would be wrapped in a paragraph."
    disallowedTypes={['Paragraph']}
    unwrapDisallowed
/>

Or, you could just replace the renderer for paragraphs with something else:

<Markdown
    source="Normally, this *sentence* would be wrapped in a paragraph."
    renderers={{Paragraph: 'span'}}
/>

This would render <span> instead of <p>, which might not be what you want, but you can use a custom react component instead if you want. Take a look at the readme for more information on the custom renderer feature.

All 4 comments

I was wondering this as well. It would be good if there was some way to avoid having the enclosing <p> tags.

Sorry for not responding earlier, I've been a bit busy with life. You could set Paragraph as a disallowedTypes and set unwrapDisallowed to true. That'll make it a bit hard to handle newlines properly, though - not sure how you want to treat those? Example:

<Markdown
    source="Normally, this *sentence* would be wrapped in a paragraph."
    disallowedTypes={['Paragraph']}
    unwrapDisallowed
/>

Or, you could just replace the renderer for paragraphs with something else:

<Markdown
    source="Normally, this *sentence* would be wrapped in a paragraph."
    renderers={{Paragraph: 'span'}}
/>

This would render <span> instead of <p>, which might not be what you want, but you can use a custom react component instead if you want. Take a look at the readme for more information on the custom renderer feature.

This doesn't work in v4.0, please confirm.

Seems like Paragraph got converted to lowercase paragraph. With the lowercase naming it does work.

You can also enable unwrapDisallowed to true.

My code:
const markdownTypesAllowed = [ 'text', 'strong', 'delete', 'emphasis', 'link' ];

<Markdown source={text} allowedTypes={markdownTypesAllowed} unwrapDisallowed={true} />

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhenyulin picture zhenyulin  路  3Comments

dbuchet picture dbuchet  路  3Comments

hiteshpatwari picture hiteshpatwari  路  3Comments

guilhermecastro-hotmart picture guilhermecastro-hotmart  路  3Comments

jonjaffe picture jonjaffe  路  3Comments