Canop / termimad

A library to display rich (Markdown) snippets and texts in a rust terminal application
MIT License
914 stars 31 forks source link

How to render a code block that has new lines in it in one block. #43

Closed pythops closed 1 year ago

pythops commented 1 year ago

When I try to render a piece of code that contains a new line in it, I get the new line without any background highlight.

for instance,

use termimad;

fn main() {
    let code = r#"
        let x =0;

        println!("{}", x);

    "#;

    println!("{}", termimad::MadSkin::default_dark().term_text(code));
}

this will produce this rendering screenshot-1691873778

as you can see it does not render it in one block.

Canop commented 1 year ago

The problem isn't really with termimad. The problem is your middle line is missing the tab or 4 spaces making it a line of codes.

Possible solutions depending on your case:

With code fences:

fn main() {
    let code = r#"
```
    let x =0;

    println!("{}", x);
```
"#;

    println!("{}", termimad::MadSkin::default_dark().term_text(code));
}
pythops commented 1 year ago

Thanks for the answer. We can mark this as closed then :)