1
1
import gulp = require( 'gulp' ) ;
2
2
const markdown = require ( 'gulp-markdown' ) ;
3
3
const transform = require ( 'gulp-transform' ) ;
4
+ const hljs = require ( 'highlight.js' ) ;
4
5
import { task } from 'gulp' ;
5
6
import * as path from 'path' ;
6
7
7
- import { SOURCE_ROOT , PROJECT_ROOT } from '../constants' ;
8
- import {
9
- execNodeTask
10
- } from '../task_helpers' ;
11
-
12
- const typedocPath = path . relative ( PROJECT_ROOT , path . join ( SOURCE_ROOT , 'lib/typedoc.json' ) ) ;
13
-
14
8
// Our docs contain comments of the form `<!-- example(...) -->` which serve as placeholders where
15
9
// example code should be inserted. We replace these comments with divs that have a
16
10
// `material-docs-example` attribute which can be used to locate the divs and initialize the example
@@ -19,7 +13,18 @@ const EXAMPLE_PATTERN = /<!--\W*example\(([^)]+)\)\W*-->/g;
19
13
20
14
gulp . task ( 'docs' , ( ) => {
21
15
return gulp . src ( [ 'src/lib/**/*.md' ] )
22
- . pipe ( markdown ( ) )
16
+ . pipe ( markdown ( {
17
+ // Add syntax highlight using highlight.js
18
+ highlight : ( code : string , language : string ) => {
19
+ if ( language ) {
20
+ // highlight.js expects "typescript" written out, while Github supports "ts".
21
+ let lang = language . toLowerCase ( ) === 'ts' ? 'typescript' : language ;
22
+ return hljs . highlight ( lang , code ) . value ;
23
+ }
24
+
25
+ return code ;
26
+ }
27
+ } ) )
23
28
. pipe ( transform ( ( content : string ) =>
24
29
content . toString ( ) . replace ( EXAMPLE_PATTERN , ( match : string , name : string ) =>
25
30
`<div material-docs-example="${ name } "></div>` ) ) )
0 commit comments