Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: refactor and update docs of mitex-{spec-gen,wasm} #158

Merged
merged 1 commit into from
Apr 19, 2024
Merged
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
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ missing_docs = "warn"

[workspace.lints.clippy]
uninlined_format_args = "warn"
missing_errors_doc = "warn"
missing_panics_doc = "warn"
missing_safety_doc = "warn"
undocumented_unsafe_blocks = "warn"
2 changes: 1 addition & 1 deletion assets/artifacts
Submodule artifacts updated 1 files
+1 −1 README.md
9 changes: 7 additions & 2 deletions crates/mitex-spec-gen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
//! Generate Default Command Specification for embedded LaTeX packages.
//! Provides embedded command specifications for MiTeX.

use mitex_spec::CommandSpec;

/// Default Command Specification.
/// The default command specification.
///
/// See [Reproducing Default Command Specification][repro-default] for more
/// information.
///
/// [repro-default]: https://github.com/mitex-rs/artifacts/blob/main/README.md#default-command-specification-since-v011
pub static DEFAULT_SPEC: once_cell::sync::Lazy<CommandSpec> = once_cell::sync::Lazy::new(|| {
CommandSpec::from_bytes(include_bytes!(
"../../../target/mitex-artifacts/spec/default.rkyv"
Expand Down
41 changes: 15 additions & 26 deletions crates/mitex-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//!
//! # Usage
//!
//! For example, if you want to call [`convert_math`] function in Typst, you can
//! write the following code in your Typst file:
//! For example, you can call [`convert_math`] function in Typst by loading the
//! plugin:
//!
//! ```typ
//! #let mitex-wasm = plugin("./mitex.wasm")
Expand Down Expand Up @@ -36,36 +36,25 @@ mod impls {
Result::Ok(res.to_bytes())
}

/// Converts a LaTeX math equation into a plain text
///
/// # Errors
/// Returns an error if the input is not a valid math equation
/// Extracts the command specification from its binary (rkyv)
/// representation.
fn extract_spec(spec: &[u8]) -> Option<mitex_spec::CommandSpec> {
(!spec.is_empty()).then(|| mitex_spec::CommandSpec::from_bytes(spec))
}

/// Converts a LaTeX math equation into a plain text. You can pass an binary
/// (rkyv) command specification by `spec` at the same time to customize
/// parsing.
#[cfg_attr(feature = "web", wasm_bindgen)]
pub fn convert_math(input: &str, spec: &[u8]) -> Result<String, String> {
let spec = if spec.is_empty() {
None
} else {
let spec = mitex_spec::CommandSpec::from_bytes(spec);
Some(spec)
};
let res = mitex::convert_math(input, spec)?;
Result::Ok(res)
mitex::convert_math(input, extract_spec(spec))
}

/// Converts a LaTeX code into a plain text
///
/// # Errors
/// Returns an error if the input is not a valid LaTeX code
/// Converts a LaTeX code into a plain text. You can pass an binary (rkyv)
/// command specification by `spec` at the same time to customize parsing.
#[cfg_attr(feature = "web", wasm_bindgen)]
pub fn convert_text(input: &str, spec: &[u8]) -> Result<String, String> {
let spec = if spec.is_empty() {
None
} else {
let spec = mitex_spec::CommandSpec::from_bytes(spec);
Some(spec)
};
let res = mitex::convert_text(input, spec)?;
Result::Ok(res)
mitex::convert_text(input, extract_spec(spec))
}
}

Expand Down
Loading