1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use std::path::Path;
#[must_use]
pub(crate) fn looks_promising(path: &str, raw: &str) -> bool {
is_standalone(path) || has_mermaid_fence(raw) || has_flowchart_header(raw)
}
#[must_use]
pub(super) fn is_standalone(path: &str) -> bool {
matches!(
Path::new(path)
.extension()
.and_then(|value| value.to_str())
.map(str::to_ascii_lowercase)
.as_deref(),
Some("mmd" | "mermaid")
)
}
#[must_use]
pub(super) fn is_links_file(path: &str) -> bool {
Path::new(path)
.file_name()
.and_then(|value| value.to_str())
.is_some_and(|name| name.eq_ignore_ascii_case("diagram-links.json"))
}
fn has_mermaid_fence(raw: &str) -> bool {
raw.contains("```mermaid")
|| raw.contains("~~~mermaid")
|| raw.contains("```Mermaid")
|| raw.contains("~~~Mermaid")
}
fn has_flowchart_header(raw: &str) -> bool {
raw.lines()
.map(str::trim_start)
.filter(|line| !line.is_empty() && !line.starts_with("%%"))
.take(3)
.any(|line| line.starts_with("flowchart") || line.starts_with("graph ") || line == "graph")
}