# Makeup

## Introduction

Makeup is a "generic syntax highlighter suitable for use in code hosting, forums, wikis or other applications that need to prettify source code" . This tagline was shamelessly stolen from the [Pygments website](

Pygments the major inspiration for this package, and the structure is basically the same.
It has **lexers**, *formatters** and **styles**.

* **Lexers** turn the source code into a list of tokens
* **Formatters** turn the list of tokens into something else (HTML, TeX, images, etc.).
  Currently only an HTML formatter exists.
* **Styles** customize the output of the formatter.
  Makeup supports all Pygments' styles (in fact, they were converted from the Python's source).
  New custom styles can be added to makeup itself, or defined in the Project that uses it.

## Demo

To see a sample of Makeup's output, go check the [demo](
Please note that not all styles define all differences between tokens.
In a given style, strings and characters might be rendered in the same color while in others , the colors might be different.
That is style-dependent.
Some of the richer styles are
the Tango style ([elixir](, [html5](,
the Colorful style ([elixir](, [html5](,
the Default style ([elixir](, [html5]( and
the Friendly style ([elixir](, [html5](

## Supported Languages

Currently, the only supported source languages are
[Elixir]( and 
[HTML5]( (with no support for embedded CSS and Javascript yet).

## Installation

If [available in Hex](, the package can be installed
by adding `makeup` to your list of dependencies in `mix.exs`:

def deps do
    {:makeup, "~> 0.1.0"}

Documentation can be generated with [ExDoc](
and published on [HexDocs]( Once published, the docs can
be found at [](

The ExDocs are still pretty primitive.

## Quickstart

To highlight some Elixir code (newlines added for clarity):

# "<pre class=\"highlight\"><code>
#   <span class=\"n\">x</span><span class=\"w\"> </span>
#   <span class=\"o\">+</span><span class=\"w\"> </span><span class=\"mi\">1</span>
# </code></pre>\n"

As you can see, the default HTML formatter uses CSS classes.
You'll need a CSS stylesheet to get the different colors and styles.

To generate a stylesheet:

Makeup.stylesheet(style) # by default, the StyleMap.default style is used.
# ... output ommited

## Advantages over Pygments

One of the greatest advantages is that it runs on the BEAM, so it can be used with elixir projects without external dependencies.

Another advantage is that the way lexers are written, we can be a lot smarter than Pygments in processing the output.
We can look for matching HTML tags, and render the contents according to the tag.
For example, in the current HTML5 lexer, the contents of a `<em></em>` are rendered in *italic*,
and the contents of the `<strong></strong>` tag are rendered in **bold**.

For the developper, lexers are also easier to write than the Pygments lexers, because we use a PEG parser.
Most Pygments lexes use something like a state table that works based on regex matches,
and uses the results of those matches to switch to another state. 
Using a PEG parser we can define the grammar in a more natural way.

## Disadvantages over Pygments

It supports only two languages (yet, contributions are welcome!).

The lexers are written using the excellent [ExSpirit]( parser.
ExSpirit does many of optimizations at compile time, which means that compile times are very long
(way over 10s per lexer, and way over 30s for the entire package sometimes).
This will only get worse as we add more lexers.
When working on a single lexer, Elixir is smart enough to only recompile that file,
so it's a little faster (still, it's over 10s)

The advantage is having parsers that are faster at runtime.

## Benchmarks


## Documentation on how to write a new lexer



Makeup is licensed under the BSD license.
This is the same license as the Pygments Makeup uses and
it seems to be compatible with the licenses used by all the dependencies.