prettier-markdown

raw JSON →
0.1.8 verified Sat Apr 25 auth: no javascript maintenance

Prettier is a popular code formatter, but it does not format JavaScript code embedded in Markdown files out of the box. prettier-markdown fills this gap by parsing Markdown files, extracting JavaScript code blocks, applying Prettier formatting, and writing the formatted code back into the Markdown. Version 0.1.8 is the latest stable release, but development appears to be dormant (last commit years ago). It provides both a CLI (with short command `pmd`) and a programmatic API returning Promises or using callbacks. Alternative tools include `prettier-plugin-md` (Prettier plugin) or `markdown-magic-prettier`, but this package offers a standalone solution.

error Error: Cannot find module 'prettier'
cause prettier is a peer dependency not automatically installed.
fix
Run 'npm install prettier' in your project.
error TypeError: prettierMarkdown is not a function
cause Using named import where default is expected.
fix
Use 'const prettierMarkdown = require('prettier-markdown');' or 'import prettierMarkdown from 'prettier-markdown';'
error SyntaxError: Unexpected token 'export'
cause The package does not support ES modules natively.
fix
Use require() or configure your bundler/Node to handle CommonJS.
deprecated Package has not been updated in years; may not work with newer Prettier versions.
fix Consider using prettier-plugin-md or markdown-magic-prettier instead.
gotcha The package uses remark internally; if your Markdown uses non-standard syntax, formatting may break.
fix Check Markdown validity; consider using a dedicated Prettier plugin.
gotcha No TypeScript definitions; TypeScript users must use require or create custom types.
fix Use // @ts-ignore or declare module 'prettier-markdown'.
npm install prettier-markdown
yarn add prettier-markdown
pnpm add prettier-markdown

Shows CLI command and programmatic usage with callback and Promise patterns.

// CLI usage
// prettier-markdown ./**/*.md
// pmd ./**/*.md

// Programmatic API
const prettierMarkdown = require('prettier-markdown');

// With callback
prettierMarkdown('./foo.md', function(err, msg) {
  if (err) console.error(err);
  else console.log(msg);
});

// With Promise
const promise = prettierMarkdown('./foo.md', {
  // options here
});
promise.then(msg => console.log(msg)).catch(err => console.error(err));