In Storybook v8, it properly removes whitespace and newlines attributes when appropriate:
\nIn Storybook v9, looks like neither of those are happening:
\nAny help is appreciated!
\nstorybook 9.0.15
\nangular 19.2.6
import type { StorybookConfig } from '@storybook/angular';\n\nconst config: StorybookConfig = {\n stories: [\n '../src/lib/**/*.mdx',\n '../src/lib/**/*.stories.@(js|jsx|mjs|ts|tsx)',\n ],\n addons: [\n '@chromatic-com/storybook',\n '@storybook/addon-themes',\n '@storybook/addon-designs',\n '@storybook/addon-docs',\n ],\n framework: {\n name: '@storybook/angular',\n options: {},\n },\n staticDirs: ['./static'],\n};\n\nexport default config;
No response
","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"@dosu thanks for the quick reply! I went with Prettier since I've already got it installed. Looks like the formatting is back to how it was before.
\nformatCode.ts
\nimport * as prettier from 'prettier/standalone';\nimport * as prettierPluginHtml from 'prettier/plugins/html';\n\nexport async function formatCode(code: string) {\n return await prettier.format(code, {\n parser: 'angular',\n plugins: [prettierPluginHtml],\n });\n}
preview.ts
\ndocs: {\n source: {\n transform: async (code: string) => {\n return await formatCode(code);\n },\n },\n}
Appreciate the help!
","upvoteCount":0,"url":"https://github.com/storybookjs/storybook/discussions/32008#discussioncomment-13723716"}}}-
Beta Was this translation helpful? Give feedback.
-
Hi @cocco3! I'm Dosu and I’m helping the storybook team. Storybook v9 changed how it formats and sanitizes Angular source code for display in Docs, which can affect whitespace and attribute cleanup compared to v8. The formatting pipeline now relies on internal sanitization utilities, and the default behavior may not strip whitespace/newlines as before. You can override or post-process the displayed source using the export const MyButton = {
// ...your story config
parameters: {
docs: {
source: {
transform: (code) =>
code
// Remove leading/trailing whitespace on each line
.split('\n').map(line => line.trim()).join('\n')
// Remove empty lines
.replace(/^\s*$(?:\r\n?|\n)/gm, ''),
},
},
},
}; You can adjust the transform function to fit your formatting needs. This approach works per-story or can be applied globally via preview parameters. The transform runs after Storybook’s internal sanitization, so you have full control over the final output shown in Docs and the code panel. For more details, see the implementation in If you need to exactly match v8’s formatting, you may need to experiment with your transform function to replicate the previous whitespace and attribute handling. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
@dosu thanks for the quick reply! I went with Prettier since I've already got it installed. Looks like the formatting is back to how it was before.
formatCode.ts
preview.ts
Appreciate the help!