v6/src/generator/highlight/shell.rs

25 lines
627 B
Rust

use super::{highlight, Highlighter};
pub struct ShellHighlighter;
impl Highlighter for ShellHighlighter {
fn highlight(&self, code: &str) -> String {
let mut res = String::new();
let mut is_first = true;
for line in code.lines() {
if is_first {
is_first = false;
} else {
res.push('\n');
}
if line.starts_with("$ ") {
res.push_str("$ ");
res.push_str(&highlight(&line[2..], "bash"));
} else {
res.push_str(line);
}
}
res
}
}