6dff287cd2
This change makes Splash merge tokens of the same type (along with any whitespace in between them) when generating HTML. The result is much smaller HTML, since less tags have to be used to produce the same result. This was most obvious with comment highlighting, for example, this comment: ``` // Hello I’m a comment ``` Would generate 5 different <span class="comment"></span> elements. Now it’s just one!
26 lines
976 B
Swift
26 lines
976 B
Swift
/**
|
|
* Splash
|
|
* Copyright (c) John Sundell 2018
|
|
* MIT license - see LICENSE.md
|
|
*/
|
|
|
|
import Foundation
|
|
|
|
/// Protocol used to define a builder for a highlighted string that's
|
|
/// returned as output from `SyntaxHighlighter`. Each builder defines
|
|
/// its own output type through the `Output` associated type, and can
|
|
/// add the various tokens and other text found in the highlighted code
|
|
/// in whichever fashion it wants.
|
|
public protocol OutputBuilder {
|
|
/// The type of output that this builder produces
|
|
associatedtype Output
|
|
/// Add a token with a given type to the builder
|
|
mutating func addToken(_ token: String, ofType type: TokenType)
|
|
/// Add some plain text, without any formatting, to the builder
|
|
mutating func addPlainText(_ text: String)
|
|
/// Add some whitespace to the builder
|
|
mutating func addWhitespace(_ whitespace: String)
|
|
/// Build the final output based on the builder's current state
|
|
mutating func build() -> Output
|
|
}
|