-
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.
Loading status checks…
Switch to use Comrak for syntax highlighting (#438)
1 parent
f0d11ce
commit a3c8ea3
Showing
6 changed files
with
127 additions
and
91 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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