vitepress icon indicating copy to clipboard operation
vitepress copied to clipboard

Sync code group selection

Open re-ovo opened this issue 2 years ago • 6 comments

Is your feature request related to a problem? Please describe.

In many cases, developers will provide code groups for multiple programming languages at the same time. I hope that after the user switches one, other code groups can automatically follow, and it is best to be persistent.

https://github.com/vuejs/vitepress/issues/2773, a solution is proposed here, but I don't think it's good enough

  1. Only supports tab, but code group needs it more
  2. This is a very commonly used feature, I think it should be officially supported, not by a plugin

Describe the solution you'd like

::: code-group

```js [config.js] :js <-- key const config = { // ... }

export default config ```

```ts [config.ts] :ts import type { UserConfig } from 'vitepress'

const config: UserConfig = { // ... }

export default config ```

:::

Describe alternatives you've considered

No response

Additional context

No response

Validations

re-ovo avatar Sep 13 '23 06:09 re-ovo

Only supports tab, but code group needs it more.

Can you elaborate more on this point.

brc-dd avatar Sep 25 '23 18:09 brc-dd

Only supports tab, but code group needs it more.

Can you elaborate more on this point.

Will using tabs give me the same appearance as code groups? I noticed that the code block on your site has a white background

截屏2023-09-26 09 14 03

re-ovo avatar Sep 26 '23 01:09 re-ovo

+1 from me. I was excited to use code groups, but find them useless without synchronisation.

@re-ovo FYI: I added the following styles to make tabs look more like code groups:

.plugin-tabs--content {
    padding: 0px !important;
}

.plugin-tabs--content div[class*='language-'] {
    background-color: var(--vp-code-block-bg) !important;
    border-radius: 0 !important;
}

svanimpe avatar Jan 13 '24 18:01 svanimpe

+1, It would be great to have code group syncing as a core feature, like it is in docusaurus.

Lehoczky avatar Feb 25 '24 07:02 Lehoczky

Came here looking for this, would love to see it added!

maxnorth avatar Jul 02 '24 15:07 maxnorth

+1 for this feature, much needed for documentation pages!

everdrone avatar Aug 18 '24 13:08 everdrone