-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21b943c
commit 9f6c018
Showing
3 changed files
with
58 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
//! comrak plugins we need | ||
mod slides; | ||
mod syntax; | ||
|
||
pub use slides::SlideAdapter; | ||
pub use syntax::SyntaxHighlighter; |
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,53 @@ | ||
//! Our Syntax Highlighting code, | ||
//! | ||
//! A comrak plugin for adding syntax highlighting classes to code blocks. | ||
pub struct SyntaxHighlighter(); | ||
|
||
impl SyntaxHighlighter { | ||
pub fn new() -> SyntaxHighlighter { | ||
SyntaxHighlighter() | ||
} | ||
} | ||
|
||
impl comrak::adapters::SyntaxHighlighterAdapter for SyntaxHighlighter { | ||
fn write_pre_tag( | ||
&self, | ||
output: &mut dyn std::io::Write, | ||
attributes: std::collections::HashMap<String, String>, | ||
) -> std::io::Result<()> { | ||
println!("Pre Attr: {:?}", attributes); | ||
writeln!(output, "<pre>")?; | ||
Ok(()) | ||
} | ||
|
||
fn write_code_tag( | ||
&self, | ||
output: &mut dyn std::io::Write, | ||
attributes: std::collections::HashMap<String, String>, | ||
) -> std::io::Result<()> { | ||
println!("Code Attr: {:?}", attributes); | ||
let mut lang_class = ""; | ||
if let Some(class) = attributes.get("class") { | ||
if let Some(lang) = class.strip_prefix("language-") { | ||
lang_class = lang; | ||
} | ||
} | ||
writeln!( | ||
output, | ||
r#"<code data-trim data-noescape class="{lang_class}">"# | ||
)?; | ||
Ok(()) | ||
} | ||
|
||
fn write_highlighted( | ||
&self, | ||
output: &mut dyn std::io::Write, | ||
lang: Option<&str>, | ||
code: &str, | ||
) -> std::io::Result<()> { | ||
println!("Got lang {:?}", lang); | ||
writeln!(output, "{}", code)?; | ||
Ok(()) | ||
} | ||
} |