
Security News
Opengrep Adds Apex Support and New Rule Controls in Latest Updates
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
@whitespace/storybook-addon-code
Advanced tools
A Storybook addon that extracts and displays syntax-highlighted source code
This addon for Storybook allows you to display the source code for your components. It uses highlight.js for syntax highlighting. Available languages are listed here.
NOTE: This addon can only be used with the new Component Story Format (CSF) introduced in Storybook 5.2.
npm i --save-dev @whitespace/storybook-addon-code
Create a file called addons.js
in your storybook config and add the following content:
import registerAddonCode from '@whitespace/storybook-addon-code/register';
registerAddonCode({
tabs: [
{ label: 'Twig', lang: 'twig' },
{ label: 'Sass', lang: 'scss' },
{ label: 'JavaScript', lang: 'javascript', matchFiles: 'js' },
],
});
tabs
should be an array with objects for each tab you want to add to the addon panel. Each object can contain these properties:
label
: The displayed label on the tab.lang
: The language as defined by highlight.js. Available languages are listed herematchFiles
: Optional. Defaults to the same value as lang
. Can be a string representing the file extension for files that should be included. Can also be a regular expression to test the filename against. Can also be function that receives the filename and returns true or false.Update or create webpack.config.js
inside your .storybook
directory by adding require.resolve('@whitespace/storybook-addon-code/loader')
as a pre-loader to .stories.js
files as shown below.
module.exports = async ({ config, mode }) => {
// ...
config.module.rules.push({
test: /\.stories\.jsx?$/,
loaders: [
/*
This loader should be first in the list unless you
want tranfromations from other loaders to affect
what’s shown in the code tabs
*/
require.resolve('@whitespace/storybook-addon-code/loader'),
// ...
],
enforce: 'pre',
});
// ...
// Return the altered config
return config;
};
The imported files inside the .stories.js
file that matches the registered tabs will be extracted automatically. Install and use null-loader to include files that are not required by the actual stories file.
import Component from './button.twig';
import '!!null-loader!./button.scss';
export default {
title: 'Example button',
};
export const withUrl = () =>
Component({
text: 'Lorem ipsum',
url: '#',
});
export const withoutUrl = () =>
Component({
text: 'Lorem ipsum',
});
FAQs
A Storybook addon that extracts and displays syntax-highlighted source code
The npm package @whitespace/storybook-addon-code receives a total of 32 weekly downloads. As such, @whitespace/storybook-addon-code popularity was classified as not popular.
We found that @whitespace/storybook-addon-code demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.