use super::emitter::fade;
use super::inline::RESET;
#[cfg(not(feature = "markdown-syntect"))]
pub(super) fn highlight(_lang: &str, body: &str) -> Vec<String> {
body.split('\n')
.map(|l| format!("{}{l}{RESET}", fade()))
.collect()
}
#[cfg(feature = "markdown-syntect")]
pub(super) fn highlight(lang: &str, body: &str) -> Vec<String> {
use syntect::util::as_24_bit_terminal_escaped;
let highlights = super::super::syntax_foreground::highlight(lang, body);
body.split('\n')
.zip(highlights)
.map(|(line, highlighted)| {
let with_nl = format!("{line}\n");
match highlighted {
Some(ranges) => {
let ranges: Vec<_> = ranges
.iter()
.map(|run| (run.style, &with_nl[run.bytes.clone()]))
.collect();
let escaped = as_24_bit_terminal_escaped(&ranges, false);
format!("{}{RESET}", escaped.trim_end_matches('\n'))
}
None => format!("{}{line}{RESET}", fade()),
}
})
.collect()
}