Giter Club home page Giter Club logo

node-pygmentize-bundled's Introduction

Pygmentize (Bundled)

A simple wrapper around Python's Pygments code formatter, with Pygments bundled.

Available as a simple String-in, Buffer-out interface and also as a read/write-Stream interface.

API

pygmentize(options, code, callback)

Pygmentize a given code string and return it as a Buffer to the callback Function.

  • options contains options to be passed to Pygments (see Options).
  • code is a String to be formatted.
  • callback is a Function, called when complete. The first argument will be an error object/string if there was a problem and the second argument will be a Buffer containing your formatted code.

pygmentize(options)

When you only supply the options argument, it will return a read/write Stream that you can pipe to and from to format your code.

  • options contains options to be passed to Pygments (see Options).

Options

Language/lexer, formatter, and their options are currently supported. Filters are not supported yet.

  • lang: source language/lexer name - string
  • format: output formatter name - string
  • options: lexer and formatter options - object

Examples

The string interface is very simple:

var pygmentize = require('pygmentize-bundled')

pygmentize({ lang: 'js', format: 'html' }, 'var a = "b";', function (err, result) {
  console.log(result.toString())
})

Results in:

<div class="highlight"><pre>
  <span class="kd">var</span>
  <span class="nx">a</span>
  <span class="o">=</span>
  <span class="s2">&quot;b&quot;</span>
  <span class="p">;</span>
</pre></div>

Example with extra options:

var pygmentize = require('pygmentize-bundled')

pygmentize({ lang: 'php', format: 'html', options: { startinline: 1 } }, 'var a = true;', function (err, result) {
  console.log(result.toString())
})

A streaming API is also available. Simply omit the code and callback arguments:

var pygmentize = require('pygmentize-bundled')

process.stdin.pipe(
  pygmentize({ lang: 'js', format: 'html' })
).pipe(process.stdout);

Refer to the Pygments documentation. For supported languages, see the list of lexers, for supported formatted, see the list of formatters.

Contributors

Pygments (Bundled) is Copyright (c) 2012 Rod Vagg <@rvagg> and licenced under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.

Pygments is licenced under the BSD licence.

node-pygmentize-bundled's People

Contributors

crohr avatar kketch avatar rvagg avatar swalkinshaw avatar

Watchers

 avatar  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.