GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - DSchau/prettier-markdown: Parse code blocks in markdown files and run prettier on them

BranchesTags
Open more actions menu

Latest commit

 

History

46 Commits
46 Commits

Folders and files

NameName
Last commit message
Last commit date
__fixtures__
__fixtures__
 
 
__mocks__
__mocks__
 
 
demo
demo
 
 
src
src
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
README.md
README.md
 
 
jest.config.js
jest.config.js
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 
yarn.lock
yarn.lock
 
 

Repository files navigation

prettier-markdown

Build Status NPM version

Prettier now includes support for prettifying Markdown (including code blocks!), so as such, I'd recommend using the official Prettier instead. See the release notes for more information

A simple utility and CLI to run prettier on code blocks within Markdown, leaving any non-code blocks untouched.

Currently works on the following languages (basically everything prettier supports!):

  • JavaScript
  • TypeScript
  • JSON
  • CSS
  • SASS
  • LESS
  • GraphQL

Install

yarn global add @dschau/prettier-markdown

Example

Prettier Markdown

Usage

CLI

Command line usage is simple. All options (besides --dry, which will not write files to disk) are passed directly through to prettier.

prettier-markdown src/**/*.md README.md --single-quote --trailing-comma es5

Programatically

prettierMarkdown(files, prettierOpts = {}, programOpts = {})

Usage is fairly simple. An array of markdown files are passed, as well as any prettier options, and prettier is run on the specified files.

const path = require('path');
const { prettierMarkdown } = require('@dschau/prettier-markdown');

prettierMarkdown(
  ['README.md', 'blog/posts/2017-01-01-hello-world/index.md'].map(file =>
    path.join(process.cwd(), file)
  )
).then(files => {
  // array of files that were written
});

Advanced Functionality

Line highlights

Note that line highlights (e.g. like the below) are kept intact and the block is still prettified!

```javascript {1-2}
const a =   'b';
const b =   'c';

  alert('hello world');
```

Frontmatter

Frontmatter, i.e. in a Gastby blog post, is preserved as authored.

---
title: Hello World
tags:
  - Some Tag
  - Another Tag
---

```javascript
// this will be prettified
var a =    'a';

```

About

Parse code blocks in markdown files and run prettier on them

Topics

blocksclicodecodeblocksgatsbyjavascriptmarkdownnodeprettier

Resources

Readme
Activity

Stars

40 stars

Watchers

2 watching

Forks

2 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.