nxt-highlightjs
TypeScript icon, indicating that this package has built-in type declarations

19.1.0 • Public • Published

Angular Highlight.js directives

GitHub license npm scope

Angular code highlighting directives with optional line numbers and support for SSR.

Quick links

Installing

npm install --save nxt-highlightjs highlight.js

Load and configure Highlight.js

import { ApplicationConfig } from '@angular/core'
import { provideHighlightOptions } from 'nxt-highlightjs'

export const appConfig: ApplicationConfig = {
    providers: [
        provideHighlightOptions({
            fullLibraryLoader: () => import('highlight.js')
        })
    ]
}

Above code loads the entire Highlight.js library. To improve performance you might want to load only the core library and neccesary languages.

import { ApplicationConfig } from '@angular/core'
import { provideHighlightOptions } from 'nxt-highlightjs'

export const appConfig: ApplicationConfig = {
    providers: [
        provideHighlightOptions({
            coreLibraryLoader: () => import('highlight.js/lib/core'),
            lineNumbersLoader: () => import('nxt-highlightjs/line-numbers'), // Optional, add line numbers if needed
            languages: {
                typescript: () => import('highlight.js/lib/languages/typescript'),
                css: () => import('highlight.js/lib/languages/css'),
                xml: () => import('highlight.js/lib/languages/xml')
            },
            themePath: 'path-to-theme.css' // Optional, useful for dynamic theme changes
        })
    ]
}

Use it in a template

<pre><code [nxtHighlight]="code"
    language="html"></code></pre>

Package Sidebar

Install

npm i nxt-highlightjs

Weekly Downloads

0

Version

19.1.0

License

MIT

Unpacked Size

142 kB

Total Files

32

Last publish

Collaborators

  • hitko