Skip to content

About

Marked extensions to expand the standard MarkedJS markdown parser with additional features.

Topics

Resources

Contributing

Stars

5 stars

Watchers

2 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Marked Extensions Logo

Build Main Status Latest Release Total npm downloads of the bundle
GitHub contributors Dependency status for repo GitHub License
Stars Forks

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.


Table of contents

Installation

Import the desired extension from the available list and apply it to your Marked instance as shown below.

Usage

Basic Usage

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);

Framework Integration

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 in class, aria-*, role, hidden, open and tabindex, configuration in mx-<pkg>-<key>-<value> class tokens, and icons are drawn with CSS. No id, 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 a dispose function. Runtimes are idempotent per root, delegate their listeners to root only and create no window globals. 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 named marked-extended:<pkg>:<event>, for example marked-extended:tabs:switch or the cancelable marked-extended:lists:toggle.
  • SSR safety. Importing a package or creating an extension never touches document or window; 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 teardown

React, Vue and Angular examples are in MIGRATION-18.1.md. An ngx-markdown adapter (withMarkedExtended) is planned.

Compatibility

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.

More Resources

Available Extensions

Extension Package Version Downloads Description
All - Bundle @fsegurai/marked-extended-bundle npm downloads Includes all extensions in a single package for easy integration
Accordion @fsegurai/marked-extended-accordion npm downloads Add collapsible accordion sections to your markdown
Alert @fsegurai/marked-extended-alert npm downloads Create styled alert boxes for important information
Code @fsegurai/marked-extended-code npm downloads Code blocks with titles, line numbers, highlights, diffs and groups
Comments @fsegurai/marked-extended-comments npm downloads Add comment sections with author and timestamp metadata
Core @fsegurai/marked-extended-core npm downloads Shared runtime helpers (bundled into every package; for authors)
Embeds @fsegurai/marked-extended-embeds npm downloads Easily embed content from various platforms (YouTube, Twitter, etc.)
Footnote @fsegurai/marked-extended-footnote npm downloads Add footnotes with automatic numbering
Inline @fsegurai/marked-extended-inline npm downloads Inline marks: ==highlight==, optional ++insert++, ^superscript^ and subscript
Kanban @fsegurai/marked-extended-kanban npm downloads Create kanban boards with customizable columns and cards
Lists @fsegurai/marked-extended-lists npm downloads Enhanced list formatting options
Slide @fsegurai/marked-extended-slide npm downloads Create slide decks directly from markdown content
Source Map @fsegurai/marked-extended-source-map npm downloads Source line numbers and safe heading ids for editor-preview scroll sync
Spoiler @fsegurai/marked-extended-spoiler npm downloads Hide content behind spoiler tags
Tables @fsegurai/marked-extended-tables npm downloads Advanced table formatting with cell spanning
Tabs @fsegurai/marked-extended-tabs npm downloads Create tabbed content sections
Timeline @fsegurai/marked-extended-timeline npm downloads Display content in an interactive timeline format
TOC @fsegurai/marked-extended-toc npm downloads Generate a table of contents with [toc] or [toc:N]
Typographic @fsegurai/marked-extended-typographic npm downloads Improve typography with smart quotes, dashes, and more
Wikilinks @fsegurai/marked-extended-wikilinks npm downloads Wiki-style [[target#heading|alias]] links resolved by your callback

Demo Application

To see all extensions in action, check out the [DEMO].

Local Development

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 start

This will serve the application locally at http://[::1]:8000.

Semantic Versioning

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

License

Licensed under MIT.

About

Marked extensions to expand the standard MarkedJS markdown parser with additional features.

Topics

Resources

Contributing

Stars

5 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors