Skip to content

Commit 66377ac

Browse files
committed
class alias tags in html generated from markdown
1 parent f40b1b2 commit 66377ac

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"gulp-clean-css": "^2.3.2",
6969
"gulp-cli": "^1.2.2",
7070
"gulp-connect": "^5.0.0",
71+
"gulp-dom": "^0.9.17",
7172
"gulp-flatten": "^0.3.1",
7273
"gulp-highlight-files": "0.0.4",
7374
"gulp-htmlmin": "^3.0.0",

tools/gulp/tasks/docs.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const highlight = require('gulp-highlight-files');
55
const rename = require('gulp-rename');
66
const flatten = require('gulp-flatten');
77
const hljs = require('highlight.js');
8+
const dom = require('gulp-dom');
89
import {task} from 'gulp';
910
import * as path from 'path';
1011

@@ -19,6 +20,24 @@ const EXAMPLE_PATTERN = /<!--\W*example\(([^)]+)\)\W*-->/g;
1920
// documentation page. Using a RegExp to rewrite links in HTML files to work in the docs.
2021
const LINK_PATTERN = /(<a[^>]*) href="([^"]*)"/g;
2122

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+
2241
gulp.task('docs', ['markdown-docs', 'highlight-docs', 'api-docs'])
2342

2443
gulp.task('markdown-docs', () => {
@@ -36,6 +55,15 @@ gulp.task('markdown-docs', () => {
3655
}
3756
}))
3857
.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+
}))
3967
.pipe(gulp.dest('dist/docs/markdown'));
4068
});
4169

@@ -47,10 +75,10 @@ gulp.task('highlight-docs', () => {
4775
};
4876

4977
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'));
5482
});
5583

5684
task('api-docs', () => {
@@ -93,4 +121,4 @@ function fixMarkdownDocLinks(link: string, filePath: string): string {
93121
// Temporary link the file to the /guide URL because that's the route where the
94122
// guides can be loaded in the Material docs.
95123
return `guide/${baseName}`;
96-
}
124+
}

0 commit comments

Comments
 (0)