Download next.js/crates/napi/src/mdx.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/crates/napi/src/mdx.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/crates/napi/src/mdx.rs
-
curl -L -o mdx.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/crates/napi/src/mdx.rs
1.16 kB
| use mdxjs::{Options, compile}; | |
| use napi::bindgen_prelude::*; | |
| pub struct MdxCompileTask { | |
| pub input: String, | |
| pub option: Buffer, | |
| } | |
| impl Task for MdxCompileTask { | |
| type Output = String; | |
| type JsValue = String; | |
| fn compute(&mut self) -> napi::Result<Self::Output> { | |
| let options: Options = serde_json::from_slice(&self.option)?; | |
| compile(&self.input, &options) | |
| .map_err(|err| napi::Error::new(Status::GenericFailure, err.to_string())) | |
| } | |
| fn resolve(&mut self, _env: Env, output: Self::Output) -> napi::Result<Self::JsValue> { | |
| Ok(output) | |
| } | |
| } | |
| pub fn mdx_compile( | |
| value: String, | |
| option: Buffer, | |
| signal: Option<AbortSignal>, | |
| ) -> napi::Result<AsyncTask<MdxCompileTask>> { | |
| let task = MdxCompileTask { | |
| input: value, | |
| option, | |
| }; | |
| Ok(AsyncTask::with_optional_signal(task, signal)) | |
| } | |
| pub fn mdx_compile_sync(value: String, option: Buffer) -> napi::Result<String> { | |
| let option: Options = serde_json::from_slice(&option)?; | |
| compile(value.as_str(), &option) | |
| .map_err(|err| napi::Error::new(Status::GenericFailure, format!("{err:?}"))) | |
| } | |