Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxHighlighter: Expose registerLanguage #23166

Merged
merged 14 commits into from
Jul 5, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { ThemeProvider, ensure, themes } from '@storybook/theming';

import type { ComponentProps } from 'react';
import React from 'react';
import { ThemeProvider, themes, ensure } from '@storybook/theming';
import scss from 'react-syntax-highlighter/dist/esm/languages/prism/scss';
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
import { SyntaxHighlighter } from './lazy-syntaxhighlighter';

// Register custom language
SyntaxHighlighter.registerLanguage('scss', scss);
Copy link
Member Author

@ndelangen ndelangen Jul 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be done, as the story renders, a custom render function would allow us to do that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, gotcha. Let me try that. 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realize I'm reading too quickly and did this in a custom loader instead of render func in a9d0d22. The loader works, but let me know if you'd prefer I go the render route. Happy to rewrite.


export default {
component: SyntaxHighlighter,
};
Expand Down Expand Up @@ -108,6 +113,18 @@ export const GraphQL = {
},
};

export const CustomSyntax = {
args: {
language: 'scss',
children: `// Custom language syntax registered
div.parent {
div.child {
color: $red;
}
}`,
},
};

export const Unsupported = {
args: {
language: 'C#',
Expand Down