Coder Social home page Coder Social logo

html-haxe-code-highlighter's Introduction

Simple Haxe Code Highlighter for HTML

Build Status Haxelib Version

Basic runtime Haxe code highlighting. Formerly used on haxe.org website.

Basic Installation

If you just want the highlighting, you can download and use the .js and .css files:

  1. Download <bin/highlighter.js> and add <script src="highlighter.js"></script> to your HTML.
  2. Download <bin/highlighter.min.css> and add <link rel="stylesheet" href="highlighter.min.css" /> to your HTML.

Installation using sources

If you want to integrate the highlighting in your project, install using Haxelib:

haxelib install html-haxe-code-highlighter

To use in code, add to your build hxml:

-lib html-haxe-code-highlighter

API

  • Highlighter.highlight(?container:js.html.Element) (JS target only) Adds highlighting to all <code class="prettyprint haxe"> and <code class="prettyprint hxml"> tags in the given element. If container is null, then document body element is used.

  • Highlighter.syntaxHighlightHaxe(code:String) Syntax highlight Haxe code. Returns code as formatted HTML text.

  • Highlighter.syntaxHighlightHXML(code:String) Syntax highlight HXML. Returns code as formatted HTML text.

CSS classes

The following css classes are applied

Description CSS class
Reserved keywords .kwd
Reserved values .val
Types .type
Strings .str
Regexp .ereg
Comments .cmt

Build with Haxe

html-haxe-code-highlighter's People

Contributors

markknol avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

html-haxe-code-highlighter's Issues

Text in comments should not be highlighted

class Test {
    static function main() {
        var code = '
            /*
            * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
            * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
            * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
            * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
            * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
            * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
            * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
            * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
            * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
            * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
            * DAMAGE.
            */
        ';
        var html = highlighter.Highlighter.syntaxHighlightHaxe(code);
        trace(html);
    }
}

The above code gives runtime error for Neko:

Called from ? line 1
Called from Test.hx line 18
Called from highlighter/Highlighter.hx line 70
Called from /home/andy/.opam/4.06.1/share/haxe/std/neko/_std/EReg.hx line 105
Uncaught exception - An error occurred while running pcre_exec
Error: Command failed with error 1

It is because the content of the comment are highlighted and apparently too complex for the neko regexp to handle. For other targets, e.g. --interp, the output is:

src/Test.hx:19:
            <span class=cmt>/*
            * <span class=type>THIS</span> <span class=type>SOFTWARE</span> <span class=type>IS</span> <span class=type>PROVIDED</span> <span class=type>BY</span> <span class=type>THE</span> <span class=type>HAXE</span> <span class=type>PROJECT</span> <span class=type>CONTRIBUTORS</span> <span class=str>"<span class=type>AS</span> <span class=type>IS</span>"</span> <span class=type>AND</span> <span class=type>ANY</span>
            * <span class=type>EXPRESS</span> <span class=type>OR</span> <span class=type>IMPLIED</span> <span class=type>WARRANTIES</span>, <span class=type>INCLUDING</span>, <span class=type>BUT</span> <span class=type>NOT</span> <span class=type>LIMITED</span> <span class=type>TO</span>, <span class=type>THE</span> <span class=type>IMPLIED</span>
            * <span class=type>WARRANTIES</span> <span class=type>OF</span> <span class=type>MERCHANTABILITY</span> <span class=type>AND</span> <span class=type>FITNESS</span> <span class=type>FOR</span> <span class=type>A</span> <span class=type>PARTICULAR</span> <span class=type>PURPOSE</span> <span class=type>ARE</span>
            * <span class=type>DISCLAIMED</span>. <span class=type>IN</span> <span class=type>NO</span> <span class=type>EVENT</span> <span class=type>SHALL</span> <span class=type>THE</span> <span class=type>HAXE</span> <span class=type>PROJECT</span> <span class=type>CONTRIBUTORS</span> <span class=type>BE</span> <span class=type>LIABLE</span> <span class=type>FOR</span>
            * <span class=type>ANY</span> <span class=type>DIRECT</span>, <span class=type>INDIRECT</span>, <span class=type>INCIDENTAL</span>, <span class=type>SPECIAL</span>, <span class=type>EXEMPLARY</span>, <span class=type>OR</span> <span class=type>CONSEQUENTIAL</span>
            * <span class=type>DAMAGES</span> (<span class=type>INCLUDING</span>, <span class=type>BUT</span> <span class=type>NOT</span> <span class=type>LIMITED</span> <span class=type>TO</span>, <span class=type>PROCUREMENT</span> <span class=type>OF</span> <span class=type>SUBSTITUTE</span> <span class=type>GOODS</span> <span class=type>OR</span>
            * <span class=type>SERVICES</span>; <span class=type>LOSS</span> <span class=type>OF</span> <span class=type>USE</span>, <span class=type>DATA</span>, <span class=type>OR</span> <span class=type>PROFITS</span>; <span class=type>OR</span> <span class=type>BUSINESS</span> <span class=type>INTERRUPTION</span>) <span class=type>HOWEVER</span>
            * <span class=type>CAUSED</span> <span class=type>AND</span> <span class=type>ON</span> <span class=type>ANY</span> <span class=type>THEORY</span> <span class=type>OF</span> <span class=type>LIABILITY</span>, <span class=type>WHETHER</span> <span class=type>IN</span> <span class=type>CONTRACT</span>, <span class=type>STRICT</span>
            * <span class=type>LIABILITY</span>, <span class=type>OR</span> <span class=type>TORT</span> (<span class=type>INCLUDING</span> <span class=type>NEGLIGENCE</span> <span class=type>OR</span> <span class=type>OTHERWISE</span>) <span class=type>ARISING</span> <span class=type>IN</span> <span class=type>ANY</span> <span class=type>WAY</span>
            * <span class=type>OUT</span> <span class=type>OF</span> <span class=type>THE</span> <span class=type>USE</span> <span class=type>OF</span> <span class=type>THIS</span> <span class=type>SOFTWARE</span>, <span class=type>EVEN</span> <span class=type>IF</span> <span class=type>ADVISED</span> <span class=type>OF</span> <span class=type>THE</span> <span class=type>POSSIBILITY</span> <span class=type>OF</span> <span class=type>SUCH</span>
            * <span class=type>DAMAGE</span>.
            */</span>

This is one source of some internal server errors found in lib.haxe.org. e.g. http://lib.haxe.org/p/HUGS/0.3.0/files/haxe/Log.hx

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.