diff options
Diffstat (limited to 'src/render/markdown.rs')
| -rw-r--r-- | src/render/markdown.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/render/markdown.rs b/src/render/markdown.rs index 8ae0a09..834c47b 100644 --- a/src/render/markdown.rs +++ b/src/render/markdown.rs @@ -82,6 +82,16 @@ impl MarkdownRender { .join("\n") } + pub fn render_with_indent(&mut self, text: &str, padding: usize) -> String { + let text = format!("{}{}", " ".repeat(padding), text); + let output = self.render(&text); + if output.starts_with('\n') { + output + } else { + output.chars().skip(padding).collect() + } + } + pub fn render_line(&self, line: &str) -> String { let (_, code_syntax, is_code) = self.check_line(line); if is_code { @@ -359,4 +369,17 @@ std::error::Error>> { let output = render.render(TEXT); assert_eq!(TEXT_WRAP_ALL, output); } + + #[test] + fn wrap_with_indent() { + let options = RenderOptions::default(); + let mut render = MarkdownRender::init(options).unwrap(); + render.wrap_width = Some(80); + + let input = "To unzip a file in Rust, you can use the `zip` crate. Here's an example code"; + let output = render.render_with_indent(input, 40); + let expect = + "To unzip a file in Rust, you can use the\n`zip` crate. Here's an example code"; + assert_eq!(output, expect); + } } |
