You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/react-code-editor/README.md
+20-24Lines changed: 20 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# @patternfly/react-code-editor
2
2
3
-
This package provides a PatternFly wrapper for the Monaco code editor
3
+
This package provides a PatternFly wrapper for the Monaco code editor, using the `@monaco-editor/react` package.
4
4
5
-
### Prerequisite
5
+
### Prerequisite
6
6
7
7
#### Node Environment
8
8
@@ -44,25 +44,25 @@ import { CodeEditor } from '@patternfly/react-code-editor';
44
44
```
45
45
46
46
Install peer deps
47
+
47
48
```json
48
49
"monaco-editor": "^0.21.3",
49
-
"monaco-editor-webpack-plugin": "^2.1.0",
50
50
"react": "^17 || ^18",
51
-
"react-dom": "^17 || ^18",
52
-
"react-monaco-editor": "^0.51.0"
51
+
"react-dom": "^17 || ^18"
53
52
```
54
53
55
-
To properly install the library `monaco-editor-webpack-plugin` be sure to follow the [plugin instructions](https://github.com/microsoft/monaco-editor/tree/main/webpack-plugin)
56
-
57
54
#### With create-react-app Projects
55
+
58
56
If you created your project with `create-react-app` you'll have some extra work to do, or you wont have syntax highlighting. Using the webpack plugin requires updating your webpack config, which `create-react-app` abstracts away. You can `npm eject` your project, but you may not want to do that. To keep your app set up in the `create-react-app` style but to get access to your webpack config you can use `react-app-rewired`.
59
57
60
58
First, install `react-app-rewired` as a development dependency:
59
+
61
60
```sh
62
61
$ npm install -D react-app-rewired
63
62
```
64
63
65
64
Next, replace all of the `react-script` references in your `package.json``scripts` section with `react-app-required`:
65
+
66
66
```json
67
67
"scripts": {
68
68
"start": "react-app-rewired start",
@@ -72,32 +72,20 @@ Next, replace all of the `react-script` references in your `package.json` `scrip
72
72
}
73
73
```
74
74
75
-
Next, create a `config-overrides.js` file at the root of your project and add the following:
Note: You should change the `languages` array based on your needs.
89
-
90
75
You can now start your app with `npm start` and syntax highlighting should work.
91
76
92
77
#### Enable YAML Syntax Highlighting
93
-
The Monaco editor doesn't ship with full YAML support. You can configure your code editor with `Languages.yaml` but there will be no highlighting, even i you have the webpack plugin working correctly. To enable YAML support you need to do the following:
78
+
79
+
The Monaco editor doesn't ship with full YAML support. You can configure your code editor with `Languages.yaml` but there will be no highlighting. To enable YAML support you need to do the following:
Finally, to allow the `monaco-yaml` autocomplete to function properly with `@monaco-editor/react`, you should configure your YAML schema in a `beforeMount` call with the `monaco-yaml``configureMonacoYaml` function. This `beforeMount` function should be passed to `CodeEditor` via the `editorProps` property like so:
103
+
104
+
```
105
+
editorProps: {
106
+
beforeMount: yourBeforeMountHandler
107
+
}
108
+
```
109
+
114
110
The `monaco-yaml` plugin has a lot of options so check out their docs to see what else you may want to add.
0 commit comments