mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
Fix up links to markdown files from within other markdown files in the Rust docs
Our language reference .md file contains a refernce to builtin_elements.md. Since rustdoc doesn't further process the embedded markdown file, the .md link remains as-is and is broken. But we can fix it up using a small snippet of JavaScript. Fixes #87
This commit is contained in:
parent
f236a7b7c7
commit
603abeabed
1 changed files with 14 additions and 0 deletions
|
@ -40,5 +40,19 @@
|
|||
}
|
||||
run();
|
||||
|
||||
// Included markdown files may have links to other markdown files, which may not have been
|
||||
// resolved by rustdoc. This helper locates such links and resolves them, assuming that each
|
||||
// .md file gets its own sub-directory with an index.html.
|
||||
function fix_markdown_links() {
|
||||
for (let anchor of document.querySelectorAll('a[href$=".md"]')) {
|
||||
let url = new URL(anchor.href);
|
||||
let dir_separator = Math.max(url.pathname.lastIndexOf("/"), 0);
|
||||
let base_name = url.pathname.slice(dir_separator + 1, -3);
|
||||
let base_path = url.pathname.slice(0, dir_separator);
|
||||
url.pathname = base_path + "/../" + base_name + "/index.html";
|
||||
anchor.setAttribute("href", url.pathname);
|
||||
}
|
||||
}
|
||||
fix_markdown_links()
|
||||
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue