Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions fixtures/TEST_QUARTO.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Sample
---

Real link: <https://example.com>.

```{.bash}
curl -O https://cdn.posit.co/r/rhel-10/pkgs/R-${R_VERSION}-1-1.$(arch).rpm
```

Inline `https://inline.example.com/code` should also be excluded.
13 changes: 13 additions & 0 deletions fixtures/TEST_RMARKDOWN.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Sample R Markdown
output: html_document
---

Real link: <https://example.com>.

```{r setup, include=FALSE}
# This URL should be ignored because it's inside a fenced code block
download.file("https://cdn.posit.co/r/rhel-10/pkgs/R-${R_VERSION}-1-1.rpm")
```

Inline `https://inline.example.com/rmd` should also be excluded.
2 changes: 1 addition & 1 deletion lychee-bin/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub(crate) struct Config {
/// This is useful when the default extensions are not enough and you don't
/// want to provide a long list of inputs (e.g. file1.html, file2.md, etc.)
///
/// [default: md,mkd,mdx,mdown,mdwn,mkdn,mkdown,markdown,html,htm,css,txt,xml]
/// [default: md,markdown,mdx,qmd,rmd,mkd,mkdn,mdwn,mdown,mkdown,html,htm,css,txt,xml]
#[arg(long, verbatim_doc_comment)]
extensions: Option<FileExtensions>,

Expand Down
29 changes: 29 additions & 0 deletions lychee-bin/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,35 @@ The config file should contain every possible key for documentation purposes."
.stdout(contains("http://127.0.0.1/inline"))
.stdout(contains("http://127.0.0.1/bash"));
}

#[test]
fn test_quarto_treated_as_markdown() {
let input = fixtures_path!().join("TEST_QUARTO.qmd");

cargo_bin_cmd!()
.arg(input)
.arg("--dump")
.assert()
.success()
.stdout(contains("https://example.com"))
.stdout(contains("cdn.posit.co").not())
.stdout(contains("inline.example.com").not());
}

#[test]
fn test_rmarkdown_treated_as_markdown() {
let input = fixtures_path!().join("TEST_RMARKDOWN.Rmd");

cargo_bin_cmd!()
.arg(input)
.arg("--dump")
.assert()
.success()
.stdout(contains("https://example.com"))
.stdout(contains("cdn.posit.co").not())
.stdout(contains("inline.example.com").not());
}

#[tokio::test]
async fn test_verbatim_skipped_by_default_via_file() {
let file = fixtures_path!().join("TEST_VERBATIM.html");
Expand Down
7 changes: 6 additions & 1 deletion lychee-lib/src/types/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ impl std::fmt::Display for FileType {

impl FileType {
/// All known Markdown extensions
// NOTE: Stored in reverse-popularity order because the `Iterator` impl for
// `FileExtensions` pops from the end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment really makes me raise an eyebrow at impl Iterator for FileExtensions. Conceptually, I do not think FileExtensions should be a stateful iterator that gets mutated.

Is iterating over FileExtensions even necessary? If iteration is needed, it should delegate to Vec's iterator, or there can just be a function that returns a slice of strings.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, true, that crossed my mind as well. Didn't want to change too much at once, but I could change that in this PR.

const MARKDOWN_EXTENSIONS: &'static [&'static str] = &[
"markdown", "mkdown", "mkdn", "mdwn", "mdown", "mdx", "mkd", "md",
"mkdown", "mdown", "mdwn", "mkdn", "mkd", "rmd", "qmd", "mdx", "markdown", "md",
];

/// All known HTML extensions
Expand Down Expand Up @@ -266,6 +268,9 @@ mod tests {
assert_eq!(FileType::from("foo.md"), FileType::Markdown);
assert_eq!(FileType::from("foo.MD"), FileType::Markdown);
assert_eq!(FileType::from("foo.mdx"), FileType::Markdown);
assert_eq!(FileType::from("foo.qmd"), FileType::Markdown);
assert_eq!(FileType::from("foo.Rmd"), FileType::Markdown);
assert_eq!(FileType::from("foo.rmd"), FileType::Markdown);

// Test that a file without an extension is considered plaintext
assert_eq!(FileType::from("README"), FileType::Plaintext);
Expand Down
Loading