Skip to content

Commit

Permalink
Load syntax theme from bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
lampsitter committed Aug 19, 2023
1 parent 0b54a76 commit d9b1a12
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

- Code blocks now use the syntax highlighting theme's caret and selection colors.
- `CommonMarkCache` now implements `Debug` ([#7](https://github.com/lampsitter/egui_commonmark/pull/7) by [@ChristopherPerry6060](https://github.com/ChristopherPerry6060)).
- `CommonMarkCache::add_syntax_theme_from_folder`
- `CommonMarkCache::add_syntax_themes_from_folder`
- `CommonMarkCache::add_syntax_theme_from_bytes`

### Changed

Expand Down
18 changes: 17 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,29 @@ impl CommonMarkCache {
/// Add more color themes for code blocks(.tmTheme files). Set the color theme with
/// [`syntax_theme_dark`](CommonMarkViewer::syntax_theme_dark) and
/// [`syntax_theme_light`](CommonMarkViewer::syntax_theme_light)
pub fn add_syntax_theme_from_folder(
pub fn add_syntax_themes_from_folder(
&mut self,
path: impl AsRef<std::path::Path>,
) -> Result<(), syntect::LoadingError> {
self.ts.add_from_folder(path)
}

#[cfg(feature = "syntax_highlighting")]
/// Add color theme for code blocks(.tmTheme files). Set the color theme with
/// [`syntax_theme_dark`](CommonMarkViewer::syntax_theme_dark) and
/// [`syntax_theme_light`](CommonMarkViewer::syntax_theme_light)
pub fn add_syntax_theme_from_bytes(
&mut self,
name: impl Into<String>,
bytes: &[u8],
) -> Result<(), syntect::LoadingError> {
let mut cursor = std::io::Cursor::new(bytes);
self.ts
.themes
.insert(name.into(), ThemeSet::load_from_reader(&mut cursor)?);
Ok(())
}

/// Refetch all images
pub fn reload_images(&mut self) {
self.images.lock().unwrap().clear();
Expand Down

0 comments on commit d9b1a12

Please sign in to comment.