Code Monkey home page Code Monkey logo

highlight's Introduction

highlight

highlight for node.js is based on highlight.js parser and is meant to highlight code syntax in languages that are not known beforehand (highlight.js detects the used language automatically). This is especially important for pages in Markdown format - there's no easy way to know which language is actually used.

Installation

Use npm package manager

npm install highlight

Usage

Include syntax highlighter

var hl = require("highlight").Highlight;

highlight code

html = hl("for(var i=0;i<10;i++)alert(i);");

use special tab replacing string (default is 4 spaces)

html = hl(code_string, "<span>  </span>");

convert code only between <code> blocks (leaves everything else as is) - especially useful if used together with converted Markdown syntax that includes <code> blocks.

html = hl("<p>PHP:</p><code><?php echo 'Hello world!';?></code>", false, true);

Styles

highlight outputs HTML code with predefined CSS class names for different elements. This doesn't make a lot of sense by default (it's just a bunch of SPAN's) so you need to use a CSS file that sets the used color set for the highlighting. There's some sample CSS files in /lib/vendor/highlight.js/styles that can be used with no modification - just include one of the files in the page you are showing the highlighted code.

<link rel="stylesheet" href="/path/to/styles/default.css"/>

highlight's People

Contributors

andris9 avatar craga89 avatar

Watchers

Kris Borchers 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.