Skip to content

Commit 32a76ea

Browse files
committed
Allow to use custom language in code snippets
1 parent 0f607f9 commit 32a76ea

File tree

4 files changed

+38
-35
lines changed

4 files changed

+38
-35
lines changed

packages/react-renderer-demo/src/app/pages/renderer/development-setup.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ Data Driven Forms is a monorepo which uses [Lerna](https://github.com/lerna/lern
1111

1212
## Install
1313

14-
```console
14+
```sh
1515
yarn install
1616
```
1717

1818
## Build
1919

20-
```console
20+
```sh
2121
yarn build
2222
```
2323

@@ -29,7 +29,7 @@ Don't forget to build all packages, which are linked together!
2929

3030
Each package has a small playground `package/demo`, where you can test your changes.
3131

32-
```console
32+
```sh
3333
cd packages/pf3-component-mapper
3434
yarn start
3535
```
@@ -38,14 +38,14 @@ yarn start
3838

3939
The documentation is a server-side rendered React application based on [NextJS framework](https://nextjs.org/).
4040

41-
```console
41+
```sh
4242
cd packages/react-renderer-demo
4343
yarn dev
4444
```
4545

4646
## How to clean?
4747

48-
```console
48+
```sh
4949
rm yarn.lock
5050
yarn lerna clean # will delete all node_modules
5151
```
@@ -54,7 +54,7 @@ yarn lerna clean # will delete all node_modules
5454

5555
Tests needed to be run from the core folder.
5656

57-
```console
57+
```sh
5858
yarn test
5959

6060
yarn test packages/pf3-component-mapper

packages/react-renderer-demo/src/app/pages/renderer/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import ListOfContents from '../../src/helpers/list-of-contents';
77

88
# Installation
99

10-
```console
10+
```sh
1111
npm install --save @data-driven-forms/react-form-renderer
1212
```
1313
or
14-
```console
14+
```sh
1515
yarn add @data-driven-forms/react-form-renderer
1616
```
1717

packages/react-renderer-demo/src/app/src/components/code-editor/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import 'brace/theme/tomorrow_night';
1212
const CodeEditor = (props) => (
1313
<AceEditor
1414
readOnly
15-
mode={typeof language === 'string' ? props.language && props.language.toLowerCase() : 'jsx'}
1615
theme="tomorrow_night"
1716
name="UNIQUE_ID_OF_DIV"
1817
editorProps={{ $blockScrolling: true }}

packages/react-renderer-demo/src/app/src/components/mdx/mdx-components.js

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,32 +64,36 @@ const MdxComponents = {
6464
{children}
6565
</Typography>
6666
),
67-
code: ({ children, lang }) => (
68-
<div style={{ background: '#1d1f21', paddingTop: 5, paddingBottom: 5, marginTop: 10, marginBottom: 10 }} className="DocCode">
69-
<CodeEditor
70-
readOnly
71-
mode={typeof lang === 'string' ? lang.toLowerCase() : 'jsx'}
72-
theme="tomorrow_night"
73-
name="UNIQUE_ID_OF_DIV"
74-
editorProps={{ $blockScrolling: true }}
75-
value={children.replace(/\n+$/, '')}
76-
fontSize={14}
77-
maxLines={Infinity}
78-
showPrintMargin={false}
79-
showGutter={false}
80-
highlightActiveLine={false}
81-
style={{ width: '80%', margin: 10 }}
82-
setOptions={{
83-
showLineNumbers: false,
84-
readOnly: true
85-
}}
86-
onLoad={(editor) => {
87-
editor.getSession().setUseWorker(false);
88-
editor.renderer.$cursorLayer.element.style.display = 'none';
89-
}}
90-
/>
91-
</div>
92-
),
67+
code: ({ children, className }) => {
68+
const lang = className ? className.toLowerCase().replace('language-', '') : '';
69+
70+
return (
71+
<div style={{ background: '#1d1f21', paddingTop: 5, paddingBottom: 5, marginTop: 10, marginBottom: 10 }} className="DocCode">
72+
<CodeEditor
73+
readOnly
74+
mode={lang ? lang : 'jsx'}
75+
theme="tomorrow_night"
76+
name="UNIQUE_ID_OF_DIV"
77+
editorProps={{ $blockScrolling: true }}
78+
value={children.replace(/\n+$/, '')}
79+
fontSize={14}
80+
maxLines={Infinity}
81+
showPrintMargin={false}
82+
showGutter={false}
83+
highlightActiveLine={false}
84+
style={{ width: '80%', margin: 10 }}
85+
setOptions={{
86+
showLineNumbers: false,
87+
readOnly: true
88+
}}
89+
onLoad={(editor) => {
90+
editor.getSession().setUseWorker(false);
91+
editor.renderer.$cursorLayer.element.style.display = 'none';
92+
}}
93+
/>
94+
</div>
95+
);
96+
},
9397
a: ({ href, children }) =>
9498
href.startsWith('/') ? (
9599
<RouterLink href={href}>

0 commit comments

Comments
 (0)