Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
remove-markdown
Advanced tools
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.
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.'
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 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 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.
remove-markdown is a node.js module that will remove (strip) Markdown formatting from text. Markdown formatting means pretty much anything that doesn’t look like regular text, like square brackets, asterisks etc.
The typical use case is to display an excerpt from some Markdown text, without any of the actual Markdown syntax - for example in a list of posts.
npm install remove-markdown
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); // plainText is now 'This is a heading\n\nThis is a paragraph with a link in it.'
You can also supply an options object to the function. Currently, the following options are supported:
const plainText = removeMd(markdown, {
stripListLeaders: true , // strip list leaders (default: true)
listUnicodeChar: '', // char to insert instead of stripped list leaders (default: '')
gfm: true // support GitHub-Flavored Markdown (default: true)
useImgAltText: true // replace images with alt-text, if present (default: true)
});
Setting stripListLeaders
to false will retain any list characters (*, -, +, (digit).
).
PRs are very much welcome. Here are some ideas for future enhancements:
The code is based on Markdown Service Tools - Strip Markdown by Brett Terpstra.
Stian Grytøyr (original creator) zuchka (maintainer since 2023)
FAQs
Remove Markdown formatting from text
The npm package remove-markdown receives a total of 217,322 weekly downloads. As such, remove-markdown popularity was classified as popular.
We found that remove-markdown demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.