uiwjs / react-codemirror

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

Usage with handlebars? #333

Open louis030195 opened 2 years ago

louis030195 commented 2 years ago

Hello!

It's not so clear how to use this lib with handlebars, if it is even possible, I see codemirror support it so why not?

I couldn't find it in import { handlebars } from '@codemirror/legacy-modes/mode/handlebars';?

Thanks a lot

jaywcjlove commented 2 years ago

@louis030195

import CodeMirror from '@uiw/react-codemirror';
import { StreamLanguage } from '@codemirror/language';
import { handlebars } from '@codemirror/legacy-modes/mode/handlebars';

const codeStr = `code string....`;

export default function App() {
  return (
    <CodeMirror
      value={codeStr}
      height="200px"
      extensions={[StreamLanguage.define(handlebars)]}
      onChange={(value, viewUpdate) => {
        console.log('value:', value);
      }}
    />
  );
}
louis030195 commented 2 years ago

Module not found: Error: Can't resolve '@codemirror/legacy-modes/mode/handlebars' ?

package.json

...
  "dependencies": {
    ...
    "@codemirror/language": "^6.0.0",
    "@codemirror/legacy-modes": "^6.0.0",
...
jaywcjlove commented 2 years ago

@louis030195 Example: https://codesandbox.io/embed/react-codemirror-example-codemirror-6-language-rz4rh?fontsize=14&hidenavigation=1&theme=dark

Miltonbhowmick commented 2 years ago

@louis030195

import CodeMirror from '@uiw/react-codemirror';
import { StreamLanguage } from '@codemirror/language';
import { handlebars } from '@codemirror/legacy-modes/mode/handlebars';

const codeStr = `code string....`;

export default function App() {
  return (
    <CodeMirror
      value={codeStr}
      height="200px"
      extensions={[StreamLanguage.define(handlebars)]}
      onChange={(value, viewUpdate) => {
        console.log('value:', value);
      }}
    />
  );
}

This solves my problem!

tslater commented 1 year ago

@louis030195 I'm having the same issue. Did you ever figure out how to import?

tslater commented 1 year ago

If I understand correctly, this might be a v5 vs v6 issue? v6 doesn't have handlebars support maybe?

lenqwang commented 1 year ago

Is seems v6 does not support handlebars, so how can v6 support handlebars?

jaywcjlove commented 1 year ago

@tslater @lenqwang https://github.com/uiwjs/react-codemirror/issues/333#issuecomment-1238887212

lenqwang commented 1 year ago

@tslater @lenqwang https://github.com/uiwjs/react-codemirror/issues/333#issuecomment-1238887212

I don't find the handlebars module file

tslater commented 1 year ago

I don't think there is any good way to use it on v6 yet. You'd have to implement it yourself.

jaywcjlove commented 1 year ago

@lenqwang @tslater https://codemirror.net/5/mode/handlebars/index.html Is it this one? I think the definition is also very simple.

lenqwang commented 1 year ago

Yes, I had to implement it myself. Although I searched the entire internet. However, I am very curious why the official has not provided an implementation of handlebars.

jaywcjlove commented 1 year ago
lenqwang commented 1 year ago

Thanks a lot, These links are very useful to me