What is remove-markdown?
The remove-markdown npm package is a utility that strips Markdown formatting from text, leaving only the plain text content. This can be useful for displaying Markdown content in environments that do not support Markdown or for preprocessing text for further analysis.
What are remove-markdown's main functionalities?
Basic Markdown Removal
This feature allows you to remove basic Markdown formatting such as headers, bold, and italic text from a string.
const removeMd = require('remove-markdown');
const markdownText = '# Hello World\nThis is a **bold** statement.';
const plainText = removeMd(markdownText);
console.log(plainText); // Output: 'Hello World\nThis is a bold statement.'
Handling Links
This feature strips Markdown link syntax, leaving just the link text.
const removeMd = require('remove-markdown');
const markdownText = '[Google](https://www.google.com) is a search engine.';
const plainText = removeMd(markdownText);
console.log(plainText); // Output: 'Google is a search engine.'
Handling Images
This feature removes Markdown image syntax, leaving just the alt text.
const removeMd = require('remove-markdown');
const markdownText = '![Alt text](https://example.com/image.jpg) is an image.';
const plainText = removeMd(markdownText);
console.log(plainText); // Output: 'Alt text is an image.'
Other packages similar to remove-markdown
turndown
Turndown is a library that converts HTML into Markdown. While it primarily focuses on converting HTML to Markdown, it can also be used to strip HTML tags, which can be useful for similar purposes as remove-markdown.
marked
Marked is a fast, low-level Markdown parser that can be used to convert Markdown to HTML. While its primary function is not to strip Markdown, it can be used in conjunction with other tools to achieve similar results.
showdown
Showdown is a bidirectional Markdown to HTML converter. It can be used to convert Markdown to HTML and then strip the HTML tags to get plain text, providing a similar end result to remove-markdown.
What is it?
remove-markdown is a node.js module that will remove (strip) Markdown formatting from a text. "Markdown formatting" means pretty much anything that doesn’t look like regular text, like square brackets, asterisks etc.
When do I need it?
The typical use case is to display an excerpt of a Markdown text, without the actual Markdown (or rendered HTML, for that matter), for example in a list of posts.
Installation
npm install remove-markdown
Usage
const removeMd = require('remove-markdown');
const markdown = '# This is a heading\n\nThis is a paragraph with [a link](http://www.disney.com/) in it.';
const plainText = removeMd(markdown);
You can also supply an options object to the function. Currently, the following options are supported:
var plainText = removeMd(markdown, {
stripListLeaders: true ,
listUnicodeChar: '',
gfm: true
});
Setting stripListLeaders
to false will retain any list characters (*, -, +, (digit).
).
TODO
PRs are very much welcome.
- Allow the RegEx expressions to be customized per rule
- Make the rules more robust, support more edge cases
- Add more (comprehensive) tests
Credits
The code is based on Markdown Service Tools - Strip Markdown by Brett Terpstra.
Author
Stian Grytøyr