Git Product home page Git Product logo

storybook-addon-markdown-docs's Introduction

Storybook addon markdown docs

Write storybook docs using regular markdown.

Warning: this project is still an experiment, not all features are supported. Join the discussion in the issues.

Writing docs

You can write documentation using regular markdown, this is converted to HTML and rendered in a storybook docs tab.

Writing code

To write code inside your docs you can write module scripts. All module scripts on the page are combined into one module, imports and variables between scripts are shared.

You will always need to provide at least a default export with the title of your docs page, and you will need to import any dependencies used in your stories.

<script type="module">
  import { html } from '@open-wc/demoing-storybook';

  export default { title: 'Elements/Button' };
</script>

Module scripts can give problems with some markdown renderers or code formatters like prettier. They can be aliased using a fenced codeblock with a type that ends with script. For example js script or ts script:

<docs-story>

\`\`\`js script
export const MyStory = () => html`<my-element></my-element>`;
\`\`\`

</docs-story>

Writing inline stories

Stories can be written inline using docs-story elements.

The embedded story can be plain HTML:

<docs-story name="My Story">
  <my-element></my-element>
</docs-story>

Or an embedded script:

<docs-story>
  <script type="module">
    export const MyStory = () => html`
      <my-element></my-element>
    `;
  </script>
</docs-story>

Or using a js script codeblock:

<docs-story>

\`\`\`js script
export const MyStory = () => html`<my-element></my-element>`;
\`\`\`

</docs-story>

Ussage

open-wc

To use this addon with @open-wc/demoing-storybook, add this main.js:

const { markdownToStories } = require('storybook-addon-markdown-docs');

module.exports = {
  stories: ['./stories/*.stories.{js,md}'],
  esDevServer: {
    fileExtensions: ['.js', '.mjs', '.md'],
    responseTransformers: [
      async function mdToStories({ url, body }) {
        const cleanURL = url.split('?')[0].split('#')[0];

        if (cleanURL.endsWith('md')) {
          return { body: await markdownToStories(body) };
        }
      },
    ],
  },
};

Regular storybook

To use this addon with regular storybook, you need to add a webpack transformation step. We don't have any defaults for this yet.

storybook-addon-markdown-docs's People

Contributors

larsdenbakker avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.