Giter Club home page Giter Club logo

prettier-markdown's Introduction

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';

```

prettier-markdown's People

Contributors

dschau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

prettier-markdown's Issues

It adds a newline to the end of code block every time

```js
client.sendText(userId, 'Hello World').then(() => {
  console.log('sent');
});
```

Becomes

```js
client.sendText(userId, 'Hello World').then(() => {
  console.log('sent');
});

```

And next time:

```js
client.sendText(userId, 'Hello World').then(() => {
  console.log('sent');
});


```

Ignore node_modules by default

If I want to use prettier-markdown "packages/**/*.md" I just can't since it's the cli is not ignoring node_modules by default (in practise I should probably be able to, but a module I use have a malformed js snippet in its readme).

Indicate which file is failing

Currently, if a file fail when you use a glob, you don't know which file is responsible for the failure.

prettier-markdown "packages/preset-react-app/**/*.md"
✖ SyntaxError: Unexpected token, expected , (3:13)
  1 | {
  2 |   ...
> 3 |   "phenomic": {
    |             ^
  4 |     "presets": [
  5 |       "@phenomic/preset-react-app"
  6 |     ]

It would be nice to have the filename :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.