Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Modules/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let package = Package(
.library(name: "NotificationServiceExtensionCore", targets: ["NotificationServiceExtensionCore"]),
.library(name: "ShareExtensionCore", targets: ["ShareExtensionCore"]),
.library(name: "SFHFKeychainUtils", targets: ["SFHFKeychainUtils"]),
.library(name: "Support", targets: ["Support"]),
.library(name: "WordPressFlux", targets: ["WordPressFlux"]),
.library(name: "WordPressShared", targets: ["WordPressShared"]),
.library(name: "WordPressUI", targets: ["WordPressUI"]),
Expand Down Expand Up @@ -52,8 +53,8 @@ let package = Package(
.package(url: "https://github.com/wordpress-mobile/NSURL-IDN", revision: "b34794c9a3f32312e1593d4a3d120572afa0d010"),
.package(url: "https://github.com/zendesk/support_sdk_ios", from: "8.0.3"),
// We can't use wordpress-rs branches nor commits here. Only tags work.
.package(url: "https://github.com/Automattic/wordpress-rs", revision: "alpha-20250926"),
.package(url: "https://github.com/wordpress-mobile/GutenbergKit", from: "0.9.0"),
.package(url: "https://github.com/Automattic/wordpress-rs", revision: "alpha-20251007"),
.package(
url: "https://github.com/Automattic/color-studio",
revision: "bf141adc75e2769eb469a3e095bdc93dc30be8de"
Expand Down Expand Up @@ -132,6 +133,13 @@ let package = Package(
name: "SFHFKeychainUtils",
cSettings: [.unsafeFlags(["-fno-objc-arc"])]
),
.target(
name: "Support",
dependencies: [
"AsyncImageKit",
"WordPressCore",
]
),
.target(name: "TextBundle"),
.target(
name: "TracksMini",
Expand Down Expand Up @@ -329,6 +337,7 @@ enum XcodeSupport {
"NotificationServiceExtensionCore",
"SFHFKeychainUtils",
"ShareExtensionCore",
"Support",
"WordPressFlux",
"WordPressShared",
"WordPressLegacy",
Expand Down
96 changes: 96 additions & 0 deletions Modules/Sources/Support/Extensions/Foundation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import Foundation

extension Date {
var isToday: Bool {
let calendar = Calendar.autoupdatingCurrent
return calendar.isDateInToday(self)
}
}

extension AttributedString {
func toHtml() -> String {
NSAttributedString(self).toHtml()
}
}

extension NSAttributedString {
func toHtml() -> String {
let documentAttributes = [
NSAttributedString.DocumentAttributeKey.documentType: NSAttributedString.DocumentType.html
]

guard
let htmlData = try? self.data(from: NSMakeRange(0, self.length), documentAttributes: documentAttributes),
let htmlString = String(data: htmlData, encoding: .utf8)
else {
return self.string
}

return htmlString
}
}

func convertMarkdownHeadingsToBold(in markdown: String) -> String {
let lines = markdown.components(separatedBy: .newlines)
var convertedLines: [String] = []

for line in lines {
let trimmedLine = line.trimmingCharacters(in: .whitespaces)

// Check if line starts with one or more # characters followed by a space
if trimmedLine.hasPrefix("#") {
// Find the first non-# character
let hashCount = trimmedLine.prefix(while: { $0 == "#" }).count

// Make sure there's at least one # and that it's followed by a space or end of string
if hashCount > 0 && hashCount < trimmedLine.count {
let remainingText = String(trimmedLine.dropFirst(hashCount))

// Check if there's a space after the hashes (proper markdown heading format)
if remainingText.hasPrefix(" ") {
let headingText = remainingText.trimmingCharacters(in: .whitespaces)
if !headingText.isEmpty {
// Convert to bold text
convertedLines.append("**\(headingText)**")
continue
}
}
}
}

// If not a heading, keep the original line
convertedLines.append(line)
}

return convertedLines.joined(separator: "\n")
}

func convertMarkdownTextToAttributedString(_ text: String) -> AttributedString {
do {
// The iOS Markdown parser doesn't support headings, so we need to convert those
let modifiedText = convertMarkdownHeadingsToBold(in: text)
return try AttributedString(
markdown: modifiedText,
options: AttributedString.MarkdownParsingOptions(
interpretedSyntax: .inlineOnlyPreservingWhitespace
)
)
} catch {
// Fallback to plain-text rendering
return AttributedString(text)
}
}

extension Task where Failure == Error {
static func delayedAndRunOnMainActor<C>(
for duration: C.Instant.Duration,
priority: TaskPriority? = nil,
operation: @MainActor @escaping @Sendable () throws -> Success,
clock: C = .continuous
) -> Task where C: Clock {
Task(priority: priority) {
try await clock.sleep(for: duration)
return try await MainActor.run(body: operation)
}
}
}
5 changes: 5 additions & 0 deletions Modules/Sources/Support/Extensions/SwiftUI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import SwiftUI

extension EdgeInsets {
static let zero = EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
}
Loading