### Install remove-markdown Source: https://github.com/zuchka/remove-markdown/blob/main/README.md Install the remove-markdown package using npm. This is the first step before using the module in your Node.js project. ```bash npm install remove-markdown ``` -------------------------------- ### TypeScript Usage Example Source: https://github.com/zuchka/remove-markdown/blob/main/_autodocs/module-exports.md Demonstrates how to import and use the `remove-markdown` module within a TypeScript project, including passing an options object to customize its behavior. ```typescript import removeMd from 'remove-markdown'; const markdown: string = '# Heading\n\n**bold**'; const plainText: string = removeMd(markdown, { stripListLeaders: true, gfm: true }); ``` -------------------------------- ### Complex Multi-Option Example Source: https://github.com/zuchka/remove-markdown/blob/main/_autodocs/api-reference.md Demonstrates combining multiple options for advanced markdown stripping, including preserving list content, using alt text for images, and replacing links with URLs. ```javascript const markdown = `## Header - **Bold item** with [link](http://example.com) - Regular item - Item with > A blockquote ![Image](url) `; const result = removeMd(markdown, { stripListLeaders: true, gfm: true, useImgAltText: true, replaceLinksWithURL: true }); // Removes markdown, keeps list content, preserves alt text, shows URLs instead of link text ``` -------------------------------- ### Comment Examples in JavaScript Source: https://github.com/zuchka/remove-markdown/blob/main/_autodocs/implementation-details.md Illustrates the minimal commenting style used, primarily for explaining specific regex rule purposes. Most rules rely on self-documenting regex patterns. ```javascript // Remove horizontal rules (stripListHeaders conflict with this rule, ...) // Header (for GFM) // Fenced codeblocks (with backticks) // Strikethrough // // Remove newlines in a paragraph (commented out) ``` -------------------------------- ### Markdown Removal with Options Source: https://github.com/zuchka/remove-markdown/blob/main/_autodocs/README.md Configure the markdown removal process by passing an options object. This example shows how to enable stripping list leaders, GitHub Flavored Markdown, using image alt text, and replacing links with URLs. ```javascript const result = removeMd(markdown, { stripListLeaders: true, gfm: true, useImgAltText: true, replaceLinksWithURL: true }); ``` -------------------------------- ### Basic Usage of remove-markdown Source: https://github.com/zuchka/remove-markdown/blob/main/README.md Import and use the removeMd function to strip Markdown from a string. This example shows how to convert a Markdown string containing a heading, paragraph, and link into plain text. ```javascript 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.' ``` -------------------------------- ### Advanced Usage with Options Source: https://github.com/zuchka/remove-markdown/blob/main/README.md Utilize the removeMd function with an options object to customize Markdown stripping behavior. This example demonstrates various options like stripping list leaders, replacing links with URLs, and skipping specific HTML tags. ```javascript 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) }); ``` -------------------------------- ### Triggering Regex Error with Invalid htmlTagsToSkip Source: https://github.com/zuchka/remove-markdown/blob/main/_autodocs/errors.md This example demonstrates how passing invalid regex special characters within the `htmlTagsToSkip` array could theoretically lead to a regex SyntaxError. ```javascript // This COULD cause a regex error (in theory): removeMd(markdown, { htmlTagsToSkip: ['[invalid]'] // [ and ] are regex metacharacters }); ``` -------------------------------- ### Sanitize HTML Tag Names for Safe Skipping Source: https://github.com/zuchka/remove-markdown/blob/main/_autodocs/errors.md When using the `htmlTagsToSkip` option with user-provided input, sanitize tag names to prevent potential security issues. This example filters out invalid characters from tag names. ```javascript function sanitizeTagName(tag) { // Only allow alphanumeric characters and hyphens (valid HTML tag names) return tag.replace(/[^a-zA-Z0-9\-]/g, ''); } const userTags = ['span', 'b