From 1340b17104785b99551b0135cceaaca4237de19b Mon Sep 17 00:00:00 2001 From: trivernis Date: Thu, 6 Aug 2020 10:20:16 +0200 Subject: [PATCH] Update Doc comments and Cargo.toml --- Cargo.toml | 3 ++- src/format/mathml.rs | 16 ++++++++++++++++ src/lib.rs | 14 +++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e36be17..d8c2e4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,12 +2,13 @@ name = "asciimath-rs" description = "AsciiMath parser" repository = "https://github.com/trivernis/asciimath-rs" -version = "0.4.3" +version = "0.4.4" authors = ["trivernis "] edition = "2018" readme = "README.md" license = "Apache-2.0" keywords = ["asciimath", "parser", "mathml"] +categories = ["mathematics", "parser-implementations"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/format/mathml.rs b/src/format/mathml.rs index ebcd1b0..22af779 100644 --- a/src/format/mathml.rs +++ b/src/format/mathml.rs @@ -12,6 +12,7 @@ use crate::tokens::{ }; use htmlescape::{encode_attribute, encode_minimal}; +/// Trait to convert the given object into a MathML representation. pub trait ToMathML { fn to_mathml(&self) -> String; } @@ -654,6 +655,21 @@ impl ToMathML for ExpressionAccent { } impl ToMathML for Expression { + /// Recursively converts the Expression into a MathML representation. + /// + /// The result needs to be enclosed in `` elements when used within + /// an html file. Currently MathML is only natively supported by Firefox and Safari. + /// + /// Example: + /// + ///``` + /// use asciimath_rs::format::mathml::ToMathML; + /// + /// fn main() { + /// let expression = asciimath_rs::parse("sin(2x - 1) + 2".to_string()); + /// println!("{}", expression.to_mathml()); + /// } + /// ``` fn to_mathml(&self) -> String { format!( "{}", diff --git a/src/lib.rs b/src/lib.rs index eb46618..d2e851f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,19 @@ pub mod parsing; pub mod tokens; pub(crate) mod utils; -/// Parses the contents of a string into an AsciiMath expression +/// Parses the contents of a string into an AsciiMath expression. +/// +/// This function first uses a tokenizer to parse the input string into +/// a sequence of tokens. Then it uses those tokens with the TreeParser to create +/// an Expression tree that can then be converted into MathML. +/// +/// Example: +/// +/// ```rust +/// fn main() { +/// let expression = asciimath_rs::parse("sin(2x) + 3".to_string()); +/// } +/// ``` pub fn parse(content: String) -> Expression { let mut tokenizer = Tokenizer::new(content); let tokens = tokenizer.parse();