SwiftPygments Plugin for Publish
ChenZhijin
.com

SwiftPygments Plugin for Publish

SwiftPygments Plugin for Publish

Splash and its official plugin are great tools for highlighting swift syntax in Publish.

However, some people write not only in Swift, but also in many other languages. That’s when SwiftPygmentsPublishPlugin will be helpful.

SwiftPygmentsPublishPlugin

It is a Pygments plugin for Publish to highlight code.

Pygments is a syntax highlighting tool made in Python that supports many languages.

Requirements

SwiftPygments uses PythonKit to interact with Pygments.

Installation

  1. Install Python if you don’t have it on your system.
  2. Install Pygments if you don’t have it on your system.
1
$ pip3 install pygments
  1. Add SwiftPygmentsPublishPlugin to your package.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
let package = Package(
    ...
    dependencies: [
    .package(url: "https://github.com/Ze0nC/SwiftPygmentsPublishPlugin", .branch("master"))
    ],
    targets: [
        .target(
            ...
            dependencies: [
                ...
                "SwiftPygmentsPublishPlugin"
            ]
        )
    ]
    ...
)

Usage

  1. Add .pygments() to your build pipeline.

SwiftPygmentsPublishPlugin must be installed before addMarkdownFiles()

1
2
3
4
5
6
7
8
import SwiftPygmentsPublishPlugin
...
try MyWebsite().publish(using: [
    .installPlugin(.pygments()),
    ...
    .addMarkdownFiles(),
    ...
])
  1. Add a pygments color scheme in your css file. You can find many on internet.
  2. Write highlighted codes!

In your markdown file, specify language after backticks to get correct highlight.

Swift

1
2
3
4
```swift
let str = "This is Swift code."
print(str)
```

Gives

1
2
let str = "This is Swift code."
print(str)

Python

1
2
3
4
```python
str = "This is also Swift code."
print(str)
```

Gives

1
2
str = "This is also Swift code."
print(str)

Blank

If no language is specified, swift syntax will be used as default.

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

Even LaTeX

1
2
3
4
5
6
```latex
\documentclass[12pt]{article}
\begin{document}
This is \LaTeX
\end{document}
```

Gives

1
2
3
4
\documentclass[12pt]{article}
\begin{document}
This is \LaTeX
\end{document}

Note

This plugin will highlight all code block but not inline codes.

Enjoy your highlighted sites!

Acknowledgement

Thanks to John Sundell (@johnsundell) for creating Publish and SplashPublishPlugin

Tagged with: