mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 00:26:34 +03:00
fix: highlight text syntax (#2069)
This commit is contained in:
parent
f8c30e5e57
commit
4fc6aa0859
|
@ -9,24 +9,21 @@ export interface SourceCodeProps {
|
|||
lang: string;
|
||||
}
|
||||
|
||||
export class SourceCode extends React.PureComponent<SourceCodeProps> {
|
||||
render() {
|
||||
const { source, lang } = this.props;
|
||||
return <StyledPre dangerouslySetInnerHTML={{ __html: highlight(source, lang) }} />;
|
||||
}
|
||||
}
|
||||
export const SourceCode = (props: SourceCodeProps) => {
|
||||
const { source, lang } = props;
|
||||
return <StyledPre dangerouslySetInnerHTML={{ __html: highlight(source, lang) }} />;
|
||||
};
|
||||
|
||||
export class SourceCodeWithCopy extends React.Component<SourceCodeProps> {
|
||||
render() {
|
||||
return (
|
||||
<CopyButtonWrapper data={this.props.source}>
|
||||
{({ renderCopyButton }) => (
|
||||
<SampleControlsWrap>
|
||||
<SampleControls>{renderCopyButton()}</SampleControls>
|
||||
<SourceCode lang={this.props.lang} source={this.props.source} />
|
||||
</SampleControlsWrap>
|
||||
)}
|
||||
</CopyButtonWrapper>
|
||||
);
|
||||
}
|
||||
}
|
||||
export const SourceCodeWithCopy = (props: SourceCodeProps) => {
|
||||
const { source, lang } = props;
|
||||
return (
|
||||
<CopyButtonWrapper data={source}>
|
||||
{({ renderCopyButton }) => (
|
||||
<SampleControlsWrap>
|
||||
<SampleControls>{renderCopyButton()}</SampleControls>
|
||||
<SourceCode lang={lang} source={source} />
|
||||
</SampleControlsWrap>
|
||||
)}
|
||||
</CopyButtonWrapper>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -13,6 +13,7 @@ import {
|
|||
humanizeNumberRange,
|
||||
getContentWithLegacyExamples,
|
||||
getDefinitionName,
|
||||
langFromMime,
|
||||
} from '../';
|
||||
|
||||
import { FieldModel, OpenAPIParser, RedocNormalizedOptions } from '../../services';
|
||||
|
@ -1320,4 +1321,18 @@ describe('Utils', () => {
|
|||
expect(getDefinitionName()).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('langFromMime', () => {
|
||||
test('should return correct lang name from content type', () => {
|
||||
expect(langFromMime('application/xml')).toEqual('xml');
|
||||
expect(langFromMime('application/x-xml')).toEqual('xml');
|
||||
expect(langFromMime('application/csv')).toEqual('csv');
|
||||
expect(langFromMime('application/x-csv')).toEqual('csv');
|
||||
expect(langFromMime('text/plain')).toEqual('tex');
|
||||
expect(langFromMime('text/x-plain')).toEqual('tex');
|
||||
expect(langFromMime('application/plain')).toEqual('tex');
|
||||
|
||||
expect(langFromMime('text/some-type')).toEqual('clike');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -21,6 +21,7 @@ import 'prismjs/components/prism-scala.js';
|
|||
import 'prismjs/components/prism-sql.js';
|
||||
import 'prismjs/components/prism-swift.js';
|
||||
import 'prismjs/components/prism-yaml.js';
|
||||
import 'prismjs/components/prism-csv.js';
|
||||
|
||||
const DEFAULT_LANG = 'clike';
|
||||
|
||||
|
|
|
@ -395,6 +395,15 @@ export function langFromMime(contentType: string): string {
|
|||
if (contentType.search(/xml/i) !== -1) {
|
||||
return 'xml';
|
||||
}
|
||||
|
||||
if (contentType.search(/csv/i) !== -1) {
|
||||
return 'csv';
|
||||
}
|
||||
|
||||
if (contentType.search(/plain/i) !== -1) {
|
||||
return 'tex';
|
||||
}
|
||||
|
||||
return 'clike';
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user