Skip to content

About

Set of constants that can help you to parse markdown content

Topics

Resources

Contributing

Security policy

Stars

10 stars

Watchers

1 watching

Forks

Latest commit

 

History

782 Commits

Folders and files

Repository files navigation

markdown-regex

Zero-dependency, TypeScript-typed RegExp patterns for extracting headers, links, images, lists and code from Markdown.

npm version CI bundle size coverage License: MIT Socket Badge

v2.1.0 is tagged and released on GitHub. The npm latest tag is still 1.2.0. Treat v2 as a preview until an npm 2.x publish lands.

Requires Node.js 20+. CI builds on Node 20, 22, and 24.

When to use this

Use markdown-regex for quick extraction, linting, or lightweight transforms.

Do not use it when you need an AST or CommonMark compliance. Use remark, micromark, or markdown-it.

Status and versions

Channel Version Notes
GitHub main / Release 2.1.0 2.1.0 TypeScript rewrite
npm latest 1.2.0 Legacy JavaScript API
Package name markdown-regex Same name on GitHub and npm
npm install github:LLazyEmail/markdown-regex#main

Quick Start

import { extractLinks, extractHeaders, REGEXP_LINK } from 'markdown-regex';

extractLinks('[a](b)');
// [{ text: 'a', url: 'b' }]

extractHeaders('# Title');
// [{ level: 1, text: 'Title' }]

'[a](b)'.match(REGEXP_LINK);
// ['[a](b)', 'a', 'b']

Every regex is global (g). Reset .lastIndex between .test() calls, or use matchAll.

API Reference

See the tables in this README and llms-full.txt. HTML cleanup lives on markdown-regex/cleanup.

import { REGEXP_EMPTY_UL } from 'markdown-regex/cleanup';
import { extractLinks } from 'markdown-regex';

Limitations

  • Nested emphasis is not fully handled.
  • REGEXP_LINK on raw Markdown matches inside code. Use extractLinks().
  • Reference links and setext headers are not matched.
  • See SECURITY.md for ReDoS. CI runs tests/redos.test.ts on every exported pattern.

Development

npm install
npm run build
npm run typecheck
npm test
npm run test:coverage

Tests are Vitest (tests/**/*.test.ts). Jest is not used.

CI builds on Node 20, 22, and 24.

Related

License

MIT

About

Set of constants that can help you to parse markdown content

Topics

Resources

Contributing

Security policy

Stars

10 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages