Skip to content

Commit ea84c7f

Browse files
committed
class alias tags in html generated from markdown
1 parent ce0e933 commit ea84c7f

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
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": "^3.0.3",
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: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const highlight = require('gulp-highlight-files');
99
const rename = require('gulp-rename');
1010
const flatten = require('gulp-flatten');
1111
const hljs = require('highlight.js');
12+
const dom = require('gulp-dom');
1213

1314
// Our docs contain comments of the form `<!-- example(...) -->` which serve as placeholders where
1415
// example code should be inserted. We replace these comments with divs that have a
@@ -21,6 +22,24 @@ const EXAMPLE_PATTERN = /<!--\W*example\(([^)]+)\)\W*-->/g;
2122
// documentation page. Using a RegExp to rewrite links in HTML files to work in the docs.
2223
const LINK_PATTERN = /(<a[^>]*) href="([^"]*)"/g;
2324

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+
];
42+
2443
task('docs', ['markdown-docs', 'highlight-docs', 'api-docs']);
2544

2645
task('markdown-docs', () => {
@@ -38,6 +57,15 @@ task('markdown-docs', () => {
3857
}
3958
}))
4059
.pipe(transform(transformMarkdownFiles))
60+
.pipe(dom(function () {
61+
MARKDOWN_TAGS_TO_CLASS_ALIAS.forEach((tag) => {
62+
Array.prototype.slice.call(this.querySelectorAll(tag)).forEach((el: any) => {
63+
el.classList.add(`docs-markdown-${tag}`);
64+
});
65+
});
66+
67+
return this;
68+
}))
4169
.pipe(dest('dist/docs/markdown'));
4270
});
4371

@@ -49,10 +77,10 @@ task('highlight-docs', () => {
4977
};
5078

5179
return src('src/examples/**/*.+(html|css|ts)')
52-
.pipe(flatten())
53-
.pipe(rename(renameFile))
54-
.pipe(highlight())
55-
.pipe(dest('dist/docs/examples'));
80+
.pipe(flatten())
81+
.pipe(rename(renameFile))
82+
.pipe(highlight())
83+
.pipe(dest('dist/docs/examples'));
5684
});
5785

5886
task('api-docs', () => {

0 commit comments

Comments
 (0)