react-codemirror icon indicating copy to clipboard operation
react-codemirror copied to clipboard

Usage with handlebars?

Open louis030195 opened this issue 2 years ago • 14 comments

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

louis030195 avatar Jun 14 '22 10:06 louis030195

@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);
      }}
    />
  );
}

jaywcjlove avatar Jun 14 '22 11:06 jaywcjlove

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",
...

louis030195 avatar Jun 14 '22 12:06 louis030195

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

jaywcjlove avatar Jun 14 '22 13:06 jaywcjlove

@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!

Miltonbhowmick avatar Sep 07 '22 04:09 Miltonbhowmick

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

tslater avatar Mar 10 '23 09:03 tslater

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

tslater avatar Mar 11 '23 02:03 tslater

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

lenqwang avatar May 30 '23 10:05 lenqwang

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

jaywcjlove avatar May 30 '23 12:05 jaywcjlove

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

I don't find the handlebars module file

lenqwang avatar May 31 '23 00:05 lenqwang

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

tslater avatar May 31 '23 03:05 tslater

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

jaywcjlove avatar May 31 '23 03:05 jaywcjlove

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.

lenqwang avatar Jun 01 '23 01:06 lenqwang

  • https://discuss.codemirror.net/t/handlebars-in-v6/5941
  • https://stackblitz.com/edit/node-rwuxbu?file=src%2Fsyntax.grammar,src%2Fhighlight.ts
  • https://codemirror.net/examples/mixed-language/

jaywcjlove avatar Jun 03 '23 05:06 jaywcjlove

Thanks a lot, These links are very useful to me

lenqwang avatar Jun 05 '23 04:06 lenqwang