ramsey/pygments

Pygments(Python语法高亮工具)的PHP包装器,源自kzykhys/pygments。

资助包维护!
ramsey

2.0.2 2021-03-07 19:15 UTC

This package is auto-updated.

Last update: 2024-09-01 21:17:13 UTC


README

Pygments(Python语法高亮工具)的PHP包装器。

Source Code Download Package PHP Programming Language Read License Build Status Codecov Code Coverage Psalm Type Coverage

关于

ramsey/pygments 是 Pygments(Python语法高亮工具)的 PHP 包装器,源自 Pygments.php 项目。

本项目遵循 行为准则。参与本项目及其社区时,您应遵守此准则。

安装

使用 Composer 将此包作为依赖项安装。

composer require ramsey/pygments

要求

  • PHP 7.4 或更高版本(包括 PHP 8)
  • Python
  • Pygments(《pip install Pygments》)

支持的 Python 和 Pygments 版本

用法

高亮源代码

use Ramsey\Pygments\Pygments;

$pygments = new Pygments();
$html = $pygments->highlight(file_get_contents('index.php'), 'php', 'html');
$console = $pygments->highlight('package main', 'go', 'ansi');

生成 CSS

use Ramsey\Pygments\Pygments;

$pygments = new Pygments();
$css = $pygments->getCss('monokai');
$prefixedCss = $pygments->getCss('default', '.syntax');

猜测词法分析器名称

use Ramsey\Pygments\Pygments;

$pygments = new Pygments();
$pygments->guessLexer('foo.rb'); // ruby

获取词法分析器/格式化器/样式的列表

use Ramsey\Pygments\Pygments;

$pygments = new Pygments();
$pygments->getLexers()
$pygments->getFormatters();
$pygments->getStyles();

设置自定义的 pygmentize 路径

use Ramsey\Pygments\Pygments;

$pygments = new Pygments('/path/to/pygmentize');

贡献

欢迎贡献!要贡献,请熟悉 CONTRIBUTING.md

协调披露

保护用户信息的安全和稳定是首要任务,我们欢迎外部安全研究人员做出贡献。如果您认为您已在此存储库维护的软件中发现了一个安全问题,请阅读 SECURITY.md 以获取提交漏洞报告的说明。

版权和许可证

ramsey/pygments 库的版权 © Ben Ramsey,并按 MIT 许可证(MIT)的条款使用。

ramsey/pygments 是 Pygments.php 的分支。Pygments.php 库的版权 © Kazuyuki Hayashi,并按 MIT 许可证(MIT)的条款使用。

请参阅 LICENSE 获取更多信息。