README.md

EnlighterJS

EnlighterJS is a free, easy-to-use, syntax highlighting class developed for MooTools. It is based on the famous Lighter.js.
Using it can be as simple as adding a single script and style to your website, choosing the elements you wish to highlight, and EnlighterJS takes care of the rest.
It also supports Inline-Syntax-Highlighting as well as the automatic creation of tab-panes to display groups of code together (useful for multi-language examples - e.g. html+css+js)
Take a look into the Documentation or view the Theme Demo

Basic Usage

Download EnlighterJS and extract the files. Copy the prebuild files of the Build/ directory into a web-accessible directory of your choice.

Link to the EnlighterJS.yui.js javascript file and the EnlighterJS.yui.css stylesheet in the head section of your document after the MooTools file.
The example below assumes you moved the files into your scripts folder under "js/" and your styles folder under "css/".
The extension .yui indicates that these files are compressed with the Yahoo YUI Compressor. These files are ready for productive use!
If you want to start developing, you should consider to use the uncompressed versions for easier debugging!

Rendering options can be defined as global option (Metainit attributes or options object) or local option using the data-enlighter- attributes on each codeblock.
It is recommended to use local options only if necessary (e.g. to define a language for each block).

Prepare your source code by giving the element (containing the code) an optional data-enlighter-language attribute with the language of the code.
Notice: Instead of Lighter.js *fuel:flame' syntax combo within the css classname, EnlighterJS will use HTML5 data- attributes!

Finally, use the following JavaScript code examples inside of a 'domready' or 'onload' callback to create the highlighted elements - this process is called initialization.
Be sure to check out the Options section to see the various options you can use. The Example pages have various examples you can use.
Further informations as well as some advanced examples are available within the Initialization Section.

#JS
// Use the Init utility function to highlight all pre elements - this is the recommended way and required to use the Code-Group feature
EnlighterJS.Util.Init('pre', null, {
language: 'php',
theme: 'Classic'
});

Instead of initializing EnlighterJS manually, since version 1.1 it is possible to use a simple html-metatag (called EnlighterJS Metainit) to run Enlighter on your page (with basic config options).

Initialization

Initialization means, that all elements (you wish to highlight) get selected and rendered by EnlighterJS. The original codeblock is set invisible and the rendered one is injected after. This task can be performed in two different ways:

1. Metainit Initialization

Instead of initializing EnlighterJS by javascript, it's possible to use a simple html-metatag (called EnlighterJS Metainit) to run Enlighter on your page (with basic config options). This will be usefull if you only need a basic setup. Take a look into the examples Examples/Testcase.Metainit.html to see how it is working!
Basically Metainit takes the given html attribute options and converts them into a options object. These options will be passed to the Enlighter.Util.Helper() utility function - for inline elements (InlineRenderer) identified by data-selector-inline as well as block elements (BlockRenderer) by data-selector-block.
This will take all the work for you by adding a single line to the head section to use all the amazing EnlighterJS features like Inline-Syntax-Highlighting or CodeGroups!

Example

Description: It enables block highlighting for all pre elements on the page as well as inline highlighting for all code elements. Javascript is set as default language used for highlighting. Each tab is replaced by four spaces to avoid rendering issues. Additionally the "raw code button" is enabled which allows the user to toggle between highlighted and unhighlighted code (e.g. to copy code).

Attributes

Following attributes are available (optional) and will be converted to the required options object to trigger EnlighterJS.Util.Helper. Take a look into the Metainit.js sources to see how it is working.

name (string) REQUIRED - This attribute identifies the metatag and has to be set to "EnlighterJS" (case sensitive)

data-hover (string) - Defines a css-classname which is added to each line. To enable build-in hover effects set it to "hoverEnabled" (default), null to disable it or to any custom class - default: "hoverEnabled"

2. Javacript based Initialization

EnlighterJS provides 4 ways to get manually initialized:

Use the native Element.enlight() method which will automatically creates an EnlighterJS instance of the selected single element

Create a new instance of EnlighterJS and provide the single element to highlight

To use Code-Groups you have to use EnlighterJS.Util.Helper utility function

Notice: You can pass any of the Global Options with each method. Every method will invoke the EnlighterJS constructor.

hover - (string) Defines a css-classname which is added to each line. To enable build-in hover effects set it to "hoverEnabled" (default), null to disable it or to any custom class - default: "hoverEnabled"

Example 2

Code-Groups

This example shows how to use code-groups. You can define a new code-group by adding a data-enlighter-group attribute to your code tags you want to group. The value is used as an internal identifier and is not shown anywhere (e.g. use numerical identifiers).
The name/title of the tab is defined by a data-enlighter-title attribute. To use a corporate style within all code-blocks grouped together, the theme definition of the first code-block defined in your document (the group leader) is used as theme of the complete group - other theme definitions will be ignored. if no theme is specified, the default theme (defined in the options) will be used, which is recommended.

Initialize Code-Groups

The initialization of code-groups differs from the standard. You have to use the EnlighterJS.Util.Helper utility function (triggered by Metainit and EnlighterJS.Util.Init) - it does the complete initialization and grouping for you!

Custom Builds

The EnlighterJS project is using Apache ANT as build-system. The YUI Compressor is used minify the production-ready javascript and css files.
To save bandwith/traffic or include self-defined languages, you can easily customize your EnlighterJS build by editing the build.xml file (found in the root directory) and run Apache ANT Build (target build)

You can also use the webbased EnlighterJS Builder to generate your customized package without the need of ANT - everything is done for you serverside!

If you want to remove some of the default theme you can edit the include.themes property and modify the list of css source files.
For Example: only include the Git and Mocha themes

Removing/Adding languages is also easy as this - they are defined by the include.languages property.
For Example: only include html+css+js syntax highlighting (be carefull - html is an alias for XML!, you have to include Xml.js)