Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.

Commit bfb948e

Browse files
committed
added highlight.js
1 parent a6985eb commit bfb948e

File tree

6 files changed

+47
-8
lines changed

6 files changed

+47
-8
lines changed

ngsw-manifest.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
{"url": "https://fonts.googleapis.com/icon?family=Material+Icons"},
55
{"url": "https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700"},
66
{"url": "https://ajax.googleapis.com/ajax/libs/hammerjs/2.0.8/hammer.min.js"},
7-
{"url": "https://cdnjs.cloudflare.com/ajax/libs/web-animations/2.2.5/web-animations.min.js"}
7+
{"url": "https://cdnjs.cloudflare.com/ajax/libs/web-animations/2.2.5/web-animations.min.js"},
8+
{"url": "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/styles/monokai_sublime.min.css"},
9+
{"url": "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/highlight.min.js"},
10+
{"url": "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/languages/typescript.min.js"}
811
]
912
}
1013
}

src/app/app.component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Component } from '@angular/core';
33
class Menu {
44
title: string;
55
link: string;
6-
options: { exact: boolean };
6+
options: { exact: boolean };
77
}
88

99
@Component({
@@ -13,25 +13,25 @@ class Menu {
1313
})
1414
export class AppComponent {
1515
menus: Menu[] = [
16-
{
16+
{
1717
title: 'Home',
1818
link: '/',
1919
options: { exact: true }
2020
},
21-
{
21+
{
2222
title: 'Operators',
2323
link: '/operators',
2424
options: { exact: false }
2525
},
26-
{
26+
{
2727
title: 'Companies',
2828
link: '/companies',
2929
options: { exact: false }
3030
},
31-
{
31+
{
3232
title: 'Team',
3333
link: '/team',
3434
options: { exact: false }
3535
}
36-
]
36+
];
3737
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Directive, ElementRef, Input, OnInit, AfterViewChecked, NgZone } from '@angular/core';
2+
3+
declare var hljs: any;
4+
5+
/*
6+
* Modified from Angular2 Highlight Package
7+
* (https://github.com/jaychase/angular2-highlight-js)
8+
*/
9+
@Directive({
10+
selector: '[appHighlightJs]'
11+
})
12+
export class HighlightJsDirective implements AfterViewChecked {
13+
private _done: boolean;
14+
15+
constructor(
16+
private elementRef: ElementRef,
17+
private zone: NgZone) {}
18+
19+
ngAfterViewChecked() {
20+
if (!this._done) {
21+
if (this.elementRef.nativeElement.innerHTML && this.elementRef.nativeElement.querySelector) {
22+
const snippets = this.elementRef.nativeElement.querySelectorAll('code');
23+
this.zone.runOutsideAngular(() => {
24+
for (const snippet of snippets) {
25+
hljs.highlightBlock(snippet);
26+
}
27+
});
28+
this._done = true;
29+
}
30+
}
31+
}
32+
}

src/app/operators/operators.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { OperatorsComponent } from './operators.component';
77
import { OperatorComponent } from './operator/operator.component';
88
import { OperatorHeaderComponent } from './operator/operator-header/operator-header.component';
99

10-
import { OperatorScrollDirective } from './operator-scroll.directive';
10+
import { OperatorScrollDirective } from './directives/operator-scroll.directive';
11+
import { HighlightJsDirective } from './directives/highlight-js.directive';
1112

1213
const OPERATOR_ROUTES = [
1314
{

src/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
<link rel="manifest" href="manifest.json">
1212
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
1313
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700" rel="stylesheet">
14+
<link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/styles/monokai_sublime.min.css" rel="stylesheet">
1415
</head>
1516
<body>
1617
<app-root></app-root>
1718
<script src="https://ajax.googleapis.com/ajax/libs/hammerjs/2.0.8/hammer.min.js"></script>
1819
<script src="https://cdnjs.cloudflare.com/ajax/libs/web-animations/2.2.5/web-animations.min.js"></script>
20+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/highlight.min.js"></script>
21+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/languages/typescript.min.js"></script>
1922
</body>
2023
</html>

0 commit comments

Comments
 (0)