Expand description
§strip-codeblocks
A Rust library to strip markdown fenced code blocks from text while preserving the inner content and leaving inline code blocks untouched.
§Features
- Removes fenced code blocks (triple backticks: ```)
- Preserves the content inside code blocks
- Keeps inline code blocks (single backticks: `) intact
- Handles code blocks with or without language identifiers
§Usage
use strip_codeblocks::strip_codeblocks;
let markdown = "Here is some text.\n\n```rust\nfn main() {\n println!(\"Hello, world!\");\n}\n```\n\nMore text with `inline code` here.";
let result = strip_codeblocks(markdown);
// Result: "Here is some text.\n\nfn main() {\n println!(\"Hello, world!\");\n}\n\nMore text with `inline code` here."§Examples
§Basic Usage
use strip_codeblocks::strip_codeblocks;
let input = "```python\nprint('hello')\n```";
let output = strip_codeblocks(input);
assert_eq!(output, "print('hello')\n");§Preserving Inline Code
use strip_codeblocks::strip_codeblocks;
let input = "This has `inline code` and ```\ncode block\n```";
let output = strip_codeblocks(input);
assert_eq!(output, "This has `inline code` and code block\n");Functions§
- strip_
codeblocks - Strips fenced code blocks from markdown text while preserving the inner content.