Skip to content

Commit f7e2ce4

Browse files
committed
Add prism prop to Editor
1 parent 68fce44 commit f7e2ce4

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"eslint-plugin-react": "^7.7.0",
5858
"jest": "^27.0.6",
5959
"prettier": "^1.17.0",
60+
"prismjs": "^1.26.0",
6061
"react": "^16.8.0",
6162
"react-dom": "^16.8.0",
6263
"rollup": "^2.55.1",
@@ -100,4 +101,4 @@
100101
"testURL": "http://localhost/"
101102
},
102103
"sideEffects": false
103-
}
104+
}

src/components/Editor/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const CodeEditor = props => {
2727

2828
const highlightCode = code => (
2929
<Highlight
30-
Prism={Prism}
30+
Prism={props.prism || Prism}
3131
code={code}
3232
theme={props.theme || liveTheme}
3333
language={props.language}
@@ -77,7 +77,8 @@ CodeEditor.propTypes = {
7777
language: PropTypes.string,
7878
onChange: PropTypes.func,
7979
style: PropTypes.object,
80-
theme: PropTypes.object
80+
theme: PropTypes.object,
81+
prism: PropTypes.object
8182
};
8283

8384
export default CodeEditor;

stories/Editor.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import React from 'react';
2-
2+
import Prism from 'prismjs';
33
import { Editor } from '../src/index';
44

55
export default {
66
title: 'Editor',
7-
component: Editor,
8-
}
7+
component: Editor
8+
};
99

10-
const Template = (args) => <Editor {...args} />;
10+
const Template = args => <Editor {...args} />;
1111

1212
export const Default = Template.bind({});
1313
Default.args = {
14-
language: "js",
14+
language: 'js',
1515
code: "const x = 'Hello World!';"
16-
};
16+
};
17+
18+
// Can't pass Prism as an arg since it is not JSON-serializable
19+
export const PrismFromNpm = () => (
20+
<Editor language="js" prism={Prism} code="const x = 'Hello World!';" />
21+
);

typings/react-live.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export type EditorProps = Omit<PreProps, 'onChange'> & {
3232
language?: Language;
3333
onChange?: (code: string) => void;
3434
theme?: PrismTheme;
35+
prism?: unknown
3536
}
3637

3738
export const Editor: ComponentClass<EditorProps>

yarn.lock

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8491,6 +8491,7 @@ minipass-fetch@^1.3.0, minipass-fetch@^1.3.2:
84918491
resolved "https://registry.yarnpkg.com/minipass-fetch/-/minipass-fetch-1.3.4.tgz#63f5af868a38746ca7b33b03393ddf8c291244fe"
84928492
integrity sha512-TielGogIzbUEtd1LsjZFs47RWuHHfhl6TiCx1InVxApBAmQ8bL0dL5ilkLGcRvuyW/A9nE+Lvn855Ewz8S0PnQ==
84938493
dependencies:
8494+
encoding "^0.1.12"
84948495
minipass "^3.1.0"
84958496
minipass-sized "^1.0.3"
84968497
minizlib "^2.0.0"
@@ -9702,7 +9703,12 @@ prism-react-renderer@^1.2.1:
97029703
resolved "https://registry.yarnpkg.com/prism-react-renderer/-/prism-react-renderer-1.2.1.tgz#392460acf63540960e5e3caa699d851264e99b89"
97039704
integrity sha512-w23ch4f75V1Tnz8DajsYKvY5lF7H1+WvzvLUcF0paFxkTHSp42RS0H5CttdN2Q8RR3DRGZ9v5xD/h3n8C8kGmg==
97049705

9705-
prismjs@^1.21.0, prismjs@~1.24.0:
9706+
prismjs@^1.21.0, prismjs@^1.26.0:
9707+
version "1.26.0"
9708+
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.26.0.tgz#16881b594828bb6b45296083a8cbab46b0accd47"
9709+
integrity sha512-HUoH9C5Z3jKkl3UunCyiD5jwk0+Hz0fIgQ2nbwU2Oo/ceuTAQAg+pPVnfdt2TJWRVLcxKh9iuoYDUSc8clb5UQ==
9710+
9711+
prismjs@~1.24.0:
97069712
version "1.24.1"
97079713
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.24.1.tgz#c4d7895c4d6500289482fa8936d9cdd192684036"
97089714
integrity sha512-mNPsedLuk90RVJioIky8ANZEwYm5w9LcvCXrxHlwf4fNVSn8jEipMybMkWUyyF0JhnC+C4VcOVSBuHRKs1L5Ow==

0 commit comments

Comments
 (0)