storybookjs / frontpage

🌐 The website for storybook.js.org
https://storybook.js.org
MIT License
212 stars 116 forks source link

Handle snippets with multiple code blocks #644

Closed kylegach closed 7 months ago

kylegach commented 7 months ago

What I did

This fix effectively stitches together a snippet that contains multiple code blocks, like this:

```js
// Button.stories.js

import Button from './Button.svelte';
import MarginDecorator from './MarginDecorator.svelte';

export default {
  component: Button,
  decorators: [() => MarginDecorator],
};

// Your stories here.

// Don't forget to use the component you're testing and not the MarginDecorator component
<!-- MarginDecorator.svelte -->

<div>
  <slot />
</div>

<style>
  div {
    margin: 3em;
  }
</style>

Into a unified code block, using the language of the first one:

````mdx
```js
// Button.stories.js

import Button from './Button.svelte';
import MarginDecorator from './MarginDecorator.svelte';

export default {
  component: Button,
  decorators: [() => MarginDecorator],
};

// Your stories here.

// Don't forget to use the component you're testing and not the MarginDecorator component

<!-- MarginDecorator.svelte -->

<div>
  <slot />
</div>

<style>
  div {
    margin: 3em;
  }
</style>


The end result then displays like:

<img width="622" alt="" src="https://github.com/storybookjs/frontpage/assets/486540/e3311c6a-7187-426e-b33d-f9723c1b12c2">

The syntax highlighting for the second portion is not perfect. This solution compromises that for simplicity of implementation, as there are currently only two examples of multi-code block snippets.

### How to test

There are literally only two snippets that meet the criteria requiring this fix and they're both on the `/writing-stories/decorators` page and apply to the Svelte renderer.

1. Open the [deploy preview's Decorators page](https://deploy-preview-644--storybook-frontpage.netlify.app/docs/writing-stories/decorators)
1. Confirm that the snippets look correct
1. Select the Svelte renderer
1. Confirm that these snippets look correct
    1. Under the [**Wrap stories with extra markup** heading](https://deploy-preview-644--storybook-frontpage.netlify.app/docs/writing-stories/decorators#wrap-stories-with-extra-markup)
    1. Under the [**Component decorators** heading](https://deploy-preview-644--storybook-frontpage.netlify.app/docs/writing-stories/decorators#component-decorators)
netlify[bot] commented 7 months ago

Deploy Preview for storybook-frontpage ready!

Name Link
Latest commit 5fc6ebea2bb89e135b1e53b7885c34ce79554ad0
Latest deploy log https://app.netlify.com/sites/storybook-frontpage/deploys/656f631f35b8a70008e2ae96
Deploy Preview https://deploy-preview-644--storybook-frontpage.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

ShaunEvening commented 7 months ago

I think that this is a good way to solve the problem as it is but I think we should re-work this page in the most recent docs to split this into two separate snippets with the IfRenderer