Integrate Splash with Publish or Jekyll
masterFor web-based workflows:
- Publish: Use the official SplashPublishPlugin.
- Jekyll: Use the splashtag custom
{% splash %}tag for Liquid templates.
repository·master·Indexed 23 days ago
https://github.com/johnsundell/splashA fast, lightweight, and flexible Swift syntax highlighter. Available as a Swift library for generating HTML or attributed strings, or via command-line tools including SplashHTMLGen for HTML generation, SplashMarkdown for decorating Markdown files, SplashImageGen for creating code sample images on macOS, and SplashTokenizer for debugging code tokens.
For web-based workflows:
{% splash %} tag for Liquid templates.To use Splash in your own Swift Package Manager-powered tool, script, or server-side application, add it as a dependency in your Package.swift file.
.package(url: "https://github.com/JohnSundell/Splash", from: "0.1.0")You can install the built-in command line tools globally using make install after cloning the repository, or compile and move a specific tool manually.
To install all tools (SplashHTMLGen, SplashMarkdown, SplashImageGen, SplashTokenizer) to /usr/local/bin:
git clone https://github.com/johnsundell/splash.git
cd splash
make installTo install a single tool manually:
swift build -c release -Xswiftc -static-stdlib
install .build/release/SplashHTMLGen /usr/local/bin/SplashHTMLGen$ git clone https://github.com/johnsundell/splash.git
$ cd splash
$ make installTo highlight code programmatically, import Splash and use the SyntaxHighlighter class. You must provide an instance of an OutputFormat (such as HTMLOutputFormat) to the initializer.
Splash supports HTML and NSAttributedString out of the box, but you can implement the OutputFormat protocol to create custom formats.
import Splash
let highlighter = SyntaxHighlighter(format: HTMLOutputFormat())
let html = highlighter.highlight("func hello() -> String")The SplashMarkdown tool iterates through all code blocks in a Markdown file and converts them into Splash-highlighted HTML.
To skip highlighting for a specific code block, add no-highlight to the opening backticks (e.g., ```no-highlight).
Example usage:
$ SplashMarkdown ~/Documents/Article.mdThe SplashHTMLGen command line tool converts Swift code into an HTML string. It assigns CSS classes to tokens rather than hardcoding colors.
To use the output, wrap the generated HTML in <pre><code> tags and link a CSS file that defines the styles for the assigned classes (e.g., .keyword, .type).
Example usage:
$ SplashHTMLGen "func hello(world: String) -> Int"The SplashTokenizer tool is a debugging utility that outputs the individual components (tokens) of a string of Swift code, excluding whitespace. This is useful for seeing how Splash breaks down code.
$ SplashTokenizer "func hello(world: String) -> Int"The SplashImageGen tool converts Swift code into an image file. It works by generating an NSAttributedString and drawing it into a graphics context.
Note: This tool is currently only available on macOS.
Example usage:
$ SplashImageGen "func hello(world: String) -> Int" "MyImage.png"The SplashImageGen command-line tool generates syntax-highlighted images of code snippets on macOS. It requires two positional arguments: the source code string and the output file path.
Required Arguments:
Optional Flags:
-p: The amount of padding (in pixels) to apply around the code.-f: A path to a specific font file to use for rendering.-s: The text size to use for rendering.The SplashTokenizer command-line tool takes a single string argument representing the code you want to tokenize. It uses the SyntaxHighlighter with a TokenizerOutputFormat to output the tokenized representation of the input string to standard output.
Usage:
splash-tokenizer "your code string here"Note: Ensure the code string is passed as a single argument. If no argument is provided, the tool will print a warning and exit.
The Splash command-line tool accepts a single argument: the path to a Markdown file. It reads the file content and outputs the decorated Markdown string (with syntax highlighting markup) to standard output.
To use it, provide the path to your Markdown file as the first argument. The tool supports tilde (~) expansion for home directory paths.
The SplashHTMLGen command-line tool takes a string of code as its first argument and outputs the corresponding HTML syntax-highlighted string to standard output. It uses the HTMLOutputFormat to wrap the highlighted code in appropriate HTML tags.
Usage:
SplashHTMLGen "your code here"If no argument is provided, the tool will print a warning and exit with status code 1.