Skip to content

Use shiki-twoslash for .svelte code blocks #649

Description

@Rich-Harris

Describe the problem

We just upgraded the docs to use shiki-twoslash, which provides tooltips on js code blocks:

image

It would be cool if svelte blocks got the same treatment.

Describe the proposed solution

Honestly no idea, but @jasonlyu123 got a POC working previously: sveltejs/kit#3324 (comment)

Alternatives considered

No response

Importance

nice to have

Additional Information

No response

Activity

  1. transferred this issue fromsveltejs/kiton Oct 26, 2024
  2. transferred this issue fromsveltejs/svelteon Oct 26, 2024
  3. jasonlyu123 commented on Oct 26, 2024

    @jasonlyu123
    Member

    Right, I never followed up on this. At some point, the POC became overly complicated when new stuff was added to the kit docs. The biggest issue is supporting the // ---cut--- comment as the script tag needs to be partly cut so source-map is harder. There is also some ts diagnostics error in svelte2tsx generated code that needs to be filtered out in a weird way and also requires a different sourcemap. So there are like a total of 3 or 4 kinds of sourcemap.

  4. teemingc commented on Oct 26, 2024

    @teemingc
    Member

    I assumed this was working when I saw the hover tooltips on variables for the new svelte site https://svelte.dev/docs/svelte/$state . I think I misunderstood since those blocks were JS only. Svelte blocks still don't have them.

  5. jasonlyu123 commented on Oct 26, 2024

    @jasonlyu123
    Member

    Yeah. the library only works with ts/js so there isn't hover info in the svelte file. There is now a twoslash vue and eslint so maybe there would be more stuff added to the base library making it easier and not needing so many layers of source map.

  6. Hugos68 commented on Oct 31, 2024

    @Hugos68

    I've made some efforts to build twoslash/svelte as a project for the upcoming Svelte hackathon:

    If this is something that you think will be valueable to the docs I will gladly submit a PR to add twoslash to .svelte blocks. It has 100% feature parity, so highlights, hovers, queries, cutted blocks etc all works.
    Just note that the PR is still just a PR so the package isn't out yet.

    This is how it looks for example:
    {F4824DA9-4F0F-4065-9C87-FE20D3824F2E}

  7. huntabyte commented on Oct 31, 2024

    @huntabyte
    Member

    @Hugos68 I have been patiently waiting for someone to build a Svelte integration for this for quite some time. This is incredible and will benefit not only the svelte.dev site but the entire ecosystem of Svelte libraries 💪 incredible job!

  8. Rich-Harris commented on Nov 5, 2024

    @Rich-Harris
    MemberAuthor

    If this is something that you think will be valueable to the docs I will gladly submit a PR to add twoslash to .svelte blocks

    This would be incredible, thank you!

  9. Hugos68 commented on Nov 5, 2024

    @Hugos68

    Sure thing, once twoslash-svelte gets merged into twoslash I'll submit a PR 👍

  10. added theissue type on Feb 24, 2026
  11. teemingc commented on Sep 30, 2026

    @teemingc
    Member

    We've switched to Twinkleplop and should probably use its svelte-twoslash package https://twinkleplop.pngwn.workers.dev/docs/twoslash

  12. linked a pull request that will close this issuefeat: add Svelte Twoslash hover tooltips #2272on Oct 1, 2026
  13. Hugos68 commented on Oct 1, 2026

    @Hugos68

    @teemingc That's awesome! looks like a great package that filled the gap we needed to be filled. Thanks for notifiying me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions