Code Monkey home page Code Monkey logo

codeflask's Introduction

npm version Build Status


CodeFlask: A micro code-editor for awesome web pages.

Installation

You can install CodeFlask via npm:

npm install codeflask

Or use it directly in browser via cdn service:

https://unpkg.com/codeflask/build/codeflask.min.js

Usage

import CodeFlask from 'codeflask';

const flask = new CodeFlask('#my-selector', { language: 'js' });

Listening for changes in editor

flask.onUpdate((code) => {
  // do something with code here.
  // this will trigger whenever the code
  // in the editor changes.
});

Updating the editor programatically

// This will also trigger .onUpdate()
flask.updateCode('const my_new_code_here = "Blabla"');

Getting the current code from editor

const code = flask.getCode();

Enabling line numbers

import CodeFlask from 'codeflask';

const flask = new CodeFlask('#my-selector', {
  language: 'js',
  lineNumbers: true
});

Enabling rtl (right to left writing)

import CodeFlask from 'codeflask';

const flask = new CodeFlask('#my-selector', {
  language: 'js',
  rtl: true
});

Enabling read only mode

import CodeFlask from 'codeflask';

const flask = new CodeFlask('#my-selector', {
  language: 'js',
  readonly: true
});

Adding other languages support:

flask.addLanguage('ruby', options)

This API is simply a proxy to add a new language to Prism itself (the code highlighter). The options parameter must be the same accepted in Prism. You can read more about it here.

By default, CodeFlask supports the following languages (which are also the default supported in Prism):

  • Markup (HTML/XML);
  • CSS;
  • C-like;
  • JavaScript;

Adding your own theme to CodeFlask

By default, CodeFlask comes with a simple theme made from scratch called CodeNoon.

You can easily override this theme with your own by writting your own CSS and adding it to your project. If that's the case, you should also disable CodeNoon with the defaultTheme option:

import CodeFlask from 'codeflask';

const flask = new CodeFlask('#my-selector', {
  language: 'js',
  defaultTheme: false
});

Credits & Thanks

CodeFlask.js was made possible by awesome open-source projects such as Prism.js and Rollup.

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.