mirror of
https://github.com/Hopiu/lychee.git
synced 2026-04-07 06:51:00 +00:00
Add support and tests for .markdown files (#152)
This commit is contained in:
parent
b8f24bfa3b
commit
41b82cb459
1 changed files with 21 additions and 2 deletions
|
|
@ -9,7 +9,7 @@ use std::path::Path;
|
|||
use std::{collections::HashSet, convert::TryFrom};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum FileType {
|
||||
Html,
|
||||
Markdown,
|
||||
|
|
@ -28,7 +28,7 @@ impl<P: AsRef<Path>> From<P> for FileType {
|
|||
let path = p.as_ref();
|
||||
match path.extension() {
|
||||
Some(ext) => match ext {
|
||||
_ if ext == "md" => FileType::Markdown,
|
||||
_ if (ext == "md" || ext == "markdown") => FileType::Markdown,
|
||||
_ if (ext == "htm" || ext == "html") => FileType::Html,
|
||||
_ => FileType::Plaintext,
|
||||
},
|
||||
|
|
@ -202,6 +202,25 @@ mod test {
|
|||
content
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_file_type() {
|
||||
assert_eq!(FileType::from(Path::new("test.md")), FileType::Markdown);
|
||||
assert_eq!(
|
||||
FileType::from(Path::new("test.markdown")),
|
||||
FileType::Markdown
|
||||
);
|
||||
assert_eq!(FileType::from(Path::new("test.html")), FileType::Html);
|
||||
assert_eq!(FileType::from(Path::new("test.txt")), FileType::Plaintext);
|
||||
assert_eq!(
|
||||
FileType::from(Path::new("test.something")),
|
||||
FileType::Plaintext
|
||||
);
|
||||
assert_eq!(
|
||||
FileType::from(Path::new("/absolute/path/to/test.something")),
|
||||
FileType::Plaintext
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_markdown_links() {
|
||||
let input = "This is [a test](https://endler.dev). This is a relative link test [Relative Link Test](relative_link)";
|
||||
|
|
|
|||
Loading…
Reference in a new issue