GithubHelp home page GithubHelp logo

bhanditz / brace Goto Github PK

View Code? Open in Web Editor NEW

This project forked from airbnb/brace

0.0 1.0 0.0 4.45 MB

browserify compatible version of the ace editor.

Home Page: http://thlorenz.github.io/brace/

License: MIT License

JavaScript 99.98% CSS 0.01% HTML 0.01%

brace's Introduction

brace

browserify compatible version of the ace editor.

browser support

This badge shows which browsers support annotations, however the editor itself works in pretty much every browser.

Try it in your browser.

Installation

npm install brace

Example

var ace = require('brace');
require('brace/mode/javascript');
require('brace/theme/monokai');

var editor = ace.edit('javascript-editor');
editor.getSession().setMode('ace/mode/javascript');
editor.setTheme('ace/theme/monokai');

Include the above as an entry in your browserify build, add a <div id="javascript-editor"></div> to your html page and a JavaScript editor will appear.

This editor will show error/warning annotations if your browser supports WebWorkers created via a blob URL (see testling support badge on top).

Please consult the detailed example for more information.

Why not just use ace?

The ace editor creates the WebWorker via a worker script url. This requires the worker scripts to reside on your server and forces you to host the ace editor on your server as well.

While that is ok in most cases, it prevents you from providing a fully working ace editor package.

With brace, you have two options:

  • include brace itself when browserifying your app to get a fully working ace editor included with your bundle (no other external scripts needed)
  • create the bundle as explained above and provide it to others so they can include it in their html page simply via a script tag

What if my browser doesn't support it?

If brace is unable to inline the web worker, it just falls back to provide the ace editor without annotation support. This means the editor is fully functional, but doesn't display errors/warnings on the left side.

As far as I understand, the original ace editor behaves in exactly the same way.

How does it work?

brace has an update script which automatically pulls down the ace builds and refactors them to provide the following:

  • inline all supported workers
  • automatically require the workers that a 'mode' (language) depends on inside the mode file itself
  • provide the modes and themes at the same paths that ace's setMode and setTheme use (just replace 'ace' with 'brace') as seen in the above example

Supported Workers

All workers included with ace are supported, except php and xquery, mainly because I wasn't able to properly stringify their code (any help with that is appreciated).

Test

npm explore brace 
npm test

brace's People

Contributors

forbeslindesay avatar kylepdavis avatar lrowe avatar monsanto avatar thlorenz 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.