leafac / rehype-shiki

Rehype plugin to highlight code blocks with Shiki
MIT License
31 stars 3 forks source link

Traverse the whole tree #5

Open devanshj opened 2 years ago

devanshj commented 2 years ago

Currently this plugin can only highlight pres at the root, so the following pre won't transform...

<div>
  <pre><code class="language-js">hello()</code></pre>
</div>

The problem is the plugin doesn't traverse the whole tree (with something like unist-util-visit), I tried to fix this but for some reason (that I don't remember) it didn't work.

(Related: https://github.com/mdx-js/mdx/discussions/1939)

leafac commented 2 years ago

Hi @devanshj,

Thanks for reaching out and reporting the issue. Interestingly, I noticed the issue on the project in which I’m using rehype-shiki at about the same time you reported it.

The reason seems to be that unistUtilModifyChildren doesn’t traverse the tree like I expected it would. Like you pointed out, the solution is probably to use unist-util-visit.

Do you think you could draft a pull request? 😁

devanshj commented 2 years ago

Thanks for reaching out and reporting the issue.

No problems.

Do you think you could draft a pull request? 😁

I already tried getting it work with unist-util-visit as I said but it seems there were other complications (which I don't have time to investigate), so I don't think I'll be able to send a PR 😅. Moreover I ended up writing a plugin myself.

leafac commented 2 years ago

👍 Thanks for the information. I’ll get to this soon…

calebeby commented 2 years ago

Hey @leafac did you get a chance to start this? I'd like to send a PR but I don't want to duplicate work if you have a WIP implementation.

leafac commented 2 years ago

@calebeby Please go ahead! I haven’t started with this yet. Looking forward to your contribution. Thanks!