rehype-shiki icon indicating copy to clipboard operation
rehype-shiki copied to clipboard

Traverse the whole tree

Open devanshj opened this issue 3 years ago • 5 comments

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)

devanshj avatar Feb 20 '22 15:02 devanshj

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? 😁

leafac avatar Mar 14 '22 09:03 leafac

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.

devanshj avatar Mar 14 '22 11:03 devanshj

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

leafac avatar Mar 15 '22 12:03 leafac

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.

calebeby avatar Apr 19 '22 00:04 calebeby

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

leafac avatar Apr 19 '22 13:04 leafac