Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: shiki transformers support #19

Open
aidenybai opened this issue Jun 24, 2024 · 2 comments
Open

feat: shiki transformers support #19

aidenybai opened this issue Jun 24, 2024 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@aidenybai
Copy link

aidenybai commented Jun 24, 2024

Shiki has the transformers API and the @shikijs/transformers package. These transformers contain a lot of useful utilities (such as highlight) that would be amazing to have. I wrote a pnpm patch to try and add it, but it didn't seem to work:

/patches/[email protected]

diff --git a/dist/core.mjs b/dist/core.mjs
index 13943e61abccc2b932fe40314014c3ceb856ceaf..b0f25036385759029c5f70ef4743d6f1eb1df7e6 100644
--- a/dist/core.mjs
+++ b/dist/core.mjs
@@ -1,6 +1,7 @@
 import { diff } from 'diff-match-patch-es';
 import { hash } from 'ohash';
 
+import {transformerNotationHighlight} from "@shikijs/transformers"
 function createMagicMoveMachine(codeToKeyedTokens2, options = {}) {
   const EMPTY = toKeyedTokens("", []);
   let previous = EMPTY;
@@ -30,7 +31,7 @@ function createMagicMoveMachine(codeToKeyedTokens2, options = {}) {
   };
 }
 function codeToKeyedTokens(highlighter, code, options, lineNumbers = false) {
-  const result = highlighter.codeToTokens(code, options);
+  const result = highlighter.codeToTokens(code,  {... options, transformers: [transformerNotationHighlight()] });
   return {
     ...toKeyedTokens(
       code,
@aidenybai aidenybai changed the title Transformers support feat: shiki transformers support Jun 24, 2024
@antfu
Copy link
Member

antfu commented Jun 25, 2024

This is pretty tricky, as magic-move is based on the highlighted tokens, but not the hast (in a way, say it runs before transformers). I am not sure if refactor this into hast-based would be possible - but before that happens, I'd say currently it's a limitation that magic-move doesn't work well with transformers.

@antfu antfu added enhancement New feature or request help wanted Extra attention is needed labels Jun 25, 2024
@elwyn-de-neve
Copy link

Hi Antfu, isn't this already featured in Sli.dev?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants