Skip to content

Commit

Permalink
Export SupportedLanguage and add plaintext support for SyntaxHighlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed May 25, 2023
1 parent 324279b commit 1d3e176
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions code/ui/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type {
SyntaxHighlighterFormatTypes,
SyntaxHighlighterProps,
SyntaxHighlighterRendererProps,
SupportedLanguage,
} from './syntaxhighlighter/syntaxhighlighter-types';
export { SyntaxHighlighter } from './syntaxhighlighter/lazy-syntaxhighlighter';
export { createCopyToClipboardFunction } from './syntaxhighlighter/syntaxhighlighter';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ export interface SyntaxHighlighterBaseProps {
useInlineStyles?: boolean;
}

export type SupportedLanguage = keyof typeof supportedLanguages;

export type SyntaxHighlighterProps = SyntaxHighlighterBaseProps & SyntaxHighlighterCustomProps;
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import md from 'react-syntax-highlighter/dist/esm/languages/prism/markdown';
import yml from 'react-syntax-highlighter/dist/esm/languages/prism/yaml';
import tsx from 'react-syntax-highlighter/dist/esm/languages/prism/tsx';
import typescript from 'react-syntax-highlighter/dist/esm/languages/prism/typescript';
import plaintext from 'react-syntax-highlighter/dist/esm/languages/hljs/plaintext';

import ReactSyntaxHighlighter from 'react-syntax-highlighter/dist/esm/prism-light';
// @ts-expect-error (Converted from ts-ignore)
Expand Down Expand Up @@ -45,6 +46,7 @@ export const supportedLanguages = {
tsx,
typescript,
graphql,
plaintext,
};

Object.entries(supportedLanguages).forEach(([key, val]) => {
Expand Down
3 changes: 2 additions & 1 deletion code/ui/components/src/typography/elements/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { Children } from 'react';
import { SyntaxHighlighter } from '../../syntaxhighlighter/syntaxhighlighter';
import { isReactChildString } from '../lib/isReactChildString';
import { codeCommon } from '../lib/common';
import type { SupportedLanguage } from '../../syntaxhighlighter/syntaxhighlighter-types';

const isInlineCodeRegex = /[\n\r]/g;

Expand Down Expand Up @@ -60,7 +61,7 @@ export const Code = ({
<StyledSyntaxHighlighter
bordered
copyable
language={(language?.[1] as any) ?? 'plaintext'}
language={(language?.[1] as SupportedLanguage) ?? 'plaintext'}
format={false}
{...props}
>
Expand Down

0 comments on commit 1d3e176

Please sign in to comment.