Skip to content

Commit

Permalink
fix relative link parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Rajat Jindal <[email protected]>
  • Loading branch information
rajatjindal committed Oct 12, 2022
1 parent 92a1c39 commit 805cf14
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
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

0 comments on commit 805cf14

Please sign in to comment.