-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add syntax highlighting. I think I broke like everything else in th…
…e process though Please help me
- Loading branch information
1 parent
a04b1a2
commit e515c11
Showing
4 changed files
with
107 additions
and
15 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
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,19 @@ | ||
use syntect::{self, highlighting::Style}; | ||
|
||
pub fn highlight_line(text: &String) -> Vec<(Style, &str)> { | ||
// using syntect, apply markdown syntax highlighting to the text | ||
let syntax_set = syntect::parsing::SyntaxSet::load_defaults_newlines(); | ||
let syntax = syntax_set.find_syntax_by_extension("md").unwrap(); | ||
let h = syntect::highlighting::ThemeSet::load_defaults(); | ||
let mut highlighter = syntect::easy::HighlightLines::new(syntax, &h.themes["base16-mocha.dark"]); | ||
|
||
let highlighted = highlighter.highlight_line(text, &syntax_set).unwrap(); | ||
// let escaped = syntect::util::as_24_bit_terminal_escaped(&highlighted, false); | ||
highlighted | ||
} | ||
|
||
pub fn to_terminal_escaped(highlighted: &Vec<(Style, &str)>) -> String { | ||
// convert the highlighted text to a string with terminal escape sequences | ||
let escaped = syntect::util::as_24_bit_terminal_escaped(highlighted, false); | ||
escaped | ||
} |