Giter Site home page Giter Site logo

talissonbento / highlight-syntax Goto Github PK

View Code? Open in Web Editor NEW

This project forked from axelav/highlight-syntax-es6

0.0 0.0 0.0 27 KB

highlight source code syntax with html

License: BSD 2-Clause "Simplified" License

JavaScript 78.68% CSS 12.53% C 1.84% Shell 6.96%

highlight-syntax's Introduction

highlight-syntax

highlight source code syntax with html

Works in node and the browser. Supported languages:

  • javascript
  • bash
  • c

Very small:

$ browserify . | uglifyjs -cm 2>/dev/null | gzip | wc -c
1776
$ browserify all.js | uglifyjs -cm 2>/dev/null | gzip | wc -c
3391

example

all languages

You can load all the languages:

var highlight = require('highlight-syntax/all')
var fs = require('fs')
var src = fs.readFileSync(process.argv[3],'utf8')
console.log(highlight(src, { lang: process.argv[2] }))

subset of languages

Or you can load a subset of languages. This will make the bundle you deliver to the browser smaller.

var highlight = require('highlight-syntax')([
  require('highlight-syntax/c'), require('highlight-syntax/sh')
])
var fs = require('fs')
var src = fs.readFileSync(process.argv[3],'utf8')
console.log(highlight(src, { lang: process.argv[2] }))

example with marked

You can pass this module to marked to highlight code in a markdown file:

var highlight = require('highlight-syntax/all')
var marked = require('marked')
var fs = require('fs')
var src = fs.readFileSync('readme.md','utf8')
console.log(marked(src, { highlight: highlight }))

api

var highlighter = require('highlight-syntax')
var highlight = require('highlight-syntax/all')

The css files in this distribution are:

  • highlight-syntax/dark.css - combined dark themes for all languages
  • highlight-syntax/light.css - combined linght themes for all languages

var highlight = highlighter(rules)

Create a highlighter function from an array of rules. You can load the rules explicitly from:

  • require('highlight-syntax/c') - c
  • require('highlight-syntax/sh') - bash
  • require('highlight-syntax/js') - javascript

var html = highlight(src, opts)

Turn a string of code src written in opts.lang to a syntax-highlighted string of html. If opts is a string, it is interpreted as the opts.lang.

  • opts.lang - string language name or file extension

usage

highlight-syntax FILES... {OPTIONS}
  -o --outfile  Write output to a file. Default: - (stdout)
  -l --lang     Set a language explicitly for stdin input.
  -t --theme    Include an inline css theme. Example: dark

install

To get the library:

npm install highlight-syntax

To get the command:

npm install -g highlight-syntax

license

BSD

highlight-syntax's People

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.