26 lines
811 B
Swift
26 lines
811 B
Swift
import Splash
|
|
|
|
struct PageCodeProcessor {
|
|
|
|
private let codeHighlightFooter = "<script>hljs.highlightAll();</script>"
|
|
|
|
private let swift = SyntaxHighlighter(format: HTMLOutputFormat())
|
|
|
|
let results: PageGenerationResults
|
|
|
|
init(results: PageGenerationResults) {
|
|
self.results = results
|
|
}
|
|
|
|
func process(_ html: String, markdown: Substring) -> String {
|
|
guard markdown.starts(with: "```swift") else {
|
|
results.require(header: .codeHightlighting)
|
|
results.require(footer: codeHighlightFooter)
|
|
return html // Just use normal code highlighting
|
|
}
|
|
// Highlight swift code using Splash
|
|
let code = markdown.between("```swift", and: "```").trimmed
|
|
return "<pre><code>" + swift.highlight(code) + "</pre></code>"
|
|
}
|
|
}
|