Code Monkey home page Code Monkey logo

Comments (3)

erosman avatar erosman commented on June 29, 2024

Did you try the example in How to Use?

from codemirror-plus.

junior291492659 avatar junior291492659 commented on June 29, 2024

Thanks for your insight. I have tried to put the key.js in the directory '/node_modules/codemirror/addon/mode' and it did work smoothly.

However, is there any other way to put this file or the core function in our own code instead of codemirror's source code package since I have to do this again once I use 'npm install' command.

Indeed, I have tried via this way

part of my own component

import codemirror from 'codemirror';
import { Controlled as CodeMirror } from 'react-codemirror2';
import init from './utils'
...
useEffect(() => {
        init(codemirror);
    }, []);


return <CodeMirror
              ...
              keyword: {
            junior: 'style1',
            price: 'style1',
          },
          >

utils.ts

export default function(CodeMirror, keywordsAndFunctions) {
    "use strict";

CodeMirror.defineOption("keyword", {}, function(cm, val, prev) {
      if (prev == CodeMirror.Init) prev = false;
    if (prev && !val)
      cm.removeOverlay("keyword");
    else if (!prev && val)
      cm.addOverlay({
        token: function(stream) {
          for (var key in cm.options.keyword) {
            if (stream.match(key, true)) {return cm.options.keyword[key];}
          }
          stream.next();
        },
        name: "keyword"
      });
    });
}

less file

.cm-style1 {
  color: pink !important;
}

And it does not work as expected. It would be really appreciated to get your advice.

from codemirror-plus.

erosman avatar erosman commented on June 29, 2024

However, is there any other way to put this file or the core function in our own code instead of codemirror's source code package since I have to do this again once I use 'npm install' command.

As in How to Use

Install the file in /addon/mode/ or any preferred directory
Add the necessary <script> & <link rel="stylesheet"> to the HTML document

There is an HTML page that displays the CodeMirror. Add the <script> to point to that file.
<script src="../whereever/keyword.js"></script>

If you want to combine the code with your own code, then there is more work involved. The code has to run after CodeMirror code is parsed but before CodeMirror instance is started e.g. in init(codemirror);.

from codemirror-plus.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.