mirror of
https://github.com/tealdeer-rs/tealdeer.git
synced 2026-08-21 23:54:18 +02:00
Underline parameters in example code
This commit is contained in:
parent
423fc4a21c
commit
152343eaef
1 changed files with 18 additions and 2 deletions
|
|
@ -2,11 +2,27 @@
|
|||
|
||||
use std::io::BufRead;
|
||||
|
||||
use ansi_term::Colour;
|
||||
use ansi_term::{Colour, ANSIStrings};
|
||||
|
||||
use tokenizer::Tokenizer;
|
||||
use types::LineType;
|
||||
|
||||
|
||||
/// Provide formatting for {{ curly braces }} in ExampleCode lines
|
||||
fn format_braces(text: &str) -> String {
|
||||
let parts = text.split("{{").flat_map(|s| s.split("}}"))
|
||||
.enumerate()
|
||||
.map(|(i, v)| {
|
||||
if i % 2 == 0 {
|
||||
Colour::Cyan.paint(v)
|
||||
} else {
|
||||
Colour::Cyan.underline().paint(v)
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
return ANSIStrings(&parts).to_string()
|
||||
}
|
||||
|
||||
/// Print a token stream to an ANSI terminal.
|
||||
pub fn print_lines<R>(tokenizer: &mut Tokenizer<R>) where R: BufRead {
|
||||
while let Some(token) = tokenizer.next() {
|
||||
|
|
@ -15,7 +31,7 @@ pub fn print_lines<R>(tokenizer: &mut Tokenizer<R>) where R: BufRead {
|
|||
LineType::Title(_) => debug!("Ignoring title"),
|
||||
LineType::Description(text) => println!(" {}", text),
|
||||
LineType::ExampleText(text) => println!(" {}", Colour::Green.paint(format!("- {}", text))),
|
||||
LineType::ExampleCode(text) => println!(" {}", Colour::Cyan.paint(format!(" {}", text))),
|
||||
LineType::ExampleCode(text) => println!(" {}", &format_braces(&text)),
|
||||
LineType::Other(text) => debug!("Unknown line type: {:?}", text),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue