@acarl005/cli-highlight 中文文档教程

发布于 7年前 浏览 20 项目主页 更新于 3年前

cli-highlight

终端中的语法高亮

版本 下载”></a> 
  <a href=构建状态 依赖项 节点版本 许可证

Example

示例Test Output

CLI Usage

Output a file

$ highlight package.json

另一个带有管道的程序的颜色输出。 示例:记录 SQL 查询的数据库迁移脚本

$ db-migrate --dry-run | highlight

命令行选项:

Usage: highlight [options] [file]

Outputs a file or STDIN input with syntax highlighting

Options:
  --language, -l  Set the langugage explicitely
                  If omitted will try to auto-detect
  --theme, -t     Use a theme defined in a JSON file
  --version, -v   Show version number                                   [boolean]
  --help, -h      Show help                                             [boolean]

Programmatic Usage

您可以以编程方式使用此模块来突出显示 Node 应用程序的日志。 示例:

const highlight = require('cli-highlight').highlight
const Sequelize = require('sequelize')

const db = new Sequelize(process.env.DB, {
  logging(log) {
    console.log(highlight(log, {language: 'sql', ignoreIllegals: true}))
  }
})

详细的 API 文档可以在这里找到。

Themes

您可以在 JSON 文件中编写自己的主题,并使用 --theme 传递它。 键必须是 highlight.js CSS 类名之一 并且该值必须是一个或一组 Chalk 样式 以应用于该令牌。

{
  "keyword": "blue",
  "built_in": ["cyan", "dim"],
  "string": "red"
}

该主题结合了默认主题。 默认主题仍然没有很多颜色或针对多种语言进行优化,欢迎 PR!

Supported Languages

理论上highlight.js的所有语言都是支持的——我就是没适应 默认主题并为所有语言编写测试。 我的主要用例是 SQL,因此得到了很好的支持。

Contributing

该模块是用 TypeScript 编写的,可以用 npm run build 编译。 npm run watch 在监视模式下启动 tsc。 测试是用 mocha 编写的。

通过为默认主题中的标记添加更多颜色并编写更多测试来改进语言支持。

cli-highlight

Syntax highlighting in your terminal

Version Downloads Build Status Dependencies Node Version License

Example

Example Test Output

CLI Usage

Output a file

$ highlight package.json

Color output of another program with piping. Example: A database migration script that logs SQL Queries

$ db-migrate --dry-run | highlight

Command line options:

Usage: highlight [options] [file]

Outputs a file or STDIN input with syntax highlighting

Options:
  --language, -l  Set the langugage explicitely
                  If omitted will try to auto-detect
  --theme, -t     Use a theme defined in a JSON file
  --version, -v   Show version number                                   [boolean]
  --help, -h      Show help                                             [boolean]

Programmatic Usage

You can use this module programmatically to highlight logs of your Node app. Example:

const highlight = require('cli-highlight').highlight
const Sequelize = require('sequelize')

const db = new Sequelize(process.env.DB, {
  logging(log) {
    console.log(highlight(log, {language: 'sql', ignoreIllegals: true}))
  }
})

Detailed API documenation can be found here.

Themes

You can write your own theme in a JSON file and pass it with --theme. The key must be one of the highlight.js CSS class names and the value must be one or an array of Chalk styles to be applied to that token.

{
  "keyword": "blue",
  "built_in": ["cyan", "dim"],
  "string": "red"
}

The theme is combined with the default theme. The default theme is still not colored a lot or optimized for many languages, PRs welcome!

Supported Languages

In theory, all languages of highlight.js are supported - I just did not adapt the default theme and wrote tests for all languages yet. My primary use case was SQL so that is supported well.

Contributing

The module is written in TypeScript and can be compiled with npm run build. npm run watch starts tsc in watch mode. Tests are written with mocha.

Improving language support is done by adding more colors to the tokens in the default theme and writing more tests.

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文