-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Comrak plugin for syntax highlighting
- Loading branch information
1 parent
5521a48
commit 763fdc5
Showing
5 changed files
with
62 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use comrak::{ | ||
plugins::syntect::{SyntectAdapter, SyntectAdapterBuilder}, | ||
Plugins, | ||
}; | ||
use std::rc::Rc; | ||
use syntect::highlighting::{Color, ThemeSet}; | ||
|
||
pub struct Highlighter { | ||
adapter: Rc<SyntectAdapter>, | ||
} | ||
|
||
impl Highlighter { | ||
pub fn get() -> Self { | ||
Self { | ||
adapter: SYNTECT_ADAPTER.with(Rc::clone), | ||
} | ||
} | ||
|
||
pub fn as_plugins(&self) -> Plugins<'_> { | ||
let mut plugins = Plugins::default(); | ||
plugins.render.codefence_syntax_highlighter = Some(&*self.adapter); | ||
plugins | ||
} | ||
} | ||
|
||
thread_local! { | ||
static SYNTECT_ADAPTER: Rc<SyntectAdapter> = Rc::new({ | ||
SyntectAdapterBuilder::new() | ||
.theme_set({ | ||
let mut ts = ThemeSet::load_defaults(); | ||
let mut theme = ts.themes["InspiredGitHub"].clone(); | ||
theme.settings.background = Some(Color { | ||
r: 0xff, | ||
g: 0xee, | ||
b: 0xff, | ||
a: 0xff, | ||
}); | ||
ts.themes.insert("InspiredGitHub2".to_string(), theme); | ||
ts | ||
}) | ||
.theme("InspiredGitHub2") | ||
.build() | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod highlight; | ||
pub mod page; | ||
pub mod string_writer; | ||
pub mod views; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters