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

@nicholas-morgan/code-highlighter

v1.0.5

Published

A jQuery plugin to add HTML markup to various types of computer programming code to make it display and appear beautifully within a HTML document.

Downloads

56

Readme

codeHighlighter

A jQuery plugin to add HTML markup to various types of computer programming code to make it display and appear beautifully within a HTML document.

Homepage: https://skcin7.github.io/codeHighlighter

Demo: https://skcin7.github.io/codeHighlighter/demo

Installing with NPM

To install codeHighlighter with NPM:

npm i @nicholas-morgan/code-highlighter

For more information, see the NPM published package page.

How To Use

Simply include the jquery.codeHighlighter.js (or the jquery.codeHighlighter.min.js) file and place the following somewhere within the JavaScript code of your web application (NOTE: make sure jQuery is included too, obviously):

Initialize codeHighlighter

$(function () {
    $.codeHighlighter();
});

codeHighlighter will now be applied to all nodes in your HTML document which have the codeHighlighter CSS class applied to it. For example:

<div class="codeHighlighter" data-language="json">{"some_json_key": "some_json_value", "etc": "etc"}</div>

In the above example, the raw/unformatted JSON in the div node will now be formatted in to beautiful looking JSON!

Settings/Configuration

codeHighlighter is configurable, which is easy to do. Each configuration setting may be applied on a per-instance basis or a per-case basis.

$(function () {
    $.codeHighlighter({
        "highlight": true,    // Whether or not to process the highlighting. Set to false to disable the highlighting from taking place.
        "linebreaks": true,   // Whether or not linebreaks should be added to the final outputted code
        "tabSize": 4,         // The size each tab should be in the outputted code (only applicable if the outputted code uses linebreaks)
    });
});

You may also change the configuration for each individual element within the HTML document by using the data- attributes of the individual element. Here's some examples:

The following will NOT process the highlighting, because of the data-highlight=false data attribute:

<div class="codeHighlighter" data-language="json" data-highlight="false">{"some_json_key": "some_json_value", "etc": "etc"}</div>

The following changes the linebreaks and tab size to be used for the final processed code to be displayed in the HTML document:

<div class="codeHighlighter" data-language="json" data-highlight="true" data-linebreaks="false" data-tab-size="2">{"some_json_key": "some_json_value", "etc": "etc"}</div>

CSS

codeHighlighter relies on some CSS code in order for the highlighting to be properly displayed, for adding things like color. Make sure you include the CSS. If your project uses a CSS pre-processor such as SCSS (which I use), you may add the SCSS to your project, which is located in the /src/scss directory within this repository. You may also just add the raw CSS code too. If you're in need of something like codeHighlighter, I imagine that this is second-nature and hopefully very obvious to you.

You may extend or alter the CSS (if you want) by adding additional CSS code that will overwrite the default CSS.

.codeHighlighter {
    font-family: "Courier New", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 12px;
    line-height: 1.5;
}

If you do add any custom CSS code, make sure you add it AFTER codeHighlighter's CSS code (or use !important in each CSS property) , or else the codeHighlighter CSS code will take priority (in which case your custom CSS would not take effect).

Contributing

Please see CONTRIBUTE.md for information regarding contributing.

Demo

Please refer to the demo page for some examples which demonstrate how codeHighlighter works.