Splash

所属分类:博客
开发工具:Swift
文件大小:273KB
下载次数:0
上传日期:2022-08-06 01:09:43
上 传 者sh-1993
说明:  一款快速、轻量级和灵活的Swift语法荧光笔,适用于博客、工具和娱乐!
(A fast, lightweight and flexible Swift syntax highlighter for blogs, tools and fun!)

文件列表:
.swiftlint.yml (138, 2022-06-09)
.travis.yml (182, 2022-06-09)
CODE_OF_CONDUCT.md (3403, 2022-06-09)
CONTRIBUTING.md (10338, 2022-06-09)
Examples (0, 2022-06-09)
Examples\sundellsColors.css (876, 2022-06-09)
Images (0, 2022-06-09)
Images\Code.png (13086, 2022-06-09)
Images\Logo.png (218817, 2022-06-09)
LICENSE (1069, 2022-06-09)
Makefile (331, 2022-06-09)
Package.swift (1162, 2022-06-09)
Sources (0, 2022-06-09)
Sources\Splash (0, 2022-06-09)
Sources\Splash\Extensions (0, 2022-06-09)
Sources\Splash\Extensions\CharacterSet (0, 2022-06-09)
Sources\Splash\Extensions\CharacterSet\CharacterSet+Contains.swift (335, 2022-06-09)
Sources\Splash\Extensions\Equatable (0, 2022-06-09)
Sources\Splash\Extensions\Equatable\Equatable+AnyOf.swift (356, 2022-06-09)
Sources\Splash\Extensions\Int (0, 2022-06-09)
Sources\Splash\Extensions\Int\Int+IsOdd.swift (193, 2022-06-09)
Sources\Splash\Extensions\Sequence (0, 2022-06-09)
Sources\Splash\Extensions\Sequence\Sequence+AnyOf.swift (517, 2022-06-09)
Sources\Splash\Extensions\Sequence\Sequence+Occurrences.swift (341, 2022-06-09)
Sources\Splash\Extensions\Strings (0, 2022-06-09)
Sources\Splash\Extensions\Strings\String+HTMLEntities.swift (522, 2022-06-09)
Sources\Splash\Extensions\Strings\String+IsNumber.swift (192, 2022-06-09)
Sources\Splash\Extensions\Strings\String+PrefixChecking.swift (521, 2022-06-09)
Sources\Splash\Extensions\Strings\String+Removing.swift (256, 2022-06-09)
Sources\Splash\Extensions\Strings\Substring+HasSuffix.swift (318, 2022-06-09)
Sources\Splash\Grammar (0, 2022-06-09)
Sources\Splash\Grammar\Grammar.swift (1564, 2022-06-09)
Sources\Splash\Grammar\SwiftGrammar.swift (21879, 2022-06-09)
Sources\Splash\Output (0, 2022-06-09)
Sources\Splash\Output\AttributedStringOutputFormat.swift (1883, 2022-06-09)
Sources\Splash\Output\HTMLOutputFormat.swift (2560, 2022-06-09)
Sources\Splash\Output\MarkdownDecorator.swift (1896, 2022-06-09)
... ...

Splash

Swift Package Manager Mac + Linux Twitter: @johnsundell

Welcome to **Splash** - a fast, lightweight and flexible Swift syntax highlighter. It can be used to generate code sample HTML for a blog post, to turn a string of Swift code into a fully syntax highlighted image, or to build custom developer tools. It's used to highlight all articles on [swiftbysundell.com](https://swiftbysundell.com). ## Usage Splash can be used either as a library in your own Swift Package Manager-powered tool or script, or by using one of the four built-in command line tools that act as frontends for the Splash library. ### On the web If you're using [Publish](https://github.com/JohnSundell/Publish), then there's an official plugin that makes it easy to integrate Splash into your website: ‘‰ [SplashPublishPlugin](https://github.com/JohnSundell/SplashPublishPlugin) If you're using Jekyll, there's also a custom ```{% splash %}``` tag available for the Liquid templating language. ‘‰ [splashtag](https://github.com/mannberg/splashtag) ### – On the command line The easiest way to get started building things with Splash is to use one of the four built-in command line tools that each enable you to use Splash in different ways. #### SplashHTMLGen `SplashHTMLGen` uses Splash's HTML output format to generate an HTML string from Swift code. You simply pass it the code you want to highlight as an argument and HTML is returned as standard output. For example, if you call it like this: ``` $ SplashHTMLGen "func hello(world: String) -> Int" ``` You'll get the following output back: ```html func hello(world: String) -> Int ``` To be as flexible as possible, Splash doesn't hardcode any colors or other CSS attributes in the HTML it generates. Instead it simply assigns a CSS class to each token. For an example of a CSS file that can be used to style Splash-generated HTML, see [Examples/sundellsColors.css](https://github.com/JohnSundell/Splash/blob/master/Examples/sundellsColors.css). When rendering your outputted html, make sure to wrap your output code in the `
` and `` tags and properly link to your `.css` file. Like this:

```html


    Hello World
    


    
        func hello(world: String) -> Int
    
``` For more information about HTML generation with Splash and how to customize it, see `HTMLOutputFormat` [here](https://github.com/JohnSundell/Splash/blob/master/Sources/Splash/Output/HTMLOutputFormat.swift). #### SplashMarkdown `SplashMarkdown` builds on top of `SplashHTMLGen` to enable easy Splash decoration of any Markdown file. Pass it a path to a Markdown file, and it will iterate through all code blocks within that file and convert them into Splash-highlighted HTML. Just like the HTML generated by `SplashHTMLGen` itself, a CSS file should also be added to any page serving the processed Markdown, since Splash only adds CSS classes to tokens ” rather than hardcoding styles inline. See the above `SplashHTMLGen` documentation for more information. Heres an example call to decorate a Markdown file at the path `~/Documents/Article.md`: ``` $ SplashMarkdown ~/Documents/Article.md ``` The decorated Markdown will be returned as standard output. Highlighting can be skipped for any code block by adding `no-highlight` next to the blocks opening row of backticks ” like this: *```no-highlight*. #### SplashImageGen `SplashImageGen` uses Splash to generate an `NSAttributedString` from Swift code, then draws that attributed string into a graphics context to turn it into an image, which is then written to disk. For example, if you call it like this: ``` $ SplashImageGen "func hello(world: String) -> Int" "MyImage.png" ``` The following image will be generated (and written to disk as `MyImage.png`): Code sample *`SplashImageGen` is currently only available on macOS.* #### SplashTokenizer The final built-in command line tool, `SplashTokenizer`, is mostly useful as a debugging tool when working on Splash - but can also be interesting to use in order to see how Splash breaks down code into tokens. Given a string of Swift code, it simply outputs all of its components (excluding whitespaces). So if you call it like this: ``` $ SplashTokenizer "func hello(world: String) -> Int" ``` You'll get the following standard output back: ``` Keyword token: func Plain text: hello(world: Type token: String Plain text: ) Plain text: -> Type token: Int ``` ### “ As a package To include Splash in your own script or Swift package, [add it as a dependency](#installation) and use the `SyntaxHighlighter` class combined with your output format of choice to highlight a string of code: ```swift import Splash let highlighter = SyntaxHighlighter(format: HTMLOutputFormat()) let html = highlighter.highlight("func hello() -> String") ``` Splash ships with two built-in output formats - HTML and `NSAttributedString`, but you can also easily add your own by implementing the `OutputFormat` protocol. ## Installation Splash is distributed as a Swift package, making it easy to install for use in scripts, developer tools, server-side applications, or to use its built-in command line tools. Splash supports both macOS and Linux. *Before you begin, make sure that you have a Swift 5.2-compatible toolchain installed (for example Xcode 11.5 or later if you're on a Mac).* ### “ As a package To install Splash for use in a Swift Package Manager-powered tool or server-side application, add Splash as a dependency to your `Package.swift` file. For more information, please see the [Swift Package Manager documentation](https://github.com/apple/swift-package-manager/tree/master/Documentation). ``` .package(url: "https://github.com/JohnSundell/Splash", from: "0.1.0") ``` ### Command line tools If you want to use Splash through one of its built-in command line tools, start by cloning the repo to your local machine: ``` $ git clone https://github.com/johnsundell/splash.git $ cd splash ``` To run a tool without installing it, you can use the Swift Package Manager's `run` command, like this: ``` $ swift run SplashHTMLGen "func hello(world: String) -> Int" ``` To install all four command line tools globally on your system, use Make: ``` $ make install ``` That will install the following four tools in your `/usr/local/bin` folder: ``` SplashHTMLGen SplashMarkdown SplashImageGen SplashTokenizer ``` If you only wish to install one of these, compile it and then move it to `/usr/local/bin`, like this: ``` $ swift build -c release -Xswiftc -static-stdlib $ install .build/release/SplashHTMLGen /usr/local/bin/SplashHTMLGen ``` ## Contributions and support Splash is developed completely in the open, and your contributions are more than welcome. It's still a very new project, so I'm sure there are bugs to be found and improvements to be made - and hopefully we can work on those together as a community. This project does not come with GitHub Issues-based support, and users are instead encouraged to become active participants in its continued development ” by fixing any bugs that they encounter, or by improving the documentation wherever it's found to be lacking. To read more about suggested workflows when contributing to Splash, how to report bugs and feature requests, as well as technical details and an architectural overview - check out the [Contributing Guide](https://github.com/JohnSundell/Splash/blob/master/CONTRIBUTING.md). ## Hope you enjoy using Splash! I had a lot of fun building Splash, and I'm looking forward to continue working on it in the open together with you! I hope you'll like it and that you'll find it useful. Let me know what you think on [Twitter](https://twitter.com/johnsundell)

近期下载者

相关文件


收藏者