11import gulp = require( 'gulp' ) ;
22const markdown = require ( 'gulp-markdown' ) ;
33const transform = require ( 'gulp-transform' ) ;
4+ const hljs = require ( 'highlight.js' ) ;
45import { task } from 'gulp' ;
56import * as path from 'path' ;
67
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-
148// Our docs contain comments of the form `<!-- example(...) -->` which serve as placeholders where
159// example code should be inserted. We replace these comments with divs that have a
1610// `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;
1913
2014gulp . task ( 'docs' , ( ) => {
2115 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+ } ) )
2328 . pipe ( transform ( ( content : string ) =>
2429 content . toString ( ) . replace ( EXAMPLE_PATTERN , ( match : string , name : string ) =>
2530 `<div material-docs-example="${ name } "></div>` ) ) )
0 commit comments