You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, and thanks for creating this plugin! It was exactly what I needed. I found it through this comment
There was a little workaround required for my use case, and I thought it could be generally helpful.
I found myself needing to rewrite relative anchors to absolute ones, which only works when knowing the current path.
This is how I do it:
constbase='/';functionabsoluteAnchors(){return(tree,file)=>{constchunks=file.history[0].split('/src/pages/');// file.history[0] is the file pathconstpath=chunks[chunks.length-1].slice(0,-4);// only path inside src/pages, without .mdxreturnrehypeUrls((url)=>{if(!url.href.startsWith('#')){return;}constabsoluteUrl=base+path+url.href;// console.log(url.href + ' -> ', absoluteUrl);returnabsoluteUrl;})(tree);};}
(I needed this because I am using a base href, which results in all relative anchor links pointing to the root path instead of the current page)
TLDR It would be handy if the function passed to the plugin would also pass a third parameter the current file, like
rehypeUrls((url,node,file)=>/* ..*/);
I could also send a PR if you like
The text was updated successfully, but these errors were encountered:
Sorry, this slipped through the cracks because I don't check Github as often as I used to.
It's been a while since I worked on any unified plugins, so the API is a bit hazy for me right now. If you already know how to implement it yourself though I'd be more than happy to accept a PR.
Hello, and thanks for creating this plugin! It was exactly what I needed. I found it through this comment
There was a little workaround required for my use case, and I thought it could be generally helpful.
I found myself needing to rewrite relative anchors to absolute ones, which only works when knowing the current path.
This is how I do it:
(I needed this because I am using a base href, which results in all relative anchor links pointing to the root path instead of the current page)
TLDR It would be handy if the function passed to the plugin would also pass a third parameter the current file, like
I could also send a PR if you like
The text was updated successfully, but these errors were encountered: