storybook icon indicating copy to clipboard operation
storybook copied to clipboard

Source Doc Block - JavaScript not formatting properly

Open dungle-scrubs opened this issue 2 years ago • 0 comments

When building a docs page and using <Source /> with JavaScript via the code prop and using a template literal, it breaks when there's a line break in a specific location.

For example, here there is a line break above return,

<Source
  language="javascript"
  dark
  format={true}
  code={dedent`
const ParentComponent = () => {
  const [isOpen, setIsOpen] = useState(false);
  const handleClick = () => {
    setIsOpen(true);
  };

  return (
  <>
    <Button onClick={handleClick}>Controlled toast</Button>
    <Toast isOpen={isOpen} onOpenChange={setIsOpen} />
  </>
); } `}
/>

Which leads to the error:

CleanShot 2022-09-19 at 13 05 12@2x

However, when removing the line break, it renders properly.

If the line break is right below return, it still renders properly.

Note: This happens with or without dedent.

Cheers

dungle-scrubs avatar Sep 19 '22 06:09 dungle-scrubs