uiwjs / react-codemirror

CodeMirror 6 component for React. @codemirror https://uiwjs.github.io/react-codemirror/
https://uiwjs.github.io/react-codemirror/
MIT License
1.65k stars 132 forks source link

failed to display python style v0.19.2 #200

Closed mbui0327 closed 3 years ago

mbui0327 commented 3 years ago

I installed the lang-python 0.19.2 and it does not work. It worked fine with the javascript example. This my code with python.

import { python } from '@codemirror/lang-python';
<CodeMirror
            value = "print('hello world!')"
            height = "200px"
            extensions = {[python()]}
            theme = 'light'
            onChange = {(value, viewUpdate) => {
                // console.log('value:', value);
            }}
        />

Do you know why?

jaywcjlove commented 3 years ago

@mbui0327 Example: https://codesandbox.io/s/react-codemirror-example-codemirror-6-200-wv4gg?file=/src/App.js

import CodeMirror from "@uiw/react-codemirror";
import { python } from "@codemirror/lang-python";

const code = `#!/usr/bin/python

count = 0
while (count < 9):
   print 'The count is:', count
   count = count + 1

print "Good bye!"
`;

export default function App() {
  return (
    <CodeMirror
      value={code}
      height="200px"
      extensions={[python()]}
      onChange={(value, viewUpdate) => {
        console.log("value:", value);
      }}
    />
  );
}
mbui0327 commented 3 years ago

Somehow my @codemirror/language was install with an older version 0.18.3. Not really sure why. I have to force install the lastest version and it works now. Thank anyway.