Skip to content

Commit f73fd7d

Browse files
riavalontinayuangao
authored andcommitted
chore(tools): add syntax highlighting logic for examples (#2951)
1 parent 478a2e4 commit f73fd7d

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333
/libpeerconnection.log
3434
npm-debug.log
3535
testem.log
36-
/.chrome
36+
/.chrome

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,12 @@
6666
"gulp-clean-css": "^2.3.2",
6767
"gulp-cli": "^1.2.2",
6868
"gulp-connect": "^5.0.0",
69+
"gulp-flatten": "^0.3.1",
70+
"gulp-highlight-files": "0.0.4",
6971
"gulp-htmlmin": "^3.0.0",
7072
"gulp-if": "^2.0.2",
7173
"gulp-markdown": "^1.2.0",
74+
"gulp-rename": "^1.2.2",
7275
"gulp-sass": "^3.1.0",
7376
"gulp-sourcemaps": "^2.4.0",
7477
"gulp-transform": "^1.1.0",

tools/gulp/tasks/docs.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import gulp = require('gulp');
22
const markdown = require('gulp-markdown');
33
const transform = require('gulp-transform');
4+
const highlight = require('gulp-highlight-files');
5+
const rename = require('gulp-rename');
6+
const flatten = require('gulp-flatten');
47
const hljs = require('highlight.js');
58
import {task} from 'gulp';
69
import * as path from 'path';
@@ -16,7 +19,7 @@ const EXAMPLE_PATTERN = /<!--\W*example\(([^)]+)\)\W*-->/g;
1619
// documentation page. Using a RegExp to rewrite links in HTML files to work in the docs.
1720
const LINK_PATTERN = /(<a[^>]*) href="([^"]*)"/g;
1821

19-
gulp.task('docs', ['markdown-docs', 'api-docs'])
22+
gulp.task('docs', ['markdown-docs', 'highlight-docs', 'api-docs'])
2023

2124
gulp.task('markdown-docs', () => {
2225
return gulp.src(['src/lib/**/*.md', 'guides/*.md'])
@@ -36,6 +39,20 @@ gulp.task('markdown-docs', () => {
3639
.pipe(gulp.dest('dist/docs/markdown'));
3740
});
3841

42+
gulp.task('highlight-docs', () => {
43+
// rename files to fit format: [filename]-[filetype].html
44+
const renameFile = (path: any) => {
45+
const extension = path.extname.slice(1);
46+
path.basename = `${path.basename}-${extension}`;
47+
};
48+
49+
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'));
54+
});
55+
3956
task('api-docs', () => {
4057
const Dgeni = require('dgeni');
4158
const docsPackage = require(path.resolve(__dirname, '../../dgeni'));

0 commit comments

Comments
 (0)