Giter VIP home page Giter VIP logo

mdformat-black's Introduction

Build Status PyPI version

mdformat-black

Mdformat plugin to Blacken Python code blocks

Description

mdformat-black is an mdformat plugin that makes mdformat format Python code blocks with Black.

Usage

Install with:

pip install mdformat-black

You may pin Black dependency for formatting stability:

pip install mdformat-black black==22.1.0

When using mdformat on the command line, Black formatting will be automatically enabled after install.

When using mdformat Python API, code formatting for Python will have to be enabled explicitly:

import mdformat

unformatted = "```python\n'''black converts quotes'''\n```\n"
formatted = mdformat.text(unformatted, codeformatters={"python"})
assert formatted == '```python\n"""black converts quotes"""\n```\n'

Usage as a pre-commit hook

Add the following to your .pre-commit-config.yaml:

- repo: https://github.com/executablebooks/mdformat
  rev: 0.7.13  # Use the ref you want to point at
  hooks:
    - id: mdformat
      additional_dependencies:
        - mdformat-black
        - black==22.1.0  # Pinning black here is optional

mdformat-black's People

Contributors

hukkin avatar hukkinj1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

freed-wu

mdformat-black's Issues

How to configure within pre-commit

Hello,
I was testing this extension and it seems that it does not follow the Black configuration from pyproject.toml which is

[tool.black]
line-length = 120
skip-magic-trailing-comma = true

the pre-commit configuration is:

  - repo: https://github.com/executablebooks/mdformat
    rev: 0.7.7
    hooks:
      - id: mdformat
        additional_dependencies:
          - mdformat-gfm
          - mdformat-black
          - mdformat_frontmatter

see sample here: Lightning-AI/pytorch-lightning#8673 (comment)

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.