Install remove-markdown via npm
mainInstall the remove-markdown module using npm to strip Markdown formatting from text in your Node.js applications.
npm install remove-markdownrepository·main·Indexed 18 days ago
https://github.com/zuchka/remove-markdownA Node.js module designed to strip Markdown formatting from text to produce plain text content. Version 0.6.4 supports GitHub-Flavored Markdown (GFM) and provides configurable options for handling list leaders, image alt-text, inline links, and HTML tags.
Install the remove-markdown module using npm to strip Markdown formatting from text in your Node.js applications.
npm install remove-markdownImport remove-markdown and call the function with a Markdown string to receive a plain text version. The function removes syntax like square brackets, asterisks, and other non-text formatting.
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.'The removeMd function accepts an optional configuration object to customize how Markdown is stripped.
Key behaviors include:
*, -, +, (digit).) are removed using stripListLeaders (default: true). You can specify a replacement character via listUnicodeChar (default: '').replaceLinksWithURL to remove inline links or separateLinksAndTexts to replace them with a format like text: URL.useImgAltText to replace images with their alt-text (default: true).gfm (default: true).htmlTagsToSkip (default: []).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)
abbr: true, // remove abbreviations, if present (default: false)
replaceLinksWithURL: true, // remove inline links, if present (default: false)
separateLinksAndTexts: ': ', // replace inline links with text, separator and link, if present (default: null)
htmlTagsToSkip: ['a', 'b'], // HTML tags to skip, if present (default: [])
throwError: false, // throw errors instead of catching and logging (default: false)
});The options object allows you to control how different Markdown elements are handled during the stripping process.
| Option | Type | Default | Description |
|---|---|---|---|
listUnicodeChar | boolean | false | If true and stripListLeaders is enabled, replaces list markers with this character (Note: implementation uses this as a prefix string). |
stripListLeaders | boolean | true | Whether to remove list markers (e.g., *, -, +, 1.). |
gfm | boolean | true | Enables GitHub Flavored Markdown stripping (fenced code blocks, strikethrough, etc.). |
useImgAltText | boolean | true | If true, replaces images  with their alt text. If false, removes them entirely. |
abbr | boolean | false | Whether to remove abbreviation definitions (e.g., *[abbr]: definition). |
replaceLinksWithURL | boolean | false | If true, replaces inline links [text](url) with the URL. If false, keeps the link text. |
separateLinksAndTexts | string | null | A string used to separate the link text and the URL when separateLinksAndTexts is provided (e.g., " "). |
htmlTagsToSkip | Array<string> | [] | A list of HTML tags that should NOT be stripped. |
throwError | boolean | false | If true, the function will throw an error if processing fails. Otherwise, it logs the error to console.error and returns the original input string. |
const removeMarkdown = require('remove-markdown');
const options = {
stripListLeaders: true,
useImgAltText: true,
replaceLinksWithURL: true,
htmlTagsToSkip: ['code', 'pre']
};
const plainText = removeMarkdown(markdown, options);The following options are available for the removeMd function:
| Option | Type | Default | Description |
|---|---|---|---|
stripListLeaders | boolean | true | If false, retains list characters (*, -, +, (digit).) |
listUnicodeChar | string | '' | Character to insert instead of stripped list leaders |
gfm | boolean | true | Support GitHub-Flavored Markdown |
useImgAltText | boolean | true | Replace images with alt-text, if present |
abbr | boolean | false | Remove abbreviations, if present |
replaceLinksWithURL | boolean | false | Remove inline links, if present |
separateLinksAndTexts | string | null | Replace inline links with text, separator and link, if present |
htmlTagsToSkip | string[] | [] | HTML tags to skip, if present |
throwError | boolean | false | Throw errors instead of catching and logging |
The default export is a function that accepts a Markdown string and an optional configuration object to strip Markdown syntax and return plain text.
Signature: function(md, options)
md (String): The Markdown text to process. If null or undefined, it defaults to an empty string.options (Object): Configuration to customize the stripping behavior. Defaults to an empty object if not provided.const removeMarkdown = require('remove-markdown');
const markdown = '# Hello World\n\nThis is **bold** and [a link](https://example.com).';
const plainText = removeMarkdown(markdown);
// Output: "Hello World\n\nThis is bold and a link."