@beeq/storybook-addon-html

中文文档
7.0.0发布于 2026/02/02AGPL-3.0-or-laterTypeScriptES Module零依赖近 30 天下载 3292

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

原始使用文档
文档目录7 节
  1. Requirements
  2. Storybook 10.x
  3. Storybook 9.x
  4. Storybook 8.x
  5. Getting Started
  6. Register addon
  7. Usage

Storybook Addon HTML

This addon for Storybook adds a tab that displays the compiled HTML for each story.

Animated preview

Requirements

Storybook 10.x

Use version 9.x of this addon.

Storybook 9.x

Use version 8.x of this addon.

Storybook 8.x

Use version 7.x of this addon.

Getting Started

Install the addon and its dependencies.

With NPM:

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

With Yarn:

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

With PNPM:

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

Register addon

// .storybook/main.js

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

Usage

You can override the wrapper element selector used to grab the component HTML.

export const parameters = {
  html: {
    root: '#my-custom-wrapper', // default: #root
  },
};

Some frameworks put comments inside the HTML. If you want to remove these you can use the removeComments parameter. Set it to true to remove all comments or set it to a regular expression that matches the content of the comments you want to remove.

export const parameters = {
  html: {
    removeComments: /^\s*remove me\s*$/, // default: false
  },
};

You can also use the removeEmptyComments parameter to remove only empty comments like <!----> and <!-- -->.

export const parameters = {
  html: {
    removeEmptyComments: true, // default: false
  },
};

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
    },
  },
};

Another way of hiding unwanted code is to define the transform option. It allows you to perform any change to the output code, e.g. removing attributes injected by frameworks.

html: {
  transform: (code) => {
    // Remove attributes `_nghost` and `ng-reflect` injected by Angular:
    return code.replace(/(?:_nghost|ng-reflect).*?="[\S\s]*?"/g, '');
  };
}

You can disable the HTML panel by setting the disable parameter to true. This will hide and disable the HTML addon in your stories.

html: {
  disable: true, // default: false
}

版本与发布记录

@beeq/storybook-addon-html 共发布 3 个版本,首次发布于 2024/03/19;过去 12 个月发布了 1 个版本。

版本发布日期距今
7.0.0latest2026/02/029 个月前
6.0.02024/03/192 年前
5.1.72024/03/192 年前

关于 @beeq/storybook-addon-html 的常见问题

@beeq/storybook-addon-html 是什么?

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

如何安装 @beeq/storybook-addon-html?

在项目目录运行 npm install @beeq/storybook-addon-html,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:storybook(^10.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@beeq/storybook-addon-html 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@beeq/storybook-addon-html 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@beeq/storybook-addon-html 可以商用吗?

@beeq/storybook-addon-html 使用 AGPL-3.0-or-later 许可。最严格的 Copyleft:除分发外,通过网络向用户提供基于它的服务也需要开源对应源码。闭源 SaaS 使用前务必评估。以上为概括,不构成法律意见,请以许可原文为准。

@beeq/storybook-addon-html 的下载量有多少?

根据 npm 官方下载统计,@beeq/storybook-addon-html 在 2026/10/08 – 2026/11/06 这 30 天内被下载 3,292 次,日均约 110 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@beeq/storybook-addon-html 还在维护吗?

最新版本 7.0.0 发布于 2026/02/02(9 个月前);至今共发布 3 个版本,其中过去 12 个月发布了 1 个;首次发布于 2024/03/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。