Skip to content

Commit

Permalink
More macro documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lampsitter committed May 11, 2024
1 parent 76a9ec2 commit f29d13e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions egui_commonmark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!())]

Expand Down
3 changes: 3 additions & 0 deletions egui_commonmark_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f29d13e

Please sign in to comment.