Skip to content

Commit

Permalink
Add showcase
Browse files Browse the repository at this point in the history
  • Loading branch information
lampsitter committed Feb 11, 2022
1 parent 3329565 commit e681407
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ name = "egui_commonmark"
authors = ["Erlend Walstad"]
version = "0.1.0"
edition = "2021"
description = "Commonmark viewer for egui"
keywords = ["commonmark", "egui"]
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/lampsitter/egui_commonmark"
exclude = ["assets/"]

[dependencies]
# Depend on master until next release
Expand All @@ -26,3 +32,6 @@ svg = ["resvg", "usvg", "tiny-skia"]

# Fetch images over http
fetch = ["ehttp", "url", "image/jpeg"]

[dev-dependencies]
eframe = { git = "https://github.com/emilk/egui" }
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
A commonmark viewer for [egui](https://github.com/emilk/egui)
# A commonmark viewer for [egui](https://github.com/emilk/egui)

[![CI](https://github.com/lampsitter/egui_commonmark/actions/workflows/rust.yml/badge.svg)](https://github.com/lampsitter/egui_commonmark/actions/workflows/rust.yml)

# Usage
<img src="https://raw.githubusercontent.com/lampsitter/egui_commonmark/example/assets/example.png" alt="showcase" width=300/>

## Usage

```rust
use egui_commonmark::*;
let markdown =
Expand Down
Binary file added assets/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//! Make sure to run this example from the repo directory and not the example
//! directory. To see all the features in full effect, run this example with
//! `cargo r --example basic --all-features`
use eframe::{egui, epi};
use egui_commonmark::*;

struct App {
cache: CommonMarkCache,
}

impl epi::App for App {
fn name(&self) -> &str {
"Markdown viewer"
}

fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) {
let text = r#"# Commonmark Viewer example
A *little* ~~paragraph~~ __with__ `multiple` styles.
| __A table!__ |
| -------- |
| ![Rust logo](examples/rust-logo-128x128.png) |
| Some filler text |
| [Link to repo](https://github.com/lampsitter/egui_commonmark) |
```rs
let mut vec = Vec::new();
vec.push(5);
```
> Some smart quote here
- [ ] A feature[^1]
- [X] A completed feature
1. Sub item
[^1]: A footnote
"#;

egui::CentralPanel::default().show(ctx, |ui| {
egui::ScrollArea::vertical().show(ui, |ui| {
CommonMarkViewer::new("viewer")
.max_image_width(Some(512))
.show(ui, &mut self.cache, text);
});
});
}
}

fn main() {
let options = eframe::NativeOptions::default();
eframe::run_native(
Box::new(App {
cache: CommonMarkCache::default(),
}),
options,
);
}
Binary file added examples/rust-logo-128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/rust-logo-license
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Logo from https://github.com/rust-lang/rust-artwork

0 comments on commit e681407

Please sign in to comment.