@uiw/codemirror-extensions-langs
v4.23.7
Published
Load languages Extensions for CodeMirror6.
Downloads
187,208
Readme
Load languages Extensions
Load languages Extensions for CodeMirror6.
Install
npm install @uiw/codemirror-extensions-langs --save
import { loadLanguage, langNames, langs } from '@uiw/codemirror-extensions-langs';
loadLanguage('tsx');
langs.tsx();
console.log('langNames:', langNames); // => "jsx" | "typescript" | "javascript" | "tsx"
Usage
import CodeMirror from '@uiw/react-codemirror';
import { langs } from '@uiw/codemirror-extensions-langs';
function App() {
return <CodeMirror value="console.log('hello world!');" height="200px" extensions={[langs.tsx()]} />;
}
export default App;
import CodeMirror from '@uiw/react-codemirror';
import { loadLanguage } from '@uiw/codemirror-extensions-langs';
function App() {
return <CodeMirror value="console.log('hello world!');" height="200px" extensions={[loadLanguage('tsx')]} />;
}
export default App;
import { EditorView } from '@codemirror/view';
import { EditorState } from '@codemirror/state';
import { loadLanguage, langs } from '@uiw/codemirror-extensions-langs';
const state = EditorState.create({
doc: 'my source code',
extensions: [langs.jsx()],
});
const view = new EditorView({
parent: document.querySelector('#editor'),
state,
});
Support Language
import CodeMirror from '@uiw/react-codemirror';
import { StreamLanguage } from '@codemirror/language';
import { go } from '@codemirror/legacy-modes/mode/go';
const goLang = `package main
import "fmt"
func main() {
fmt.Println("Hello, 世界")
}`;
export default function App() {
return <CodeMirror value={goLang} height="200px" extensions={[StreamLanguage.define(go)]} />;
}
- ~~
@codemirror/legacy-modes/mode/cpp
~~ =>@codemirror/lang-cpp
- ~~
@codemirror/legacy-modes/mode/html
~~ =>@codemirror/lang-html
- ~~
@codemirror/legacy-modes/mode/java
~~ =>@codemirror/lang-java
- ~~
@codemirror/legacy-modes/mode/javascript
~~ =>@codemirror/lang-javascript
- ~~
@codemirror/legacy-modes/mode/json
~~ =>@codemirror/lang-json
- ~~
@codemirror/legacy-modes/mode/lezer
~~ =>@codemirror/lang-lezer
- ~~
@codemirror/legacy-modes/mode/markdown
~~ =>@codemirror/lang-markdown
- ~~
@codemirror/legacy-modes/mode/php
~~ =>@codemirror/lang-php
- ~~
@codemirror/legacy-modes/mode/python
~~ =>@codemirror/lang-python
- ~~
@codemirror/legacy-modes/mode/rust
~~ =>@codemirror/lang-rust
- ~~
@codemirror/legacy-modes/mode/sql
~~ =>@codemirror/lang-sql
- ~~
@codemirror/legacy-modes/mode/xml
~~ =>@codemirror/lang-xml
- ~~
@codemirror/legacy-modes/mode/css
~~ =>@codemirror/lang-less
- ~~
@codemirror/legacy-modes/mode/sass
~~ =>@codemirror/lang-sass
- ~~
@codemirror/legacy-modes/mode/clojure
~~ =>@nextjournal/lang-clojure
- ~~
@codemirror/legacy-modes/mode/clike
~~ =>@replit/codemirror-lang-csharp
Contributors
As always, thanks to our amazing contributors!
Made with github-action-contributors.
License
Licensed under the MIT License.