Bark/NotificationServiceExtension/Processor/MarkdownProcessor.swift
2025-12-02 10:54:53 +08:00

43 lines
1.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// MarkdownProcessor.swift
// NotificationServiceExtension
//
// Created by huangfeng on 11/21/25.
// Copyright © 2025 Fin. All rights reserved.
//
import UIKit
class MarkdownProcessor: NotificationContentProcessor {
func process(identifier: String, content bestAttemptContent: UNMutableNotificationContent) async throws -> UNMutableNotificationContent {
let userInfo = bestAttemptContent.userInfo
guard let markdown = userInfo["markdown"] as? String, !markdown.isEmpty else {
return bestAttemptContent
}
let config = MarkdownParser.Configuration(
baseFont: UIFont.preferredFont(forTextStyle: .body),
baseColor: UIColor.white,
linkColor: UIColor.systemBlue,
codeTextColor: UIColor.black,
codeBackgroundColor: UIColor.gray,
codeBlockTextColor: UIColor.black,
quoteColor: UIColor.systemGray
)
let body = MarkdownParser(configuration: config)
.parse(markdown)
.string
// body \n\n
.replacingOccurrences(of: "\n\n+", with: "\n", options: .regularExpression)
bestAttemptContent.body = body
/// APS , Porgressor 使
var aps = userInfo["aps"] as? [String: Any] ?? [:]
var alert = aps["alert"] as? [String: Any] ?? [:]
alert["body"] = body
aps["alert"] = alert
bestAttemptContent.userInfo["aps"] = aps
return bestAttemptContent
}
}