ReadKeep/readeck/Utils/StringExtensions.swift
Ilyas Hallak 09f1ddea58 Add text-to-speech functionality
- Add TTSManager and SpeechQueue utilities
- Create AddTextToSpeechQueueUseCase and ReadBookmarkUseCase
- Add SpeechPlayer UI components (GlobalPlayerContainerView, SpeechPlayerView, SpeechPlayerViewModel)
- Update BookmarkDetailView and BookmarkDetailViewModel for TTS integration
- Add audio background mode to Info.plist
- Update PhoneTabView for TTS controls
- Add StringExtensions for text processing
- Add StringExtensionsTests for testing
- Update Localizable.xcstrings with new strings
- Add VS Code settings
2025-07-09 22:31:17 +02:00

29 lines
1.1 KiB
Swift

import Foundation
extension String {
var stripHTML: String {
// Entfernt HTML-Tags und decodiert HTML-Entities
let attributedString = try? NSAttributedString(
data: Data(utf8),
options: [
.documentType: NSAttributedString.DocumentType.html,
.characterEncoding: String.Encoding.utf8.rawValue
],
documentAttributes: nil
)
return attributedString?.string ?? self
}
var stripHTMLSimple: String {
// Einfache Regex-basierte HTML-Entfernung
return self.replacingOccurrences(of: "<[^>]+>", with: "", options: .regularExpression, range: nil)
.replacingOccurrences(of: "&nbsp;", with: " ")
.replacingOccurrences(of: "&amp;", with: "&")
.replacingOccurrences(of: "&lt;", with: "<")
.replacingOccurrences(of: "&gt;", with: ">")
.replacingOccurrences(of: "&quot;", with: "\"")
.replacingOccurrences(of: "&#39;", with: "'")
.trimmingCharacters(in: .whitespacesAndNewlines)
}
}