跳转到主要内容

Mdformat插件,用于格式化Python代码块

项目描述

mdformat-ruff

pre-commit.ci status github/workflow

github/downloads github/downloads/latest github/issues github/issues-closed github/issues-pr github/issues-pr-closed github/discussions github/milestones github/forks github/stars github/watchers github/contributors github/commit-activity github/last-commit github/release-date

github/license github/languages github/languages/top github/directory-file-count github/code-size github/repo-size github/v

pypi/status pypi/v pypi/downloads pypi/format pypi/implementation pypi/pyversions

Mdformat插件,用于格式化Python代码块

描述

mdformat-ruff 是一个 mdformat 插件,用于使用 ruff 格式化 mdformat 的 Python 代码块。

用法

使用以下命令安装

pip install mdformat-ruff

您可以将 ruff 依赖项固定,以确保格式化稳定性

pip install mdformat-ruff ruff==22.1.0

在命令行上使用 mdformat 时,安装后将会自动启用 ruff 格式化。

在使用 mdformat Python API 时,需要显式启用 Python 代码的格式化

import mdformat

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

作为 pre-commit 钩子使用

将以下内容添加到您的 .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-ruff
          - ruff==22.1.0 # Pinning ruff here is optional

项目详情


下载文件

根据您的平台下载文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源代码分发

mdformat_ruff-0.1.3.tar.gz (3.4 kB 查看散列)

上传时间 源码

构建分发包

mdformat_ruff-0.1.3-py3-none-any.whl (3.9 kB 查看散列)

上传时间 Python 3

由以下支持