Support Ukraine 🇺🇦Help Ukrainian ArmyHumanitarian Assistance to Ukrainians

How to convert a string with markdown to a string with plain text?

Laverage

Jan 06 2020 at 07:38 GMT

I have some markdown that I want to convert to plain text.

For example,

const markdown = 'Markdown **is** _great_. `But` I want\n```\nplain text\n```'

markdownToPlainText(markdown)
// Should output:
// Markdown is great. But I want
// plain text

What npm package can I use to accomplish that?

1 Answer

Mike The Programmer

Jan 06 2020 at 07:46 GMT

There's an npm package called remove-markdown that you can use to do the markdown to plain text conversion.

npm install remove-markdown

Here's how to use it:

const removeMd = require('remove-markdown')

const markdown = 'Markdown **is** _great_. `But` I want\n```\nplain text\n```\n'

const plainText = removeMd(markdown)
console.log(plainText)
// Output:
// Markdown is great. But I want
// plain text
claritician © 2022