Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix relative link parsing #136

Merged
merged 1 commit into from
Oct 13, 2022
Merged
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
Binary file modified docs/modules/bartholomew.wasm
Binary file not shown.
12 changes: 7 additions & 5 deletions src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ fn visit_files(dir: PathBuf, cb: &mut dyn FnMut(&DirEntry)) -> anyhow::Result<()
fn maybe_translate_relative_link(dest: markdown::CowStr) -> markdown::CowStr {
if let Some(dest) = dest.strip_suffix(".md") {
if let Some(dest) = dest.strip_prefix("./") {
return format!("/{dest}").into();
} else if !dest.contains('/') {
return format!("/{dest}").into();
return dest.to_string().into();
}

return dest.to_string().into();
}

dest
Expand Down Expand Up @@ -407,10 +407,12 @@ mod test {
let input = r#"
This is a [relative link](./relative.md), but this is a [URL](https://en.wikipedia.org/).
Here's another [relative link](elsewhere.md), and here's [something else](/foo).
And this is an example of [relative deep link](./relatively/deep.md) and an example of [absolute deep link](/absolute/deep.md)
"#;

let expected_output = r#"<p>This is a <a href="/relative">relative link</a>, but this is a <a href="https://en.wikipedia.org/">URL</a>.
Here’s another <a href="/elsewhere">relative link</a>, and here’s <a href="/foo">something else</a>.</p>
let expected_output = r#"<p>This is a <a href="relative">relative link</a>, but this is a <a href="https://en.wikipedia.org/">URL</a>.
Here’s another <a href="elsewhere">relative link</a>, and here’s <a href="/foo">something else</a>.
And this is an example of <a href="relatively/deep">relative deep link</a> and an example of <a href="/absolute/deep">absolute deep link</a></p>
"#;

let actual_output =
Expand Down