[−][src]Function broken_md_links::check_broken_links
pub fn check_broken_links(
path: &Path,
dir: bool,
ignore_header_links: bool,
no_errors: bool,
links_cache: &mut HashMap<PathBuf, Vec<String>>
) -> Result<u64, String>
Check broken links in a Markdown file or directory
The input path
will be checked recursively as a directory if dir
is set to true
, else as a single file.
By default, when a header points to a specific header (e.g. other_file.md#some-header
), the target file will be opened and
the function will check if it contains the said header. As this feature may slow down the whole process, it's possible to disable it by
settings ignore_header_links
to true
.
In order to improve performances when looking at header-specific links, when a file's list of headers is made, it is stored inside a cache
This cache is shared recursively through the links_cache
argument. As it uses a specific format, it's recommanded to just pass a mutable
reference to an empty HashMap to this function, and not build your own one which may cause detection problems.
If the no_errors
parameter is set, all broken/invalid link errors will be displayed as simple warnings (but errors will still be counted).
The function returns an error is something goes wrong, or else the number of broken and invalid (without target) links.
Examples
// Single file assert_eq(check_broken_links(Path::new("file.md"), false, false, &mut HashMap::new()), Ok(0), "There are broken/invalid links :("); // Directory assert_eq(check_broken_links(Path::new("dir/"), true, false, &mut HashMap::new()), Ok(0), "There are broken/invalid links :(");