https://github.com/nerdsupremacist/syntax-highlight-publish-plugin
Plugin to add syntax highlighting (for multiple languages) to your Publish Site, with the least amount of effort.
https://github.com/nerdsupremacist/syntax-highlight-publish-plugin
plugin publish publish-plugin splash syntax syntax-highlighting textmate
Last synced: 3 months ago
JSON representation
Plugin to add syntax highlighting (for multiple languages) to your Publish Site, with the least amount of effort.
- Host: GitHub
- URL: https://github.com/nerdsupremacist/syntax-highlight-publish-plugin
- Owner: nerdsupremacist
- License: mit
- Created: 2021-01-14T18:43:24.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-02-07T22:11:29.000Z (over 4 years ago)
- Last Synced: 2024-09-16T17:49:22.100Z (8 months ago)
- Topics: plugin, publish, publish-plugin, splash, syntax, syntax-highlighting, textmate
- Language: Swift
- Homepage:
- Size: 40 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Syntax Highlight Publish Plugin
Plugin to add syntax highlighting (for multiple languages) to your Publish Site, with the least amount of effort.
It currently supports defining Grammars with:
- [Syntax](https://github.com/nerdsupremacist/Syntax): SwiftUI-like parser builder DSL
- [TextMate](https://macromates.com/manual/en/language_grammars) Grammars
- [Splash](https://github.com/JohnSundell/Splash) Grammars## Installation
### Swift Package ManagerYou can install SyntaxHighlightPublishPlugin via [Swift Package Manager](https://swift.org/package-manager/) by adding the following line to your `Package.swift`:
```swift
import PackageDescriptionlet package = Package(
[...]
dependencies: [
.package(url: "https://github.com/nerdsupremacist/syntax-highlight-publish-plugin.git", from: "0.1.0")
]
)
```## Usage
You have three options to add new Grammars to your site:
- Use Syntax
- Use TextMate
- Use SplashYou are allowed to add as many grammars as you like. And the plugin will choose the correct grammar depending on the language in each code block:
```swift
try MyPublishSite().publish(using: [
...
// use plugin and include all the grammars that you want to use (note: we only ship this plugin with Swift)
.installPlugin(.syntaxHighlighting(.swift, .kotlin, .scala, .java, .json, .graphql)),
])
```
### Syntax
[Syntax](https://github.com/nerdsupremacist/Syntax) is a SwiftUI-like parser builder DSL that you can use to define your custom Grammar structurally.
For example this is how you would write a Parser that can parse the output of FizzBuzz:```swift
enum FizzBuzzValue {
case number(Int)
case fizz
case buzz
case fizzBuzz
}struct FizzBuzzParser: Parser {
var body: AnyParser<[FizzBuzzValue]> {
Repeat {
Either {
IntLiteral().map { FizzBuzzValue.number($0) }Word("FizzBuzz").map(to: FizzBuzzValue.fizzBuzz)
Word("Fizz").map(to: FizzBuzzValue.fizz)
Word("Buzz").map(to: FizzBuzzValue.buzz)
}
}
}
}
```And in order to add it to our site we use the Parser to create a `Grammar`:
```swift
import SyntaxHighlightPublishPluginextension Grammar {
// define Fizz Buzz Grammar
static let fizzBuzz = Grammar(name: "FizzBuzz") {
FizzBuzzParser()
}
}try MyPublishSite().publish(using: [
...
// use plugin and include your Grammar
.installPlugin(.syntaxHighlighting(.fizzbuzz)),
])
```### TextMate
Most programming languages have a TextMate definition out there so that you don't have to put in the work in coding it all down.
You can simply search for the VS Code plugin for your language of choice and in the repo you will most likely find a .tmLanguage file.
That's all you need to add support for that language on your site.Let's say for that you want to add support for Kotlin:
```swift
import SyntaxHighlightPublishPluginextension Grammar {
static let kotlin = try! Grammar(textMateFile: URL(fileURLWithPath: "/path/to/Kotlin.tmLanguage"))
}try MyPublishSite().publish(using: [
...
.installPlugin(.syntaxHighlighting(.kotlin)),
])
```
### Splash
If you were already using [Splash](https://github.com/JohnSundell/Splash) on your site before and put in the work to add a custom Splash Grammar. No problem. We can use that too:
```swift
import SyntaxHighlightPublishPluginextension Grammar {
static let myLanguage = Grammar(name: "MyLanguage", grammar: MyGrammar())
}try MyPublishSite().publish(using: [
...
.installPlugin(.syntaxHighlighting(.myLanguage)),
])
```## Contributions
Contributions are welcome and encouraged!## License
SyntaxHighlightPublishPlugin is available under the MIT license. See the LICENSE file for more info.