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

snippet-highlight

v1.0.2

Published

A lightweight, easy-to-use and framework agnostic syntax highlighter for your code examples(snippets) in web applications

Downloads

976

Readme

snippet-highlight

A lightweight, easy-to-use and framework agnostic syntax highlighter for your code examples(snippets) in web applications

Why another code highlighter?

There are many syntax highlighters avaliable already but most of those are either complex to setup or front end framework specific. snippet-highlight is built using concepts of web components. You can use it everywhere, i.e. Angular, React, Vue, any framework, No Framework!

Index

Usage

  • Install/Include dependency (npm module or script)
  • Add Selector and pass attributes in your HTML page
  <snippet-highlight theme="dark" language="javascript" content="your code-snippet"/>

Installation

  1. Install as npm module

    npm i snippet-highlight

    OR

    yarn add snippet-highlight
  2. Or, Include as script on your HTML page

    <script src="https://unpkg.com/snippet-highlight/dist/snippet-highlight.js"></script>

Framework Integration

No Framework or Any Framework

  • Include the script as shown above
  • Use the selector as shown in usage

Angular

Using snippet-highlight within an Angular CLI project is a two-step process. We need to:

  1. Include the CUSTOM_ELEMENTS_SCHEMA in the modules that use the components
  2. Call defineCustomElements(window) from main.ts (or some other appropriate place)

Including the Custom Elements Schema

Including the CUSTOM_ELEMENTS_SCHEMA in the module allows the use of the web components in the HTML markup without the compiler producing errors. Here is an example of adding it to AppModule:

import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';

@NgModule({
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class AppModule {}

The CUSTOM_ELEMENTS_SCHEMA needs to be included in any module that uses custom elements.

Calling defineCustomElements

snippet-highlight includes a main function that is used to load the components in the collection. That function is called defineCustomElements() and it needs to be called once during the bootstrapping of your application. One convenient place to do this is in main.ts as such:

import { defineCustomElements } from 'snippet-highlight/dist/loader';

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.log(err));
defineCustomElements(window);

React

With an application built using the create-react-app script the easiest way to include the component library is to call defineCustomElements(window) from the index.js file.

import { defineCustomElements } from 'snippet-highlight/dist/loader';
defineCustomElements(window);

Vue

In order to use the custom element library within the Vue app, the application must be modified to define the custom elements and to inform the Vue compiler which elements to ignore during compilation. This can all be done within the main.js file. For example:

import Vue from 'vue';
import App from './App.vue';
import { defineCustomElements } from 'snippet-highlight/dist/loader';

Vue.config.productionTip = false;
Vue.config.ignoredElements = [/snippet-\w*/];

defineCustomElements(window);

new Vue({
  render: h => h(App)
}).$mount('#app');

Properties

Supported Languages

clike, ruby, crystal, csharp, dotnet, markup-templating, markup, xml, html, mathml, svg, django, jinja2, javascript, js, csp, css, d, dart, diff, docker, dockerfile, eiffel, elixir, elm, erb, erlang, flow, fortran, fsharp, gedcom, gherkin, git, glsl, go, graphql, groovy, haml, handlebars, haskell, haxe, hpkp, hsts, http, ichigojam, icon, inform7, ini, io, j, java, jolie, json, jsonp, jsx, julia, keyman, kotlin, latex, less, liquid, lisp, elisp, emacs, emacs-lisp, livescript, lolcode, lua, makefile, markdown, matlab, mel, mizar, monkey, n4js, n4jsd, nasm, nginx, nim, nix, nsis, ocaml, oz, parigp, parser, pascal, objectpascal, perl, php, sql, plsql, powershell, processing, prolog, properties, protobuf, pug, puppet, pure, python, q, qore, r, reason, renpy, rest, rip, roboconf, rust, sas, sass, scala, scheme, scss, smalltalk, smarty, soy, stylus, swift, tap, tcl, textile, tsx, tt2, twig, typescript, ts, velocity, verilog, vhdl, vim, visual-basic, vb, wasm, wiki, xeora, xeoracube, xojo, xquery, yaml

Demo

Dark Theme

Dark Theme HTML

Light Theme

Light Theme Groovy