Syntax highlight swift code

This commit is contained in:
Christoph Hagen
2022-08-18 08:49:01 +02:00
parent a444c51697
commit 8a264b141b
3 changed files with 31 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import Foundation
import Ink
import Splash
struct PageContentGenerator {
@@ -7,6 +8,8 @@ struct PageContentGenerator {
private let files: FileProcessor
private let swift = SyntaxHighlighter(format: HTMLOutputFormat())
init(factory: TemplateFactory, files: FileProcessor) {
self.factory = factory
self.files = files
@@ -31,8 +34,8 @@ struct PageContentGenerator {
}
let codeModifier = Modifier(target: .codeBlocks) { html, markdown in
if markdown.starts(with: "```swift") {
#warning("Syntax highlight swift code")
return html
let code = markdown.between("```swift", and: "```").trimmed
return "<pre><code>" + swift.highlight(code) + "</pre></code>"
}
hasCodeContent = true
return html