9.0.0 • Published 3 years ago

angular2-highlight-js v9.0.0

Weekly downloads
466
License
MIT
Repository
github
Last release
3 years ago

angular2-highlight-js

highlight.js integration with Angular.

Quick links

Installation

npm install --save angular2-highlight-js@latest highlight.js

Usage

Add the highlight.js css for the style you want to use to your app's styles in angular.json.

 "styles": [
             "./node_modules/highlight.js/styles/monokai-sublime.css",
              ...
            ],

In app.module.ts import the highlight.js library and any languages you will be highlighting.

import { registerLanguage } from 'highlight.js';
import javascript from 'highlight.js/lib/languages/javascript';
import typescript from 'highlight.js/lib/languages/typescript';

registerLanguage('typescript', typescript);
registerLanguage('javascript', javascript);

Import the AngularHighlightJsModule.

import { AngularHighlightJsModule } from 'angular2-highlight-js';
@NgModule({
  declarations: [AppComponent],
  imports: [...AngularHighlightJsModule],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

This library contains the HighlightJsContentDirective Below are usage notes for each. A demo app is also available as in the repo.

For hljsContent directive

Use this to highlight the contents of and element which will be set dynamically (by setting innerHTML for example).

Import the directive and declare it.

@Component({
    selector: 'demo',
    templateUrl: 'demo.component.html',
    styleUrls: ['demo.component.css']
})

Add the attribute hljsContent to the element which will have content that requires highlighting. When the content is changed the directive will look for all child elements which match the selector provided and highlight them. If no selector is given it will default to finding all code elements.

<section [innerHTML]="sampleContent" hljsContent=".highlight"></section>

You can configure highlight.js by using the options property on the directive

<section
  [innerHTML]="sampleContent"
  hljsContent=".highlight"
  [options]="{ useBr: true }"
></section>
9.0.0

3 years ago

8.0.1

5 years ago

8.0.1-beta.6

5 years ago

8.0.1-beta.5

5 years ago

8.0.1-beta.4

5 years ago

8.0.1-beta.3

5 years ago

8.0.1-beta.2

5 years ago

8.0.1-beta.1

5 years ago

8.0.1-alpha.5

5 years ago

8.0.1-alpha.4

5 years ago

8.0.1-alpha.3

5 years ago

8.0.1-alpha.2

5 years ago

8.0.1-alpha.1

5 years ago

8.0.1-alpha

5 years ago

6.0.1-alpha

7 years ago

6.0.0-alpha

7 years ago

5.0.2

7 years ago

5.0.1

7 years ago

5.0.0

7 years ago

5.0.0-alpha

7 years ago

4.0.0

7 years ago

4.0.0-alpha

7 years ago

3.0.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

2.0.0-alpha.3

8 years ago

2.0.0-alpha.2

8 years ago

2.0.0-alpha.1

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago