npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

source-highlight

v1.0.0

Published

Bindings for the GNU source-highlight library

Downloads

3

Readme

node-source-highlight

GNU source-highlight is a library to highlight source code in several different languages and output formats. This package provides Node.js bindings to the C++ library; currently, it requires you to have the library preinstalled.

Installation :package:

npm install --save source-highlight

Example

// Load the source code into a UTF-8 buffer
const input = Buffer.from(`
  console.log('Hello world!');
`);

// Create the SourceHighlight instance. "esc.outlang" will output colored characters to the console. You can
// use "html.outlang" too.
const sourceHighlight = new SourceHighlight('esc.outlang');

// Highlight the source code.
const output = sourceHighlight.highlight(input, 'javascript.lang', '').toString();

console.log(output);

API Documentation - SourceHighlight

import { SourceHighlight } from 'source-highlight';

[email protected] exports just the SourceHighlight class. The API documentation for the GNU source-highlight can be found here. The methods of SourceHighlight provided by this package are enlisted below.

Constructor

constructor(outLangDef: string)

Create a SourceHighlight instance that will output into the format specified, e.g. html.outlang.

highlight

highlight(input: string, output: string, inputLang: string): void

Highlight the input file and write into the output file. inputLang is the name of the language definition file you want to use. (This cannot be a path, e.g. html.lang is valid not /path/to/html.lang)

highlight(input: Buffer, inputLang: string, inputFileName: string): Buffer

Highlight the source code in the UTF-8 buffer using the language definition file inputLang (again only a filename in the data directory, not a path). You can provide inputFileName optionally OR pass a blank string.

checkLangDef

checkLangDef(langFile: string): void

Check if the language definition file (in the data directory) is valid. It will throw an error if it is invalid.

checkOutLangDef

checkOutLangDef(outLangFile: string): void

Check if the output format specification file (in the data directory) is valid. It will throw an error if it is invalid.

setDataDir

setDataDir(dataDir: string): void

Set the data directory. By default, this will be a directory with all the language definition files and output formats that ship with GNU source-highlight.

setStyleFile

setStyleFile(styleFile: string): void

Set the style file.

setStyleCssFile

setStyleCssFile(cssFile: string): void

Use a CSS style file.

setStyleDefaultFile

setStyleDefaultFile(styleFile: string): void

Set the default style file.

setTitle

setTitle(title: string): void

setInputLang

setInputLang(inputLang: string): void

Set the input language to use when it can't be inferred.

setCss

setCss(css: string): void

setHeaderFileName

setHeaderFileName(headerFileName: string): void

Set the header file to be prepended to the output document.

setFooterFileName

setFooterFileName(footerFileName: string): void

Set the footer file to be appended to the output document.

setOutputDir

setOutputDir(outputDir: string): void