Skip to content

Commit 3eaa717

Browse files
committed
fix: add markdown code syntax highlighting
1 parent 73bc50e commit 3eaa717

File tree

5 files changed

+47
-40
lines changed

5 files changed

+47
-40
lines changed

package-lock.json

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"react-dom": "^16.12.0",
2727
"react-json-view": "^1.19.1",
2828
"react-markdown": "^4.0.6",
29-
"react-syntax-highlighter": "^15.3.0"
29+
"react-syntax-highlighter": "^15.4.3"
3030
},
3131
"devDependencies": {
3232
"@open-rpc/meta-schema": "^1.11.0",

src/ExamplePairing/ExamplePairing.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from "react";
22
import Grid from "@material-ui/core/Grid";
3-
import { Card, CardContent, Theme, withStyles, WithStyles } from "@material-ui/core";
3+
import { Card, CardContent, CardHeader, Theme, withStyles, WithStyles } from "@material-ui/core";
44
import ReactJson from "react-json-view";
55
import ReactMarkdown from "react-markdown";
66
import { ExampleObject, ExamplePairingObject } from "@open-rpc/meta-schema";
@@ -48,8 +48,9 @@ class ExamplePairing extends Component<IProps, {}> {
4848
className={classes.description}
4949
/>
5050
</Grid>
51-
<Grid item xs={6}>
51+
<Grid item xs={12} sm={6}>
5252
<Card>
53+
<CardHeader title="Request"></CardHeader>
5354
<CardContent>
5455
{examplePairing.params && <ReactJson src={{
5556
id: 1,
@@ -60,7 +61,8 @@ class ExamplePairing extends Component<IProps, {}> {
6061
</CardContent>
6162
</Card>
6263
</Grid>
63-
<Grid item xs={6}>
64+
<Grid item xs={12} sm={6}>
65+
<CardHeader title="Result"></CardHeader>
6466
<Card>
6567
<CardContent>
6668
{examplePairing.result && <ReactJson src={{

src/MarkdownDescription/MarkdownDescription.tsx

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,34 @@ import React from "react";
22
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
33
import { materialDark, materialLight } from "react-syntax-highlighter/dist/esm/styles/prism";
44
import ReactMarkdown from "react-markdown";
5-
import { MethodObject } from "@open-rpc/meta-schema";
5+
import { Container } from "@material-ui/core";
66

77
interface IProps {
88
className?: string;
99
source?: string;
1010
uiSchema: any;
1111
}
1212

13-
const MarkdownDescription: React.FC<IProps> = ({source, className, uiSchema}) => {
14-
return (
15-
<ReactMarkdown
16-
renderers={{
17-
code: ({ language, value }) => {
18-
return <SyntaxHighlighter
19-
style={uiSchema && uiSchema.appBar["ui:darkMode"] ? materialDark : materialLight}
20-
language={language}
21-
children={value}
22-
/>;
23-
},
24-
}}
25-
source={source}
26-
className={className}
27-
/>
28-
);
13+
const MarkdownDescription: React.FC<IProps> = ({ source, className, uiSchema }) => {
14+
try {
15+
return (
16+
<ReactMarkdown
17+
renderers={{
18+
code: ({ language, value }) => {
19+
return <SyntaxHighlighter
20+
style={uiSchema && uiSchema.appBar["ui:darkMode"] ? materialDark : materialLight}
21+
language={language}
22+
children={value}
23+
/>;
24+
},
25+
}}
26+
source={source}
27+
className={className}
28+
/>
29+
);
30+
} catch (e) {
31+
return <ReactMarkdown source={source} className={className} />;
32+
}
2933
};
3034

3135
export default MarkdownDescription;

src/Methods/Methods.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import MarkdownDescription from "../MarkdownDescription/MarkdownDescription";
2525
const styles = (theme: Theme) => ({
2626
description: {
2727
color: theme.palette.text.primary,
28+
width: "100%",
2829
},
2930
heading: {
3031
flexBasis: "33.33%",

0 commit comments

Comments
 (0)