Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,31 @@ extension MarkdownDocument {
return bodyText
}

// MARK: - RTF Conversion

/// Converts the Markdown document to RTF data.
///
/// - Parameter options: Configuration options for the conversion (default: .default)
/// - Returns: The RTF data representation of the document
/// - Throws: Conversion errors if the operation fails
public func toRTF(options: RTFOptions = .default) async throws -> Data {
let root = try await parseAST()
let converter = RTFConverter()
return try await converter.convert(from: root, options: options)
}

/// Generates Markdown content from RTF data.
///
/// - Parameters:
/// - data: The RTF data to convert
/// - options: Configuration options for the generation (default: .default)
/// - Returns: The generated Markdown content
/// - Throws: Generation errors if the operation fails
public static func fromRTF(data: Data, options: RTFGeneratorOptions = .default) async throws -> String {
let generator = RTFGenerator()
return try await generator.generate(from: data, options: options)
}

// MARK: - Private Helpers

/// Serializes the frontmatter mapping back to YAML format.
Expand All @@ -73,13 +98,4 @@ extension MarkdownDocument {
// public func toHTML(options: HTMLOptions = .default) async throws -> String {
// fatalError("HTML conversion not yet implemented")
// }

// /// Converts the Markdown document to RTF.
// ///
// /// - Parameter options: Configuration options for RTF conversion
// /// - Returns: The RTF data representation of the document
// /// - Throws: Conversion errors if the operation fails
// public func toRTF(options: RTFOptions = .default) async throws -> Data {
// fatalError("RTF conversion not yet implemented")
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

/// Errors that can occur during RTF conversion.
public enum RTFConversionError: Error, Sendable {
/// Failed to generate RTF data from the attributed string.
case failedToGenerateRTF

/// Failed to parse RTF data into an attributed string.
case failedToParseRTF

/// The provided data is not valid RTF.
case invalidRTFData
}
Loading