Skip to content

chore(tools): add syntax highlighting logic for examples #2951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
/libpeerconnection.log
npm-debug.log
testem.log
/.chrome
/.chrome
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@
"gulp-clean-css": "^2.3.2",
"gulp-cli": "^1.2.2",
"gulp-connect": "^5.0.0",
"gulp-flatten": "^0.3.1",
"gulp-highlight-files": "0.0.4",
"gulp-htmlmin": "^3.0.0",
"gulp-if": "^2.0.2",
"gulp-markdown": "^1.2.0",
"gulp-rename": "^1.2.2",
"gulp-sass": "^3.1.0",
"gulp-sourcemaps": "^2.4.0",
"gulp-transform": "^1.1.0",
Expand Down
19 changes: 18 additions & 1 deletion tools/gulp/tasks/docs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import gulp = require('gulp');
const markdown = require('gulp-markdown');
const transform = require('gulp-transform');
const highlight = require('gulp-highlight-files');
const rename = require('gulp-rename');
const flatten = require('gulp-flatten');
const hljs = require('highlight.js');
import {task} from 'gulp';
import * as path from 'path';
Expand All @@ -16,7 +19,7 @@ const EXAMPLE_PATTERN = /<!--\W*example\(([^)]+)\)\W*-->/g;
// documentation page. Using a RegExp to rewrite links in HTML files to work in the docs.
const LINK_PATTERN = /(<a[^>]*) href="([^"]*)"/g;

gulp.task('docs', ['markdown-docs', 'api-docs'])
gulp.task('docs', ['markdown-docs', 'highlight-docs', 'api-docs'])

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

gulp.task('highlight-docs', () => {
// rename files to fit format: [filename]-[filetype].html
const renameFile = (path: any) => {
const extension = path.extname.slice(1);
path.basename = `${path.basename}-${extension}`;
};

return gulp.src('src/examples/**/*.+(html|css|ts)')
.pipe(flatten())
.pipe(rename(renameFile))
.pipe(highlight())
.pipe(gulp.dest('dist/docs/examples'));
});

task('api-docs', () => {
const Dgeni = require('dgeni');
const docsPackage = require(path.resolve(__dirname, '../../dgeni'));
Expand Down