mdx-formatter

Type to search...

to open search from anywhere

You are viewing documentation for an older version. View the latest version

Usage

CLI and API usage for mdx-formatter

CLI

# Check files (exit with error if formatting needed)
mdx-formatter --check "**/*.{md,mdx}"

# Format files in place
mdx-formatter --write "**/*.{md,mdx}"

# Preview what would be changed (default)
mdx-formatter "**/*.{md,mdx}"

# Ignore specific patterns
mdx-formatter --write "**/*.md" --ignore "node_modules/**,dist/**"

# Use a custom config file
mdx-formatter --write "**/*.md" --config ./my-config.json

API

import { format } from '@takazudo/mdx-formatter';

// Format a string
const formatted = await format('# Hello\nWorld');
console.log(formatted); // '# Hello\n\nWorld'

// Format with custom settings
const formatted2 = await format(content, {
  settings: {
    addEmptyLinesInBlockJsx: {
      blockComponents: ['Outro', 'InfoBox'],
    },
    indentJsxContent: {
      containerComponents: ['Outro', 'InfoBox'],
    },
    formatMultiLineJsx: {
      ignoreComponents: ['CodeBlock'],
    },
  },
});

Stdin

cat file.md | ./format-stdin.js > formatted.md

Integration with lint-staged

Add to your package.json:

{
  "lint-staged": {
    "*.{md,mdx}": ["mdx-formatter --write"]
  }
}

Revision History