Skip to content

[Documentation]: FAQ: Adding new languages to the syntax highlighter is no longer an issue #25307

@Clindbergh

Description

@Clindbergh

Describe the problem

Currently the FAQ states

Why aren't my code blocks highlighted with Storybook MDX
Out of the box, Storybook provides syntax highlighting for a set of languages (e.g., Javascript, Markdown, CSS, HTML, Typescript, GraphQL) you can use with your code blocks. Currently, there's a known limitation when you try and register a custom language to get syntax highlighting. We're working on a fix for this And will update this section once it's available.
https://storybook.js.org/docs/faq#why-arent-my-code-blocks-highlighted-with-storybook-mdx

Thanks to #23166 / #19794 / #21341 this is no longer an issue.

With storybook 7.6.3 and these packages

    "@types/react-syntax-highlighter": "^15.5.11",
    "react-syntax-highlighter": "^15.5.0",

this code in preview.ts

import scss from 'react-syntax-highlighter/dist/esm/languages/prism/scss';

SyntaxHighlighter.registerLanguage('scss', scss);

enables code highlighting in mdx:

@import '../../../src/lib/scss/variables';

.clazz {
  background-color: $ultra-fancy-blue;
}

Additional context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions