Using rehype/remark plugins on elements with custom components #506
Unanswered
emmalexandria
asked this question in
Q&A
Replies: 1 comment
-
I had the same issue and I've worked around it by generating the IDs in the components using the github-slugger package. For instance: <script lang="ts">
import GithubSlugger from "github-slugger";
let data: HTMLHeadElement;
const slugger = new GithubSlugger();
</script>
<h2
id={slugger.slug(data?.innerText)}
bind:this={data}
class="mt-4 text-3xl font-semibold">
<slot />
</h2> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using custom components to style all my markdown elements (such as headers), and when I tried to integrate remark-slug and remark-autolink-headings, I ran into a problem. The plugins do not seem to apply when using custom components which (in retrospect) is obvious.
However, is there any way to work around this? In fact, am I even approaching styling things like headers correctly? I kind of just went for doing it through custom components, but I don't know if there's a better, more intended way. I know that Josh Collinsworth's blog starter manages it, but I can't for the life of me figure out where the custom layouts/styles are (if they even exist in the starter - for all I know the example site is not a 1:1 build of the repo).
Help would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions