feat: expose parse_text via FFI - returns paragraph blocks from TXT
This commit is contained in:
parent
f8c0864b61
commit
25ad7490a3
@ -1786,6 +1786,13 @@ public func parseMarkdown(content: String)throws -> [DocumentBlock] {
|
||||
)
|
||||
})
|
||||
}
|
||||
public func parseText(content: String)throws -> [DocumentBlock] {
|
||||
return try FfiConverterSequenceTypeDocumentBlock.lift(try rustCallWithError(FfiConverterTypeDocumentError_lift) {
|
||||
uniffi_zx_document_ffi_fn_func_parse_text(
|
||||
FfiConverterString.lower(content),$0
|
||||
)
|
||||
})
|
||||
}
|
||||
public func readImageMeta(filePath: String)throws -> ImageMeta {
|
||||
return try FfiConverterTypeImageMeta_lift(try rustCallWithError(FfiConverterTypeDocumentError_lift) {
|
||||
uniffi_zx_document_ffi_fn_func_read_image_meta(
|
||||
@ -1822,6 +1829,9 @@ private let initializationResult: InitializationResult = {
|
||||
if (uniffi_zx_document_ffi_checksum_func_parse_markdown() != 11780) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_zx_document_ffi_checksum_func_parse_text() != 32792) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_zx_document_ffi_checksum_func_read_image_meta() != 62824) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
|
||||
@ -101,6 +101,11 @@ fn read_text_stats(file_path: String) -> Result<Arc<TextStats>, DocumentError> {
|
||||
Ok(Arc::new(zx_document_core::text::text_stats(&content)))
|
||||
}
|
||||
|
||||
fn parse_text(content: String) -> Result<Vec<DocumentBlock>, DocumentError> {
|
||||
let blocks = zx_document_core::text::parse_text_content(&content);
|
||||
Ok(blocks.into_iter().map(Into::into).collect())
|
||||
}
|
||||
|
||||
fn parse_markdown(content: String) -> Result<Vec<DocumentBlock>, DocumentError> {
|
||||
let blocks = zx_document_core::markdown::parse_markdown(&content).map_err(|e| match e {
|
||||
zx_document_core::error::DocumentError::ParseError(_) => DocumentError::ParseError,
|
||||
|
||||
@ -10,6 +10,9 @@ namespace zx_document {
|
||||
|
||||
[Throws=DocumentError]
|
||||
sequence<DocumentBlock> parse_markdown([ByRef] string content);
|
||||
|
||||
[Throws=DocumentError]
|
||||
sequence<DocumentBlock> parse_text([ByRef] string content);
|
||||
};
|
||||
|
||||
[Error]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user