GithubHelp home page GithubHelp logo

How to avoid <p> tag about react-markdown HOT 7 CLOSED

remarkjs avatar remarkjs commented on August 16, 2024 19
How to avoid

tag

from react-markdown.

Comments (7)

RemyMachado avatar RemyMachado commented on August 16, 2024 29

You can vanish the paragraph tag with a React.Fragment.

  return (
    <ReactMarkdown
      components={{
        p: React.Fragment,
      }}
    >
      {children}
    </ReactMarkdown>
  )

from react-markdown.

rexxars avatar rexxars commented on August 16, 2024 28

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.

from react-markdown.

Fleuv avatar Fleuv commented on August 16, 2024 17

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

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

from react-markdown.

vincerubinetti avatar vincerubinetti commented on August 16, 2024 11

Note that as of 2021 (version ???), the parameter names have changed a bit:

<ReactMarkdown
  components={{ p: "span" }}
  ...
>
  {children}
</ReactMarkdown>

And allowedElements / disallowedElements instead of allowedTypes / disallowedTypes

from react-markdown.

guillempuche avatar guillempuche commented on August 16, 2024 4

You can also enable unwrapDisallowed to true.

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

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

from react-markdown.

jordanmkoncz avatar jordanmkoncz commented on August 16, 2024

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

from react-markdown.

arisros avatar arisros commented on August 16, 2024

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

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

paragraph: 'p',

with lowercase p

paragraph: 'p',

from react-markdown.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.