2024-5-3

GitHub Flavored Markdown with remark-gfm

A Comprehensive Guide to GFM Features and Usage

Table of Contents

Introduction

remark-gfm is a plugin for remark that adds support for GitHub Flavored Markdown (GFM) features. This guide covers all the GFM features supported by the package and provides practical examples for each.

Installation and Setup

npm install remark-gfm

Integration with Remark

import rehypeStringify from 'rehype-stringify'
import remarkGfm from 'remark-gfm'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import {read} from 'to-vfile'
import {unified} from 'unified'

const file = await unified()
  .use(remarkParse)
  .use(remarkGfm)
  .use(remarkRehype)
  .use(rehypeStringify)
  .process(await read('example.md'))

console.log(String(file))
GFM automatically converts URLs and email addresses to links without requiring explicit markdown link syntax.

Examples

Visit our website at www.company.com or contact us at support@company.com.
Follow us on https://twitter.com/company for updates.
Visit our website at www.company.com or contact us at support@company.com. Follow us on https://twitter.com/company for updates.

Limitations and Best Practices:

  • Autolinks must be surrounded by whitespace
  • URLs with special characters might need explicit linking
  • Some domains might require explicit http:// or https:// prefix

Footnotes

Footnotes allow you to add references and additional information without cluttering the main content.

Basic Syntax

Here's a statement that needs a reference[^1].

[^1]: This is the reference text.
Here's a statement that needs a reference1.

Examples

Here's a complex example[^example] with multiple footnotes[^multiple] demonstrating different use cases[^different].

[^example]: First footnote with simple text.
[^multiple]: Second footnote with multiple lines:
    - Supporting point 1
    - Supporting point 2
    - Supporting point 3
[^different]: Third footnote with `code` and [links](https://example.com).
Here's a complex example2 with multiple footnotes3 demonstrating different use cases4.

Best Practices:

  • Use meaningful reference labels
  • Keep footnotes concise
  • Consider using inline footnotes for brief additions
  • Order footnotes logically

Strikethrough

Strikethrough text is useful for showing changes, updates, or deprecated information.

Basic Syntax

~~Strikethrough text~~
Strikethrough text

Examples

  1. Showing Changes:
  • Original price: $99.99 Now: $79.99
  1. Task Updates:
  • Complete initial draft
  • Review with team
  • Publish document
  1. Deprecated Features: Use legacy API Use new v2 API endpoints

Nested Formatting

You can combine strikethrough with other formatting:
  • Bold strikethrough
  • Italic strikethrough
  • code strikethrough

Tables

Tables in GFM provide flexible ways to organize and present data.

Alignment Options: Left-aligned (Default)

| Header 1 | Header 2 | Header 3 |
| - | - | - |
| Row 1 | Data | Data |
| Row 2 | Data | Data |
Header 1Header 2Header 3
Row 1DataData
Row 2DataData

Alignment Options: Right-aligned

| Header 1 | Header 2 | Header 3 |
| -: | -: | -: |
| Row 1 | Data | Data |
| Row 2 | Data | Data |
Header 1Header 2Header 3
Row 1DataData
Row 2DataData

Alignment Options: Center-aligned

| Header 1 | Header 2 | Header 3 |
| :-: | :-: | :-: |
| Row 1 | Data | Data |
| Row 2 | Data | Data |
Header 1Header 2Header 3
Row 1DataData
Row 2DataData

Alignment Options: Mixed Alignment

| Left | Center | Right |
| :- | :-: | -: |
| Text | Text | Text |
| Data | Data | Data |
LeftCenterRight
TextTextText
DataDataData

Best Practices for Tables

  1. Keep tables simple and readable
  2. Use consistent column widths
  3. Align numbers right
  4. Align text left
  5. Use center alignment sparingly

Tasklists

Tasklists (or checklists) are perfect for tracking progress and creating interactive to-do lists.

Basic Syntax

- [ ] Unchecked item
- [x] Checked item
  • Unchecked item
  • Checked item

Examples

Project Checklist

  • Project Setup
    • Initialize repository
    • Set up development environment
    • Configure CI/CD
  • Development Phase
    • Create basic structure
    • Implement core features
    • Write tests
  • Deployment
    • Prepare documentation
    • Deploy to staging
    • Deploy to production

Release Checklist

  • Code review completed
  • Tests passed
  • Documentation updated
  • Version bumped
  • Changelog updated
  • Release notes prepared

Best Practices:

  1. Use hierarchical structure for complex tasks
  2. Keep items concise
  3. Update regularly
  4. Include completion dates for tracked items

Compatibility and Browser Support

FeatureChromeFirefoxSafariEdge
Autolinks
Footnotes
Strikethrough
Tables
Tasklists

Additional Resources

Footnotes

  1. This is the reference text.
  2. First footnote with simple text.
  3. Second footnote with multiple lines:
    • Supporting point 1
    • Supporting point 2
    • Supporting point 3
  4. Third footnote with code and links.