Skip to content

Markdown viewer for egui

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

lampsitter/egui_commonmark

Repository files navigation

A commonmark viewer for egui

Crate Documentation

showcase

While this crate's main focus is commonmark, it also supports a subset of Github's markdown syntax: tables, strikethrough, tasklists and footnotes.

Usage

In Cargo.toml:

egui_commonmark = "0.16"
# Specify what image formats you want to use
image = { version = "0.24", default-features = false, features = ["png"] }
use egui_commonmark::*;
let markdown =
r"# Hello world

* A list
* [ ] Checkbox
";

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 macros feature. This will do the parsing of the markdown at compile time and output egui widgets.

Example

use egui_commonmark::{CommonMarkCache, commonmark};
let mut cache = CommonMarkCache::default();
let _response = commonmark!("example", ui, &mut cache, "# ATX Heading Level 1");

Alternatively you can embed a file

Example

use egui_commonmark::{CommonMarkCache, commonmark_str};
let mut cache = CommonMarkCache::default();
commonmark_str!("example_file", ui, &mut cache, "content.md");

Features

  • macros: macros for compile time parsing of markdown
  • better_syntax_highlighting: Syntax highlighting inside code blocks with syntect
  • svg: Support for viewing svg images
  • fetch: Images with urls will be downloaded and displayed

Examples

For an easy intro check out the hello_world example. To see all the different features egui_commonmark has to offer check out the book example.

License

Licensed under either of

at your option.