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

@shikijs/transformers: add transformerFold #861

Open
4 tasks done
typed-sigterm opened this issue Dec 7, 2024 · 7 comments
Open
4 tasks done

@shikijs/transformers: add transformerFold #861

typed-sigterm opened this issue Dec 7, 2024 · 7 comments

Comments

@typed-sigterm
Copy link

Clear and concise description of the problem

Just like folding in Monaco Editor:

image

It's useful when the codeblock is large.

Can we have this?

Suggested solution

Add a transformer transformerFold to @shikijs/transformers

**Shiki Style Syntax**:

```ts
// [!code fold:start] variables
let a = 1

// [!code fold:start] variable b
let b = 1
// [!code fold:end]

// [!code fold:end]

console.log(a, b)
```

**Monaco Style Syntax**:

```ts
// #region variables
let a = 1

// #region variable b
let b = 1
// #endregion

// #endregion

console.log(a, b)
```

Render to:

image

Alternative

No response

Additional context

No response

Validations

Contributes

  • If this feature request is accepted, I am willing to submit a PR to fix this issue
@antfu
Copy link
Member

antfu commented Dec 10, 2024

That's interesting, I love that idea! I would love to see how you implement it, let's see the PR!

@typed-sigterm
Copy link
Author

I'm sorry that I'm preparing for 中考 and may not have time to implement this :(

@Fro-Q
Copy link

Fro-Q commented Feb 7, 2025

I will try to implement this one.

@Codingmaster123fe
Copy link

I think that will work in my opinion because I had the same issue to

@candle-admin
Copy link

This would be super useful!

@Fro-Q
Copy link

Fro-Q commented Feb 16, 2025

I’ve implemented this feature, but the approach is somewhat unconventional, and the code is a bit messy due to limited technical skills. So there won’t be a PR. However, you can check out this repo and use it in VitePress as a customTransformer.

If anyone has a better implementation or would like to discuss my messy approach further, feel free to reach out.

@typed-sigterm
Copy link
Author

Maybe <details> can be used to avoid injecting JS.

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

No branches or pull requests

5 participants