GithubHelp home page GithubHelp logo

doc22940 / parinfer-codemirror Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shaunlebron/parinfer-codemirror

0.0 1.0 0.0 33 KB

Parinfer layer for CodeMirror

License: ISC License

JavaScript 87.32% HTML 8.20% Shell 3.10% CSS 1.38%

parinfer-codemirror's Introduction

Parinfer for CodeMirror

A Parinfer layer for the browser-based CodeMirror editor.

used by Parinfer's official demo editor and website to demonstrate canonical plugin behavior

Demo

Run npm install and open demo.html for working example.

Usage

Attach Parinfer to a CodeMirror instance:

parinferCodeMirror.init(cm);

NOTE: To ensure your code structure is preserved when enabling Parinfer, the editor will be suspended in a "correction" mode (i.e. Paren Mode) if the editor has unbalanced code. Once the highlighted errors are fixed, the editor resumes the originally intended mode as expected.

Styling

Style the following class names. Those from demo.html shown below:

  • .parinfer-error - erroneous characters (unbalanced quotes or parens)

    parinfercm-error
  • .parinfer-paren-trail - parens at end of a line (dim to subtly show they are inferred)

    parinfercm-paren-trail

API

parinferCodeMirror.init(cm, mode, options);
// `mode` is 'paren', 'indent', or 'smart'
// `options` is passed to Parinfer

parinferCodeMirror.disable(cm); // disable Parinfer's effects on the editor
parinferCodeMirror.enable(cm);  // re-enable after disabling

parinferCodeMirror.setMode(cm, mode);
parinferCodeMirror.setOptions(cm, options);

The only Parinfer options you should pass is {forceBalance: true}, but only if you want aggressively-balanced parens. It is off by default since some edge-cases make this undesirable. When turned off, unmatched parens that cannot be safely resolved are highlighted rather than removed.

All of the API functions above will return a boolean indicating if the text was successfully processed without errors.

History

The original implementation used for the Parinfer website was rushed for the sake of proving the idea in an animated way. This standalone version simplifies the implementation, removes the custom internal hacks, and improves the integration required by new Parinfer features.

parinfer-codemirror's People

Contributors

shaunlebron avatar wilkerlucio avatar

Watchers

 avatar

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.