31 lines
1.1 KiB
Swift
31 lines
1.1 KiB
Swift
|
//
|
||
|
// GemtextToHTMLIntentHandler.swift
|
||
|
// GeminiIntents
|
||
|
//
|
||
|
// Created by Shadowfacts on 10/1/21.
|
||
|
//
|
||
|
|
||
|
import Intents
|
||
|
import GeminiFormat
|
||
|
|
||
|
class GemtextToHTMLIntentHandler: NSObject, GemtextToHTMLIntentHandling {
|
||
|
|
||
|
func handle(intent: GemtextToHTMLIntent, completion: @escaping (GemtextToHTMLIntentResponse) -> Void) {
|
||
|
guard let response = intent.response,
|
||
|
let text = response.body,
|
||
|
let url = response.url else {
|
||
|
completion(GemtextToHTMLIntentResponse(code: .failure, userActivity: nil))
|
||
|
return
|
||
|
}
|
||
|
let doc = GeminiParser.parse(text: text, baseURL: url)
|
||
|
let renderer = GeminiHTMLRenderer()
|
||
|
renderer.addLinkClass = false
|
||
|
renderer.addHeadingLineIDs = false
|
||
|
let html = renderer.renderDocumentToHTML(doc)
|
||
|
let intentResp = GemtextToHTMLIntentResponse(code: .success, userActivity: nil)
|
||
|
intentResp.html = INFile(data: html.data(using: .utf8)!, filename: "converted_gemtext.html", typeIdentifier: "public.html")
|
||
|
completion(intentResp)
|
||
|
}
|
||
|
|
||
|
}
|