Home

Awesome

markdown-magic-prettier

Use prettier to format JS codeblocks in markdown files via markdown-magic

Install

yarn add -D markdown-magic markdown-magic-prettier prettier

Note: prettier is a peer dependency and must be installed separately from this module

Adding the plugin

See example.js for usage.

<!-- AUTO-GENERATED-CONTENT:START (CODE:src=./example.js) --> <!-- The below code snippet is automatically added from ./example.js -->
const fs = require('fs');
const path = require('path');
const markdownMagic = require('markdown-magic');

const config = {
  transforms: {
    PRETTIER: require('./index.js'),
  },
};

const markdownPath = path.join(__dirname, 'README.md');
markdownMagic(markdownPath, config);
<!-- AUTO-GENERATED-CONTENT:END *-->

Usage in markdown

Wrap code blocks to format the content.

<!-- AUTO-GENERATED-CONTENT:START (PRETTIER) -->
console.log('hello world');
<!-- AUTO-GENERATED-CONTENT:END -->

Options

All prettier options are supported.

There are a few defaults set:

<!-- AUTO-GENERATED-CONTENT:START (PRETTIER) -->
const defaults = {
  singleQuote: true,
  trailingComma: 'es5',
};
<!-- AUTO-GENERATED-CONTENT:END -->