{"id":16113,"library":"markdown-it","title":"Markdown-it Parser","description":"Markdown-it is a high-performance and highly extensible Markdown parser, currently at version 14.1.1. It strictly follows the CommonMark specification while also offering several useful syntax extensions like URL autolinking, smart typography (typographer), and HTML tag support. Known for its speed and configurability, users can easily add, modify, or replace parsing rules and extend functionality via a rich ecosystem of community-developed plugins available on npm. It prioritizes safety by design and is suitable for both Node.js and browser environments. The project maintains an active development pace with frequent updates, ensuring ongoing compatibility and feature enhancements.","status":"active","version":"14.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/markdown-it/markdown-it","tags":["javascript","markdown","parser","commonmark","markdown-it","markdown-it-plugin"],"install":[{"cmd":"npm install markdown-it","lang":"bash","label":"npm"},{"cmd":"yarn add markdown-it","lang":"bash","label":"yarn"},{"cmd":"pnpm add markdown-it","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primary ESM import for Node.js and modern browser bundlers. It's a default export.","wrong":"import { markdownit } from 'markdown-it'","symbol":"markdownit","correct":"import markdownit from 'markdown-it'"},{"note":"CommonJS import for Node.js environments. This is the traditional way for older projects.","symbol":"markdownit","correct":"const markdownit = require('markdown-it')"},{"note":"For TypeScript users to import the type definition of the default export.","symbol":"MarkdownIt","correct":"import type MarkdownIt from 'markdown-it'"},{"note":"For browser environments loading markdown-it via a <script> tag (UMD build). Note the global is `markdownit` (no dash).","symbol":"window.markdownit","correct":"const md = window.markdownit()"}],"quickstart":{"code":"import markdownit from 'markdown-it';\n\n// Initialize markdown-it with specific options\nconst md = markdownit({\n  html: true,        // Enable HTML tags in source\n  linkify: true,     // Autoconvert URL-like text to links\n  typographer: true  // Enable smart quotes and other typographic replacements\n});\n\n// Example 1: Basic rendering\nconst markdownText1 = '# Hello, markdown-it!\\n\\nThis is a *simple* paragraph with an [example link](https://example.com).';\nconst htmlResult1 = md.render(markdownText1);\nconsole.log('Basic Render:\\n', htmlResult1);\n\n// Example 2: Render inline content (without paragraph wrap)\nconst markdownText2 = '__markdown-it__ rulezz!';\nconst htmlResult2 = md.renderInline(markdownText2);\nconsole.log('\\nInline Render:\\n', htmlResult2);\n\n// Example 3: Demonstrating typographer and linkify\nconst markdownText3 = 'Check out google.com or write \"hello\" here.';\nconst htmlResult3 = md.render(markdownText3);\nconsole.log('\\nTypographer & Linkify:\\n', htmlResult3);","lang":"typescript","description":"Demonstrates basic markdown-it initialization with common options, renders a block of Markdown text, and shows inline rendering for single-line content."},"warnings":[{"fix":"Access the global instance using `window.markdownit`.","message":"When using markdown-it in a browser environment via a `<script>` tag, the global variable created is `window.markdownit` (without a hyphen). Attempting to access `window.markdown-it` will result in a `ReferenceError`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Explicitly initialize with a preset (e.g., `markdownit('default')`) or configure options to match previous behavior after consulting the changelog for your specific upgrade path.","message":"Earlier versions of markdown-it (prior to v11) had a different default preset. If you are upgrading from a very old version, some default rules or options may have changed, potentially altering rendering output.","severity":"breaking","affected_versions":"<11.0.0"},{"fix":"Only use well-vetted and trusted plugins from reliable sources. When in doubt, audit plugin code or sanitize the output further if it contains user-generated content after parsing.","message":"While markdown-it is designed to be safe by default, using third-party plugins can introduce security vulnerabilities if they are not properly audited. Always review plugin code for potential XSS or other injection risks, especially if processing untrusted user input.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Thoroughly test custom rule sets with diverse Markdown inputs. Consult the 'Development info' documentation on the GitHub repository for guidance on rule management and plugin development.","message":"Managing rule priorities and order when adding or replacing custom parsing rules can be complex. Incorrect rule configuration can lead to unexpected parsing behavior or conflicts between rules.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Use `import markdownit from 'markdown-it'` for ESM or `const markdownit = require('markdown-it')` for CommonJS.","cause":"Attempting to `import { markdownit } from 'markdown-it'` (named import) instead of `import markdownit from 'markdown-it'` (default import) in an ESM environment, or mixing CJS `require` with an ESM-only context.","error":"TypeError: markdownit is not a constructor"},{"fix":"Ensure you are referencing `window.markdownit()` when using the UMD build directly in the browser.","cause":"In a browser environment, the `markdown-it` UMD build exposes its API on `window.markdownit`. Directly using `markdownit()` without `window.` will result in this error.","error":"ReferenceError: markdownit is not defined"},{"fix":"Verify plugin registration (`md.use(plugin)`). Check rule names for typos. Adjust rule insertion methods (`.before()`, `.after()`, `.at()`) and priorities to ensure correct execution order.","cause":"Incorrectly registered the plugin, specified a wrong rule name, or set an incorrect rule priority, leading to it not firing or being overridden.","error":"My custom plugin isn't working or is conflicting with existing rules."}],"ecosystem":"npm"}