30 lines
733 B
Rust
Raw Normal View History

2019-06-08 14:16:05 +03:00
pub(crate) fn mark_fenced_blocks_as_rust(src: &str) -> String {
let mut processed_lines = Vec::new();
let mut in_code_block = false;
2019-06-08 14:16:05 +03:00
for line in src.lines() {
if line.starts_with("```") {
2019-06-08 14:16:05 +03:00
in_code_block ^= true
}
let line = if in_code_block && line.starts_with("```") && !line.contains("rust") {
2019-06-08 14:16:05 +03:00
"```rust"
} else {
2019-06-08 14:16:05 +03:00
line
};
processed_lines.push(line);
}
2019-06-08 14:16:05 +03:00
processed_lines.join("\n")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_codeblock_adds_rust() {
let comment = "```\nfn some_rust() {}\n```";
2019-06-08 14:16:05 +03:00
assert_eq!(mark_fenced_blocks_as_rust(comment), "```rust\nfn some_rust() {}\n```");
}
}