@@ -9,6 +9,7 @@ const highlight = require('gulp-highlight-files');
9
9
const rename = require ( 'gulp-rename' ) ;
10
10
const flatten = require ( 'gulp-flatten' ) ;
11
11
const hljs = require ( 'highlight.js' ) ;
12
+ const dom = require ( 'gulp-dom' ) ;
12
13
13
14
// Our docs contain comments of the form `<!-- example(...) -->` which serve as placeholders where
14
15
// example code should be inserted. We replace these comments with divs that have a
@@ -21,6 +22,26 @@ const EXAMPLE_PATTERN = /<!--\W*example\(([^)]+)\)\W*-->/g;
21
22
// documentation page. Using a RegExp to rewrite links in HTML files to work in the docs.
22
23
const LINK_PATTERN = / ( < a [ ^ > ] * ) h r e f = " ( [ ^ " ] * ) " / g;
23
24
25
+ // HTML tags in the markdown generated files that should receive a .docs-markdown-${tagName} class
26
+ // for styling purposes.
27
+ const MARKDOWN_TAGS_TO_CLASS_ALIAS = [
28
+ 'a' ,
29
+ 'h1' ,
30
+ 'h2' ,
31
+ 'h3' ,
32
+ 'h4' ,
33
+ 'h5' ,
34
+ 'li' ,
35
+ 'ol' ,
36
+ 'p' ,
37
+ 'table' ,
38
+ 'tbody' ,
39
+ 'td' ,
40
+ 'th' ,
41
+ 'tr' ,
42
+ 'ul'
43
+ ] ;
44
+
24
45
task ( 'docs' , [ 'markdown-docs' , 'highlight-docs' , 'api-docs' ] ) ;
25
46
26
47
task ( 'markdown-docs' , ( ) => {
@@ -38,6 +59,7 @@ task('markdown-docs', () => {
38
59
}
39
60
} ) )
40
61
. pipe ( transform ( transformMarkdownFiles ) )
62
+ . pipe ( dom ( createTagNameAliaser ( 'docs-markdown' ) ) )
41
63
. pipe ( dest ( 'dist/docs/markdown' ) ) ;
42
64
} ) ;
43
65
@@ -49,10 +71,10 @@ task('highlight-docs', () => {
49
71
} ;
50
72
51
73
return src ( 'src/examples/**/*.+(html|css|ts)' )
52
- . pipe ( flatten ( ) )
53
- . pipe ( rename ( renameFile ) )
54
- . pipe ( highlight ( ) )
55
- . pipe ( dest ( 'dist/docs/examples' ) ) ;
74
+ . pipe ( flatten ( ) )
75
+ . pipe ( rename ( renameFile ) )
76
+ . pipe ( highlight ( ) )
77
+ . pipe ( dest ( 'dist/docs/examples' ) ) ;
56
78
} ) ;
57
79
58
80
task ( 'api-docs' , ( ) => {
@@ -95,3 +117,20 @@ function fixMarkdownDocLinks(link: string, filePath: string): string {
95
117
// guides can be loaded in the Material docs.
96
118
return `guide/${ baseName } ` ;
97
119
}
120
+
121
+ /**
122
+ * Returns a function to be called with an HTML document as its context that aliases HTML tags by
123
+ * adding a class consisting of a prefix + the tag name.
124
+ * @param classPrefix The prefix to use for the alias class.
125
+ */
126
+ function createTagNameAliaser ( classPrefix : string ) {
127
+ return function ( ) {
128
+ MARKDOWN_TAGS_TO_CLASS_ALIAS . forEach ( tag => {
129
+ for ( let el of this . querySelectorAll ( tag ) ) {
130
+ el . classList . add ( `${ classPrefix } -${ tag } ` ) ;
131
+ }
132
+ } ) ;
133
+
134
+ return this ;
135
+ } ;
136
+ }
0 commit comments