Skip to content

Commit 8b64c78

Browse files
committed
chore(tools): add syntax highlighting logic for examples
1 parent 4b830d3 commit 8b64c78

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,13 @@
6666
"gulp-clean-css": "^2.3.2",
6767
"gulp-cli": "^1.2.2",
6868
"gulp-connect": "^5.0.0",
69+
"gulp-filter": "^5.0.0",
70+
"gulp-flatten": "^0.3.1",
71+
"gulp-highlight-files": "0.0.4",
6972
"gulp-htmlmin": "^3.0.0",
7073
"gulp-if": "^2.0.2",
7174
"gulp-markdown": "^1.2.0",
75+
"gulp-rename": "^1.2.2",
7276
"gulp-sass": "^3.1.0",
7377
"gulp-sourcemaps": "^2.4.0",
7478
"gulp-transform": "^1.1.0",

tools/gulp/tasks/docs.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import gulp = require('gulp');
22
const markdown = require('gulp-markdown');
33
const transform = require('gulp-transform');
4+
const filter = require('gulp-filter');
5+
const highlight = require('gulp-highlight-files');
6+
const rename = require('gulp-rename');
7+
const flatten = require('gulp-flatten');
48
const hljs = require('highlight.js');
9+
const exec = require('child_process').exec;
510
import {task} from 'gulp';
611
import * as path from 'path';
712

@@ -16,7 +21,7 @@ const EXAMPLE_PATTERN = /<!--\W*example\(([^)]+)\)\W*-->/g;
1621
// documentation page. Using a RegExp to rewrite links in HTML files to work in the docs.
1722
const LINK_PATTERN = /(<a[^>]*) href="([^"]*)"/g;
1823

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

2126
gulp.task('markdown-docs', () => {
2227
return gulp.src(['src/lib/**/*.md', 'guides/*.md'])
@@ -36,6 +41,40 @@ gulp.task('markdown-docs', () => {
3641
.pipe(gulp.dest('dist/docs/markdown'));
3742
});
3843

44+
gulp.task('highlight-docs', () => {
45+
const cssFilter = filter('**/*.css', {restore: true});
46+
const tsFilter = filter('**/*.ts', {restore: true});
47+
const htmlFilter = filter('**/*.html', {restore: true});
48+
49+
// rename files to fit format: [filename]-[filetype].html
50+
const renameFile = (path: any) => {
51+
const extension = path.extname.slice(1);
52+
path.basename = `${path.basename}-${extension}`;
53+
};
54+
55+
gulp.src(['src/examples/**/*.{css,ts,html}', '!src/examples/*.*'])
56+
// Flatten structure so that examples folder has no nested dirs
57+
.pipe(flatten())
58+
59+
.pipe(htmlFilter)
60+
.pipe(rename(renameFile))
61+
.pipe(highlight({language: 'html'}))
62+
.pipe(gulp.dest('dist/docs/examples'))
63+
.pipe(htmlFilter.restore)
64+
65+
.pipe(cssFilter)
66+
.pipe(rename(renameFile))
67+
.pipe(highlight({language: 'css'}))
68+
.pipe(gulp.dest('dist/docs/examples'))
69+
.pipe(cssFilter.restore)
70+
71+
.pipe(tsFilter)
72+
.pipe(rename(renameFile))
73+
.pipe(highlight({language: 'ts'}))
74+
.pipe(gulp.dest('dist/docs/examples'))
75+
.pipe(tsFilter.restore);
76+
});
77+
3978
task('api-docs', () => {
4079
const Dgeni = require('dgeni');
4180
const docsPackage = require(path.resolve(__dirname, '../../dgeni'));

0 commit comments

Comments
 (0)