A library of custom extensions for Marked.js
@fsegurai/marked-extensions is a collection of custom extensions for Marked.js, making it more powerful and versatile.
Import the desired extension from the available list and apply it to your Marked instance as shown below.
import {marked} from "marked";
import markedExtendedTables from "@fsegurai/marked-extended-tables";
// or UMD script
// <script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.js"></script>
// <script src="https://cdn.jsdelivr.net/npm/@fsegurai/marked-extended-tables/lib/index.umd.js"></script>
marked.use(markedExtendedTables());
const exampleMarkdown = `
| H1 | H2 | H3 |
|---------|---------|---------|
| This cell spans 3 columns |||
`;
marked.parse(exampleMarkdown);Since 18.1.0, every package follows one runtime contract, so the same output works in plain pages, React, Vue, Angular and server-side rendering. Upgrading from 18.0.x? Read MIGRATION-18.1.md: 18.1.0 is a minor version with breaking changes.
- Sanitizer-safe markup. The default HTML survives strict sanitizers such as Angular's
SecurityContext.HTML: state lives inclass,aria-*,role,hidden,openandtabindex, configuration inmx-<pkg>-<key>-<value>class tokens, and icons are drawn with CSS. Noid,style,data-*, inline handlers,<script>,<svg>or<iframe>in the default output. unsafeHtml: true. Each package whose markup changed keeps its 18.0 markup behind this option, for pages that do not sanitize.- Explicit runtimes. Interactive behaviour comes from
attachX(root, options?)(attachTabs,attachEmbeds,attachSlides…), which returns adisposefunction. Runtimes are idempotent per root, delegate their listeners torootonly and create nowindowglobals.attachX.refresh(root), or{ observe: true }, re-applies per-element setup after the content is replaced. attachAll. The bundle attaches every runtime at once and returns one{ dispose(), refresh() }handle.- Events. Runtimes dispatch bubbling
CustomEvents namedmarked-extended:<pkg>:<event>, for examplemarked-extended:tabs:switchor the cancelablemarked-extended:lists:toggle. - SSR safety. Importing a package or creating an extension never touches
documentorwindow; ids are content hashes, so server and client renders match.
import { Marked } from 'marked';
import { attachAll, markedExtendedTabs, markedExtendedEmbeds } from '@fsegurai/marked-extended-bundle';
const marked = new Marked().use(markedExtendedTabs(), markedExtendedEmbeds());
container.innerHTML = marked.parse(markdown); // or your framework's sanitized [innerHTML] / v-html binding
const handle = attachAll(container); // after render
handle.refresh(); // after replacing the content
handle.dispose(); // on teardownReact, Vue and Angular examples are in MIGRATION-18.1.md. An ngx-markdown
adapter (withMarkedExtended) is planned.
| Packages | Marked peer | Notes |
|---|---|---|
| 18.1.x | ^18 |
Safe-by-default runtime contract, mx- classes (breaking, see MIGRATION-18.1.md) |
| 18.0.x | ^18 |
Pin ~18.0.0 to stay on the 18.0 markup |
| 17.x | ^17 |
18.1.0 is a minor version that contains breaking changes, so a ^18 range picks it up: pin ~18.0.0 until you have
followed MIGRATION-18.1.md.
| Extension | Package | Version | Downloads | Description |
|---|---|---|---|---|
| All - Bundle | @fsegurai/marked-extended-bundle | Includes all extensions in a single package for easy integration | ||
| Accordion | @fsegurai/marked-extended-accordion | Add collapsible accordion sections to your markdown | ||
| Alert | @fsegurai/marked-extended-alert | Create styled alert boxes for important information | ||
| Code | @fsegurai/marked-extended-code | Code blocks with titles, line numbers, highlights, diffs and groups | ||
| Comments | @fsegurai/marked-extended-comments | Add comment sections with author and timestamp metadata | ||
| Core | @fsegurai/marked-extended-core | Shared runtime helpers (bundled into every package; for authors) | ||
| Embeds | @fsegurai/marked-extended-embeds | Easily embed content from various platforms (YouTube, Twitter, etc.) | ||
| Footnote | @fsegurai/marked-extended-footnote | Add footnotes with automatic numbering | ||
| Inline | @fsegurai/marked-extended-inline | Inline marks: ==highlight==, optional ++insert++, ^superscript^ and |
||
| Kanban | @fsegurai/marked-extended-kanban | Create kanban boards with customizable columns and cards | ||
| Lists | @fsegurai/marked-extended-lists | Enhanced list formatting options | ||
| Slide | @fsegurai/marked-extended-slide | Create slide decks directly from markdown content | ||
| Source Map | @fsegurai/marked-extended-source-map | Source line numbers and safe heading ids for editor-preview scroll sync | ||
| Spoiler | @fsegurai/marked-extended-spoiler | Hide content behind spoiler tags | ||
| Tables | @fsegurai/marked-extended-tables | Advanced table formatting with cell spanning | ||
| Tabs | @fsegurai/marked-extended-tabs | Create tabbed content sections | ||
| Timeline | @fsegurai/marked-extended-timeline | Display content in an interactive timeline format | ||
| TOC | @fsegurai/marked-extended-toc | Generate a table of contents with [toc] or [toc:N] | ||
| Typographic | @fsegurai/marked-extended-typographic | Improve typography with smart quotes, dashes, and more | ||
| Wikilinks | @fsegurai/marked-extended-wikilinks | Wiki-style [[target#heading|alias]] links resolved by your callback |
To see all extensions in action, check out the [DEMO].
I highly recommend using "bun" to manage the project dependencies.
To set up the demo locally, follow the next steps:
git clone https://github.com/fsegurai/marked-extensions.git
bun install
bun startThis will serve the application locally at http://[::1]:8000.
The expected commits format follows the Conventional Commits specification. Example:
- feat: add new markdown extension for spoilers
- fix: resolve issue with user profile update
- docs: update API documentation
- style: format code according to new style guide
- refactor: simplify user authentication logic
- test: add or fix unit tests for user registration
- chore: update build process or dependencies
- perf: improve database query performance
Licensed under MIT.