mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 05:25:40 +09:00
feat(markdown): add a binary AST envelope to the native ABI (#2117)
This commit is contained in:
1 parent
69ef46356b
commit
990176ac7c
4 files changed
+380
No files matched your search
@@ -36,6 +36,36 @@ pub unsafe extern "C" fn fluxer_md_parse(
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::missing_safety_doc)]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fluxer_md_parse_binary(
|
||||
input_ptr: *const u8,
|
||||
input_len: usize,
|
||||
flags: u32,
|
||||
tsv_ptr: *const u8,
|
||||
tsv_len: usize,
|
||||
out: *mut FluxerMdBuffer,
|
||||
) -> u32 {
|
||||
let Ok(input) = std::str::from_utf8(unsafe { slice(input_ptr, input_len) }) else {
|
||||
return unsafe { write_error(out, "invalid markdown input") };
|
||||
};
|
||||
let Ok(emoji_context) = std::str::from_utf8(unsafe { slice(tsv_ptr, tsv_len) }) else {
|
||||
return unsafe { write_error(out, "invalid emoji context") };
|
||||
};
|
||||
let parsed = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
let context = crate::EmojiContext::parse(emoji_context);
|
||||
let mut parser = crate::MarkdownParser::new(flags, context);
|
||||
parser
|
||||
.parse(input)
|
||||
.map(|nodes| crate::binary::write_ast_binary(&nodes))
|
||||
}));
|
||||
match parsed {
|
||||
Ok(Ok(bytes)) => unsafe { write_data(out, bytes) },
|
||||
Ok(Err(_)) => unsafe { write_error(out, "markdown parse failed") },
|
||||
Err(_) => unsafe { write_error(out, "markdown parser panicked") },
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::missing_safety_doc)]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fluxer_md_buffer_free(out: *mut FluxerMdBuffer) {
|
||||
|
||||
Reference in new issue
Block a user