Crate egui_commonmark_macros

source ·
Expand description

Compile time evaluation of markdown that generates egui widgets

It is recommended to use this crate through the parent crate egui_commonmark. If you for some reason don’t want to use it you must also import egui_commonmark_backend directly from your crate to get access to CommonMarkCache and internals that the macros require for the final generated code.

§API

§Embedding markdown text directly

The macro has the following format:

commonmark!(id, ui, cache, text);

§Example
let mut cache = CommonMarkCache::default();
let _response = commonmark!("example", ui, &mut cache, "# ATX Heading Level 1");

As you can see it also returns a response like most other egui widgets.

§Embedding markdown file

The macro has the exact same format as the commonmark! macro:

commonmark_str!(id, ui, cache, file_path);

§Example
let mut cache = CommonMarkCache::default();
commonmark_str!("example", ui, &mut cache, "foo.md");

One drawback is that the file cannot be tracked by rust on stable so the program won’t recompile if you only change the content of the file. To work around this you can use a nightly compiler and enable the nightly feature when iterating on your markdown files.

§Limitations

Compared to it’s runtime counterpart egui_commonmark it currently does not offer customization. This is something that will be addressed eventually once a good API has been chosen.

§What this crate is not

This crate does not have as a goal to make widgets that can be interacted with through code.

let ... = commonmark!("example", ui, &mut cache, "- [ ] Task List");
task_list.set_checked(true); // No !!

For that you should fall back to normal egui widgets

§Features

  • nightly — Enable tracking of markdown files to recompile when their content changes

Macros§