Skip to content

Commit 41fc641

Browse files
committed
Add highlight.js lib
Add highlight-directive to highlight code-blocks
1 parent f646196 commit 41fc641

9 files changed

Lines changed: 56 additions & 9 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@types/lodash": "^4.14.136",
2525
"bootstrap": "^4.3.1",
2626
"font-awesome": "^4.7.0",
27+
"highlight.js": "^9.15.9",
2728
"lodash": "^4.17.15",
2829
"rxjs": "~6.4.0",
2930
"tslib": "^1.10.0",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {Directive, ElementRef, AfterViewInit} from "@angular/core";
2+
import hlJs from "highlight.js/lib/highlight";
3+
import cs from "highlight.js/lib/languages/cs";
4+
hlJs.registerLanguage("csharp", cs);
5+
6+
@Directive({
7+
selector: "code[appHighlight]"
8+
})
9+
export class HighlightDirective implements AfterViewInit {
10+
constructor (private elRef: ElementRef) {}
11+
12+
ngAfterViewInit() {
13+
hlJs.highlightBlock(this.elRef.nativeElement);
14+
}
15+
}

src/app/shared/directives/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {HighlightDirective} from "./highlight.directive";
2+
3+
export const DIRECTIVES: any[] = [
4+
HighlightDirective
5+
];

src/app/shared/shared.module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@ import {RouterModule} from "@angular/router";
44

55
import * as fromContainers from "./containers";
66
import * as fromComponents from "./components";
7+
import * as fromDirectives from "./directives";
78

89
@NgModule({
910
declarations: [
1011
...fromContainers.CONTAINERS,
11-
...fromComponents.COMPONENTS
12+
...fromComponents.COMPONENTS,
13+
...fromDirectives.DIRECTIVES
1214
],
1315
imports: [
1416
CommonModule,
1517
RouterModule
1618
],
1719
exports: [
1820
...fromContainers.CONTAINERS,
19-
...fromComponents.COMPONENTS
21+
...fromComponents.COMPONENTS,
22+
...fromDirectives.DIRECTIVES
2023
]
2124
})
2225
export class SharedModule {

src/app/version1.0.0/components/getting-started/getting-started.component.html

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,8 @@ <h2>Basic guid</h2>
5757
<p>
5858
Let's start with creating a new class called <code>Person</code>.
5959
</p>
60-
<pre>
61-
<code class="language-javascript">
62-
<!-- public class Person {
63-
public string Name {get; set;}
64-
public int Age {get; set;}
65-
} -->
66-
</code>
60+
<pre class="code-block">
61+
<code appHighlight>{{person1}}</code>
6762
</pre>
6863
</div>
6964
</ng-container>

src/app/version1.0.0/components/getting-started/getting-started.component.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ export class GettingStartedComponent implements OnInit {
1515
previous: IPost;
1616
next: IPost;
1717

18+
//#region Codes
19+
person1 = `
20+
public class Person {
21+
public string Name {get; set;}
22+
public int Age {get; set;}
23+
}`;
24+
//#endregion
25+
1826
ngOnInit(): void {
1927
this.post = DocService.findPost(this.versionId, this.postId);
2028

src/styles/components/_code.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* Import highlight.js style from node_modules */
2+
@import "highlight.js/scss/vs.scss";
3+
4+
.code-block {
5+
background-color: #f0f0f0;
6+
padding: 0;
7+
margin: 0;
8+
}
9+
10+
.hljs {
11+
padding: 0;
12+
background-color: #f0f0f0;
13+
display: inline;
14+
}

src/styles/components/_index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/* Individual Components */
88
@import "anchor";
99
@import "button";
10+
@import "code";
1011

1112
/* Angular Components*/
1213
@import "post-wrapper";

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3017,6 +3017,11 @@ hash.js@^1.0.0, hash.js@^1.0.3:
30173017
inherits "^2.0.3"
30183018
minimalistic-assert "^1.0.1"
30193019

3020+
highlight.js@^9.15.9:
3021+
version "9.15.9"
3022+
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.15.9.tgz#865257da1dbb4a58c4552d46c4b3854f77f0e6d5"
3023+
integrity sha512-M0zZvfLr5p0keDMCAhNBp03XJbKBxUx5AfyfufMdFMEP4N/Xj6dh0IqC75ys7BAzceR34NgcvXjupRVaHBPPVQ==
3024+
30203025
hmac-drbg@^1.0.0:
30213026
version "1.0.1"
30223027
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"

0 commit comments

Comments
 (0)