summaryrefslogtreecommitdiff
path: root/src/util/path_display.rs
blob: 78ff989edaf0fce12900099c04d4813dcfcfb9ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//! Helpers for displaying filesystem paths in generated Markdown.

use std::path::Path;

/// Converts a path to a Markdown-friendly display string.
///
/// The returned string uses Rust's debug-style path formatting so that unusual characters remain
/// visible instead of affecting the Markdown structure. For example, embedded newlines are shown as
/// `\n`, and invalid UTF-8 bytes are escaped.
///
/// Surrounding quotes added by debug formatting are stripped when present, so ordinary paths remain
/// easy to read.
pub fn display_path(path: &Path) -> String {
    let s = format!("{:?}", path);
    s.strip_prefix('"')
        .and_then(|s| s.strip_suffix('"'))
        .unwrap_or(&s)
        .to_string()
}