diff --git a/README.md b/README.md index b82b3fd..29a4d9a 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,38 @@ let mut cache = CommonMarkCache::default(); CommonMarkViewer::new("viewer").show(ui, &mut cache, markdown); ``` + +## Compile time evaluation of markdown + +If you want to embed markdown directly the binary then you can enable the `macro` feature. +This will do the parsing of the markdown at compile time and output egui widgets. + +### Example + +```rust +use egui_commonmark::{CommonMarkCache, commonmark}; +# egui::__run_test_ui(|ui| { +let mut cache = CommonMarkCache::default(); +let _response = commonmark!("example", ui, &mut cache, "# ATX Heading Level 1"); +# }); +``` + +Alternatively you can embed a file + +### Example + +```rust +use egui_commonmark::{CommonMarkCache, commonmark_str}; +# egui::__run_test_ui(|ui| { +let mut cache = CommonMarkCache::default(); +commonmark_str!("example_file", ui, &mut cache, "content.md"); +# }); +``` + + ## Features +* `macro`: macros for compile time parsing of markdown * `better_syntax_highlighting`: Syntax highlighting inside code blocks with [`syntect`](https://crates.io/crates/syntect) * `svg`: Support for viewing svg images diff --git a/egui_commonmark/src/lib.rs b/egui_commonmark/src/lib.rs index 2d32512..8ba58a6 100644 --- a/egui_commonmark/src/lib.rs +++ b/egui_commonmark/src/lib.rs @@ -24,7 +24,36 @@ //! ```toml //! image = { version = "0.24", default-features = false, features = ["png"] } //! ``` +//! # Compile time evaluation of markdown //! +//! If you want to embed markdown directly the binary then you can enable the `macro` feature. +//! This will do the parsing of the markdown at compile time and output egui widgets. +//! +//! ## Example +//! +//! ``` +//! use egui_commonmark::{CommonMarkCache, commonmark}; +//! # egui::__run_test_ui(|ui| { +//! let mut cache = CommonMarkCache::default(); +//! let _response = commonmark!("example", ui, &mut cache, "# ATX Heading Level 1"); +//! # }); +//! ``` +//! +//! Alternatively you can embed a file +//! +//! +//! ## Example +//! +//! ```rust,ignore +//! use egui_commonmark::{CommonMarkCache, commonmark_str}; +//! # egui::__run_test_ui(|ui| { +//! let mut cache = CommonMarkCache::default(); +//! commonmark_str!("example_file", ui, &mut cache, "content.md"); +//! # }); +//! ``` +//! +//! For more information check out the documentation for +//! [egui_commonmark_macros](https://docs.rs/crate/egui_commonmark_macros/latest) #![cfg_attr(feature = "document-features", doc = "# Features")] #![cfg_attr(feature = "document-features", doc = document_features::document_features!())] diff --git a/egui_commonmark_macros/src/lib.rs b/egui_commonmark_macros/src/lib.rs index e14cba6..1d38b98 100644 --- a/egui_commonmark_macros/src/lib.rs +++ b/egui_commonmark_macros/src/lib.rs @@ -47,6 +47,9 @@ //! # }); //! ``` //! +//! One current drawback is that the file is not tracked by rust so the program won't recompile +//! if you only change the content of the file. +//! //! ## Limitations //! //! Compared to it's runtime counterpart egui_commonmark it currently does not