import Splash

struct SwiftBlock: BlockProcessor {

    static let blockId: ContentBlock = .swift

    let content: Content

    let results: PageGenerationResults

    let language: ContentLanguage

    private let swift = SyntaxHighlighter(format: HTMLOutputFormat())

    init(content: Content, results: PageGenerationResults, language: ContentLanguage) {
        self.content = content
        self.results = results
        self.language = language
    }

    func process(_ markdown: Substring) -> String {
        // Highlight swift code using Splash
        let code = markdown.between("```swift", and: "```").trimmed
        return "<pre><code>" + swift.highlight(code) + "</pre></code>"
    }
}
