Update Doc comments and Cargo.toml

pull/9/head
trivernis 4 years ago
parent d70ac0e58e
commit 1340b17104

@ -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 <trivernis@protonmail.com>"]
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

@ -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 `<math></math>` 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!("<math>{}</math>", expression.to_mathml());
/// }
/// ```
fn to_mathml(&self) -> String {
format!(
"<mrow>{}</mrow>",

@ -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();

Loading…
Cancel
Save