Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

A Storybook addon that extracts and displays compiled syntax-highlighted HTML

License

Notifications You must be signed in to change notification settings

lmestel/storybook-addon-html

 
 

Repository files navigation

Moved to https://github.com/kickstartDS/storybook-addon-html


Storybook Addon HTML

This addon for Storybook adds a tab that displays the compiled HTML for each story. It uses highlight.js for syntax highlighting.

Animated preview

Getting Started

With NPM:

npm i --save-dev @whitespace/storybook-addon-html

With Yarn:

yarn add -D @whitespace/storybook-addon-html

Register addon

// .storybook/main.js

module.exports = {
  // ...
  addons: [
    '@whitespace/storybook-addon-html',
    // ...
  ],
};

Usage

The HTML is formatted with Prettier. You can override the Prettier config (except parser and plugins) by providing an object following the Prettier API override format in the html parameter:

// .storybook/preview.js

export const parameters = {
  // ...
  html: {
    prettier: {
      tabWidth: 4,
      useTabs: false,
      htmlWhitespaceSensitivity: 'strict',
    },
  },
};

You can override the showLineNumbers and wrapLines settings for the syntax highlighter by using the highlighter parameter:

export const parameters = {
  html: {
    highlighter: {
      showLineNumbers: true, // default: false
      wrapLines: false, // default: true
    },
  },
};

You can add a decorator to wrap the story:

export const parameters = {
  html: {
    decorator: (Story, context) => (
      <MyProvider>
        <Story {...context}>
      </MyProvider>
    )
  },
};

Supported frameworks

As of version 4.0.0 all frameworks are supported per default 🎉

About

A Storybook addon that extracts and displays compiled syntax-highlighted HTML

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%