Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-highlightjs

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-highlightjs

Instant code highlighting, auto-detect language, super easy to use.

  • 1.2.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
58K
increased by7.03%
Maintainers
1
Weekly downloads
 
Created
Source

Angular Highlight.js

npm npm Build Status npm

Instant code highlighting, auto-detect language, super easy to use


Table of Contents

Installation

  1. Install it with npm
$ npm install --save ngx-highlightjs
  1. Head to highlight.js download page and get your custom package bundle including only the languages you need.

  2. Create new folder in src/assets/lib/hljs and extract the downloaded zip file there.

Usage

Import HighlightModule library from any module:

import { HighlightModule } from 'ngx-highlightjs';

@NgModule({
  imports: [
    // ...
    HighlightModule.forRoot()
  ]
})
export class AppModule { }

The function forRoot accepts 1 optional parameters, forRoot(options?: HighlightOptions)

With options parameter you can set:

  • theme: select the theme, use theme's name without the extension, default: 'github'
  • path: hljs library location, default: 'assets/lib/hljs'
  • auto: auto-highlight when code's text changes, default: true

Choose highlighting theme:

    HighlightModule.forRoot({ theme: 'agate'});

List of all available themes from highlight.js

Import highlight.js library from a custom path

   const options: HighlightOptions = {
     theme: 'agate',
     path: 'assets/js/highlight-js'
   };

   HighlightModule.forRoot(options);

Now you can use the directive highlight, you can:

  • Highlight a code element
<!-- Highlight target element -->
<pre><code highlight [code]="someCode"></code></pre>
<!-- Or -->
<pre><code highlight [textContent]="someCode"></code></pre>
  • Highlight all child code elements
<!-- Highlight child elements of type <pre><code> -->
<div highlight="all">
  <pre><code [textContent]="htmlCode"></code></pre>
  <pre><code [textContent]="tsCode"></code></pre>
  <pre><code [textContent]="cssCode"></code></pre>
</div>
  • Highlight custom elements
<!-- Highlight custom child elements -->
<div highlight="section code">
  <section><code [textContent]="pythonCode"></code></section>
  <section><code [textContent]="swiftCode"></code></section>
</div>

Options

  • [highlight]: string, default ''

    • Use just highlight on the element to highlight it.
    • Use highlight="all" to highlight all child code elements.
    • Use highlight="{selector}" to highlight custom child elements.
  • [code]: string, default null

Development

This project uses ng-packagr for development.

Use the following command to build

$ npm run packagr

Issues

If you identify any errors in the library, or have an idea for an improvement, please open an issue.

Author

Murhaf Sousli

More plugins

Keywords

FAQs

Package last updated on 27 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc