+
30
-

有没有可以对python代码格式化的js插件或库?

有没有可以对python代码格式化的js插件或库?

网友回复

+
27
-

有2种js可实现:

800_auto

1、安装 prettier 和 prettier-plugin-python:

npm install prettier @prettier/plugin-python

const prettier = require("prettier");
const code = `
def hello_world():
    print("Hello, world!")
`;

const formattedCode = prettier.format(code, {
  parser: "python",
  plugins: ["@prettier/plugin-python"],
});

console.log(formattedCode);

2、pyodide插件

<!DOCTYPE html>
<html>
<head>
  <title>Pyodide Black Formatter</title>
  <script src="https://cdn.jsdelivr.net/pyodide/v0.23.4/full/pyodide.js"></script>
</head>
<body...

点击查看剩余70%

我知道答案,我要回答