mdBook
mdBook copied to clipboard
Link Anything
Problem
It is very useful with spec-md to be able to share a link to anything: https://spec-md.com/#sel-EAHHFCAACCyFm2Q
It would be great if we could include this functionality in mdBook.
Proposed Solution
https://github.com/leebyron/spec-md/blob/main/src/client/linkSelections.js is the implementation for md-spec
https://github.com/WesleyAC/deeplinks is another implementation
Notes
No response
I managed to get deeplinks.js
working with the existing html renderer configuration options however it was a bit clunky:
additional-js
doesn't work as deeplinks.js
is a module and additional-js
doesn't account for that. additonal-js
also doesn't copy over dependency imports. Maybe we could define a folder inside of theme that was copied over completely?
I was able to get this working by including a folder in my src
directory as js
which is copied over to the final book (any name works really). I then changed my theme/head.hbs
to:
<script type="module" src="{{path_to_root}}/js/deeplinks.js"></script>
and included this additional-css
:
* {
/* Make sure when we scroll we don't hide our target under the menubar */
scroll-margin-block-start: calc(var(--menu-bar-height) + 2em);
}