Skip to content

Commit 6b0f46f

Browse files
authored
Merge pull request #98 from alioso/CT-995
CT-995 better handling of description code blocks
2 parents b5215fd + 329979f commit 6b0f46f

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/css/components/0_utilities/typography.css

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ input[type="text"] {
2222
@apply p-4 mt-2 mb-2 bg-ThemeBeige block;
2323
}
2424

25-
.api-body pre code {
26-
@apply p-2 mt-2 mb-4 bg-ThemeBeige block;
27-
overflow-x: auto;
28-
}
29-
30-
.api-body code {
31-
@apply p-1 bg-ThemeBeige;
32-
}
33-
3425
.api-desc code {
3526
@apply font-normal px-1 bg-ThemeTagGrey inline text-xs relative;
3627
padding-top: 4px;

src/pages/api/v4.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React from "react";
22
// import PropTypes from "prop-types";
33
import { graphql, StaticQuery } from "gatsby";
44
import Markdown from "react-markdown/with-html";
5+
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
6+
import { atomDark } from "react-syntax-highlighter/dist/esm/styles/prism";
57

68
import Layout from "../../components/4_layouts/layout";
79
import SEO from "../../components/0_utilities/seo";
@@ -27,6 +29,25 @@ const HeadingRenderer = props => {
2729
return <Heading {...props} />;
2830
};
2931

32+
class CodeBlock extends React.PureComponent {
33+
render() {
34+
const { value } = this.props;
35+
36+
return (
37+
<SyntaxHighlighter
38+
language="shell"
39+
style={atomDark}
40+
className="api-samples"
41+
codeTagProps={{
42+
style: { whiteSpace: "pre-wrap" }
43+
}}
44+
>
45+
{value}
46+
</SyntaxHighlighter>
47+
);
48+
}
49+
}
50+
3051
class APIDocs extends React.Component {
3152
componentDidMount() {
3253
window.addEventListener("scroll", () => {
@@ -58,7 +79,7 @@ class APIDocs extends React.Component {
5879
<Markdown
5980
source={n.info.description}
6081
escapeHtml={false}
61-
renderers={{ heading: HeadingRenderer }}
82+
renderers={{ heading: HeadingRenderer, code: CodeBlock }}
6283
className="md:mt-8 api-body"
6384
/>
6485
</div>

0 commit comments

Comments
 (0)