SwiftPygments Publish 插件

一个用于 Publish 的 Pygments 插件,用于高亮代码。

Pygments 是一个用 Python 编写的语法高亮工具,支持多种语言。

要求

SwiftPygments 使用 PythonKit 与 Pygments 交互。

安装

  1. 如果你的系统上没有安装 Python,请安装。
  2. 如果你的系统上没有安装 Pygments,请安装。
$ pip3 install pygments
  1. SwiftPygmentsPublishPlugin 添加到你的 package 中。
let package = Package(
    ...
    dependencies: [
    .package(url: "https://github.com/Ze0nC/SwiftPygmentsPublishPlugin", .branch("master"))
    ],
    targets: [
        .target(
            ...
            dependencies: [
                ...
                "SwiftPygmentsPublishPlugin"
            ]
        )
    ]
    ...
)

用法

  1. .pygments() 添加到你的构建流程中。
import SwiftPygmentsPublishPlugin
...
try MyWebsite().publish(using: [
    .installPlugin(.pygments()),
    ...
    .addMarkdownFiles(),
    ...
])
  1. 在你的 css 文件中添加一个 Pygments 颜色方案。你可以在网上找到很多。

  2. 编写高亮的代码!

在你的 markdown 文件中,在 ``` 后面指定语言以获得正确的代码高亮。

```swift
let str = "This is Swift code."
print(str)
```

指定代码为 python

```python
str = "This is also Swift code."
print(str)
```

如果没有指定语言,将默认使用 swift 语法。

```
let str = "This is also Swift code."
print(str)
```

注意

这个插件将会高亮所有代码块,但不包括行内代码。

享受你高亮显示的网站吧!

鸣谢

感谢 John Sundell (@johnsundell) 创建了 Publish 和 SplashPublishPlugin

许可

MIT 许可证