remark plugin to support GitHub Flavored Markdown (GFM) features including autolink literals, footnotes, strikethrough, tables, and task lists
npx @tessl/cli install tessl/npm-remark-gfm@4.0.0remark-gfm is a plugin for the remark markdown processor that adds support for GitHub Flavored Markdown (GFM) extensions. It enables parsing and serialization of autolink literals, footnotes, strikethrough, tables, and task lists in markdown documents.
npm install remark-gfmESM (recommended):
import remarkGfm from 'remark-gfm';For TypeScript users with type annotations:
import remarkGfm, {type Options} from 'remark-gfm';CommonJS:
const remarkGfm = require('remark-gfm');import {unified} from 'unified';
import remarkParse from 'remark-parse';
import remarkRehype from 'remark-rehype';
import rehypeStringify from 'rehype-stringify';
import remarkGfm from 'remark-gfm';
const processor = unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkRehype)
.use(rehypeStringify);
const result = await processor.process('~~strikethrough~~ and www.example.com');The main function that adds GFM support to a remark processor.
/**
* Add support for GFM (autolink literals, footnotes, strikethrough, tables, tasklists)
* @param options - Configuration options (optional)
* @returns Nothing (undefined)
*/
declare function remarkGfm(options?: Options | null | undefined): undefined;
export default remarkGfm;Usage Examples:
import {unified} from 'unified';
import remarkParse from 'remark-parse';
import remarkGfm from 'remark-gfm';
// Basic usage without options
const processor = unified()
.use(remarkParse)
.use(remarkGfm);
// With options
const processor = unified()
.use(remarkParse)
.use(remarkGfm, {
singleTilde: false,
tablePipeAlign: true
});
// TypeScript usage with explicit types
import type {Options} from 'remark-gfm';
const options: Options = {
singleTilde: false,
stringLength: (value: string) => value.length,
tablePipeAlign: true,
tableCellPadding: true
};
const processor = unified()
.use(remarkParse)
.use(remarkGfm, options);Options interface for customizing remark-gfm behavior.
export interface Options {
/**
* Whether to support strikethrough with a single tilde.
* Single tildes work on github.com but are technically prohibited by GFM.
* You can always use 2 or more tildes for strikethrough.
* @default true
*/
singleTilde?: boolean;
/**
* Whether to serialize with a blank line for the first line of footnote definitions.
* @default false
*/
firstLineBlank?: boolean;
/**
* Function to detect the size of table cells, used when aligning cells.
* @default (value) => value.length
*/
stringLength?: (value: string) => number;
/**
* Whether to align table pipes in serialized output.
* @default true
*/
tablePipeAlign?: boolean;
/**
* Whether to add a space of padding between table pipes and cells.
* @default true
*/
tableCellPadding?: boolean;
}Usage Examples:
import remarkGfm from 'remark-gfm';
import stringWidth from 'string-width';
// Disable single tilde strikethrough
processor.use(remarkGfm, {
singleTilde: false
});
// Custom string length for Unicode-aware table alignment
processor.use(remarkGfm, {
stringLength: stringWidth
});
// Disable table formatting
processor.use(remarkGfm, {
tablePipeAlign: false,
tableCellPadding: false
});This plugin adds support for the following GFM extensions:
Automatically converts URLs and email addresses to links:
www.example.com → <a href="http://www.example.com">www.example.com</a>https://example.com → <a href="https://example.com">https://example.com</a>contact@example.com → <a href="mailto:contact@example.com">contact@example.com</a>Support for footnote syntax:
Here is a footnote reference[^1].
[^1]: Here is the footnote definition.Support for strikethrough text:
~~two tildes~~ (standard GFM)~one tilde~ (GitHub extension, can be disabled with singleTilde: false)Support for GitHub-style tables:
| Header 1 | Header 2 |
| -------- | -------- |
| Cell 1 | Cell 2 |With alignment:
| Left | Center | Right |
| :--- | :----: | ----: |
| L | C | R |Support for task list items:
- [ ] Incomplete task
- [x] Complete taskunified ecosystem with remark-parse for parsingremark-stringify for serialization back to markdownremark-rehype for HTML conversion