@@ -5,6 +5,7 @@ const highlight = require('gulp-highlight-files');
5
5
const rename = require ( 'gulp-rename' ) ;
6
6
const flatten = require ( 'gulp-flatten' ) ;
7
7
const hljs = require ( 'highlight.js' ) ;
8
+ const dom = require ( 'gulp-dom' ) ;
8
9
import { task } from 'gulp' ;
9
10
import * as path from 'path' ;
10
11
@@ -19,6 +20,24 @@ const EXAMPLE_PATTERN = /<!--\W*example\(([^)]+)\)\W*-->/g;
19
20
// documentation page. Using a RegExp to rewrite links in HTML files to work in the docs.
20
21
const LINK_PATTERN = / ( < a [ ^ > ] * ) h r e f = " ( [ ^ " ] * ) " / g;
21
22
23
+ // HTML tags in the markdown generated files that should receive a .docs-markdown-${tagName} class
24
+ // for styling purposes.
25
+ const MARKDOWN_TAGS_TO_CLASS_ALIAS = [
26
+ 'a' ,
27
+ 'h1' ,
28
+ 'h2' ,
29
+ 'h3' ,
30
+ 'h4' ,
31
+ 'h5' ,
32
+ 'li' ,
33
+ 'ol' ,
34
+ 'p' ,
35
+ 'table' ,
36
+ 'tbody' ,
37
+ 'td' ,
38
+ 'th'
39
+ ] ;
40
+
22
41
gulp . task ( 'docs' , [ 'markdown-docs' , 'highlight-docs' , 'api-docs' ] )
23
42
24
43
gulp . task ( 'markdown-docs' , ( ) => {
@@ -36,6 +55,15 @@ gulp.task('markdown-docs', () => {
36
55
}
37
56
} ) )
38
57
. pipe ( transform ( transformMarkdownFiles ) )
58
+ . pipe ( dom ( function ( ) {
59
+ MARKDOWN_TAGS_TO_CLASS_ALIAS . forEach ( ( tag ) => {
60
+ Array . prototype . slice . call ( this . querySelectorAll ( tag ) ) . forEach ( ( el : any ) => {
61
+ el . classList . add ( `docs-markdown-${ tag } ` ) ;
62
+ } ) ;
63
+ } ) ;
64
+
65
+ return this ;
66
+ } ) )
39
67
. pipe ( gulp . dest ( 'dist/docs/markdown' ) ) ;
40
68
} ) ;
41
69
@@ -47,10 +75,10 @@ gulp.task('highlight-docs', () => {
47
75
} ;
48
76
49
77
return gulp . src ( 'src/examples/**/*.+(html|css|ts)' )
50
- . pipe ( flatten ( ) )
51
- . pipe ( rename ( renameFile ) )
52
- . pipe ( highlight ( ) )
53
- . pipe ( gulp . dest ( 'dist/docs/examples' ) ) ;
78
+ . pipe ( flatten ( ) )
79
+ . pipe ( rename ( renameFile ) )
80
+ . pipe ( highlight ( ) )
81
+ . pipe ( gulp . dest ( 'dist/docs/examples' ) ) ;
54
82
} ) ;
55
83
56
84
task ( 'api-docs' , ( ) => {
@@ -93,4 +121,4 @@ function fixMarkdownDocLinks(link: string, filePath: string): string {
93
121
// Temporary link the file to the /guide URL because that's the route where the
94
122
// guides can be loaded in the Material docs.
95
123
return `guide/${ baseName } ` ;
96
- }
124
+ }
0 commit comments