(&self, code: &str, language: &str)
| 567 | |
| 568 | #[must_use] |
| 569 | pub fn highlight_code(&self, code: &str, language: &str) -> String { |
| 570 | let syntax = self |
| 571 | .syntax_set |
| 572 | .find_syntax_by_token(language) |
| 573 | .unwrap_or_else(|| self.syntax_set.find_syntax_plain_text()); |
| 574 | let mut syntax_highlighter = HighlightLines::new(syntax, &self.syntax_theme); |
| 575 | let mut colored_output = String::new(); |
| 576 | |
| 577 | for line in LinesWithEndings::from(code) { |
| 578 | match syntax_highlighter.highlight_line(line, &self.syntax_set) { |
| 579 | Ok(ranges) => { |
| 580 | let escaped = as_24_bit_terminal_escaped(&ranges[..], false); |
| 581 | colored_output.push_str(&apply_code_block_background(&escaped)); |
| 582 | } |
| 583 | Err(_) => colored_output.push_str(&apply_code_block_background(line)), |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | colored_output |
| 588 | } |
| 589 | |
| 590 | pub fn stream_markdown(&self, markdown: &str, out: &mut impl Write) -> io::Result<()> { |
| 591 | let rendered_markdown = self.markdown_to_ansi(markdown); |
no test coverage detected