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

@nowzoo/ngx-highlight-js

v2.1.15

Published

Angular component and service for highlight.js

Downloads

47

Readme

ngx-highlight-js

Angular component and service for Highlight.js. Works with remote URLs or strings/variables. Loads highlight.js core, languages and themes as needed.

Demo

Quick Start

Install the library and the @nowzoo/sheetload dependency with NPM...

npm i @nowzoo/ngx-highlight-js @nowzoo/sheetload --save

Import into AppModule with NgxHighlightJsModule.forRoot()...

import { NgxHighlightJsModule } from '@nowzoo/ngx-highlight-js';
// other imports...
@NgModule({
imports: [
  NgxHighlightJsModule.forRoot(),
  // other imports...
]
})
export class MyModule { }

Add an NgxHighlightJsComponent. You can provide an absolute or relative URL with the url input...

<ngx-highlight-js lang="scss"
  url="https://raw.githubusercontent.com/twbs/bootstrap/v4.1.1/scss/_variables.scss">
</ngx-highlight-js>

Or use the code input to use a string or a variable...

<!-- string... -->
<ngx-highlight-js lang="bash"
  code="npm i @nowzoo/ngx-highlight-js --save"></ngx-highlight-js>
<!-- variable... -->
<ngx-highlight-js lang="bash"
  [code]="myVar"></ngx-highlight-js>

API

Module: NgxHighlightJsModule

static forRoot()

Global Options

Change the default theme:

The default theme is loaded by default. To change this on an app-wide basis, provide an alternate value for NGX_HIGHLIGHT_JS_DEFAULT_THEME:

@NgModule({
  providers: [
    {provide: NGX_HIGHLIGHT_JS_DEFAULT_THEME, useValue: 'atelier-cave-dark'}
  ]
})
export class AppModule { }

Change the CDN URL:

By default, Highlight.js assets are downloaded from //cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0. Change this with NGX_HIGHLIGHT_JS_DEFAULT_THEME:

@NgModule({
  providers: [
    {provide: NGX_HIGHLIGHT_JS_DEFAULT_THEME, useValue: '/path/to/highlight-js'}
  ]
})
export class AppModule { }

Service: NgxHighlightJsService

Methods

loaded(): Promise<any>
Ensures highlight.js is loaded, then resolves with the global hljs instance.

loadLanguage(lang: string): Promise<void>
Resolves after ensuring the javascript to format the language has been loaded.

loadTheme(theme: string): Promise<void>
Resolves after the stylesheet for the theme has loaded. Use the basename of the theme, like 'dracula'. Only one theme can be loaded at a time.

highlight(lang: string, code: string): Promise<string>
Highlights code with lang.

Properties

theme: string
The currently loaded theme.

Component: NgxHighlightJsComponent

selector: ngx-highlight-js | exportAs: ngxHighlightJs

Inputs

code: string
A string containing the code you want to highlight.

url: string
A URL with the code you want to highlight.

lang: string
Required. The language.

Properties

isInitializing: boolean True when highlighting (or re-highlighting) the code.

error: string Set if highlighting fails.

Contributing

Contributions are welcome.

git clone https://github.com/nowzoo/ngx-highlight-js.git
npm i
ng build ngx-highlight-js --prod

The library code is located under projects/ngx-highlight-js.

Testing the library...

ng test ngx-highlight-js

You can also use Wallaby for testing. Use the config found at projects/ngx-highlight-js/wallaby.js.

Building the library...

ng build ngx-highlight-js --prod

The demo code is in src. Run the demo locally...

# Build the current version of the library first...
ng build ngx-highlight-js --prod

ng serve --open

License

MIT