Skip to content
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

gulp: Inline regex source #1537

Merged
merged 4 commits into from
Jan 23, 2019
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 components/prism-pug.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
'punctuation': /[.\-!=|]+/
};

var filter_pattern = '(^([\\t ]*)):{{filter_name}}(?:(?:\\r?\\n|\\r(?!\\n))(?:\\2[\\t ]+.+|\\s*?(?=\\r?\\n|\\r)))+';
var filter_pattern = /(^([\t ]*)):{{filter_name}}(?:(?:\r?\n|\r(?!\n))(?:\2[\t ]+.+|\s*?(?=\r?\n|\r)))+/.source;

// Non exhaustive list of available filters and associated languages
var filters = [
Expand Down
2 changes: 1 addition & 1 deletion components/prism-pug.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions components/prism-pure.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
'ats',
'dsp'
];
var inlineLanguageRe = '%< *-\\*- *{lang}\\d* *-\\*-[\\s\\S]+?%>';
var inlineLanguageRe = /%< *-\*- *{lang}\d* *-\*-[\s\S]+?%>/.source;

inlineLanguages.forEach(function (lang) {
var alias = lang;
Expand All @@ -78,4 +78,4 @@
Prism.languages.pure['inline-lang'].inside.rest = Prism.util.clone(Prism.languages.c);
}

}(Prism));
}(Prism));
4 changes: 2 additions & 2 deletions components/prism-textile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function(Prism) {
// We don't allow for pipes inside parentheses
// to not break table pattern |(. foo |). bar |
var modifierRegex = '(?:\\([^|)]+\\)|\\[[^\\]]+\\]|\\{[^}]+\\})+';
var modifierRegex = /(?:\([^|)]+\)|\[[^\]]+\]|\{[^}]+\})+/.source;
var modifierTokens = {
'css': {
pattern: /\{[^}]+\}/,
Expand Down Expand Up @@ -254,4 +254,4 @@
Prism.languages.textile['phrase'].inside['table'].inside['acronym'] = nestedPatterns['acronym'];
Prism.languages.textile['phrase'].inside['table'].inside['mark'] = nestedPatterns['mark'];

}(Prism));
}(Prism));
20 changes: 19 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,27 @@ var gulp = require('gulp'),
reject(err);
}
});
});
}),

inlineRegexSource = function () {
return replace(
/\/((?:[^\n\r[\\\/]|\\.|\[(?:[^\n\r\\\]]|\\.)*\])*)\/\.source\b/,
function (m, source) {
// escape backslashes
source = source.replace(/\\/g, '\\\\');
// escape single quotes
source = source.replace(/'/g, "\\'");
// unescape characters like \\n and \\t to \n and \t
source = source.replace(/(^|[^\\])\\\\([nrt0])/g, '$1\\$2');
// wrap source in single quotes
return "'" + source + "'";
}
);
};

gulp.task('components', function() {
return gulp.src(paths.components)
.pipe(inlineRegexSource())
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('components'));
Expand All @@ -54,6 +71,7 @@ gulp.task('build', function() {

gulp.task('plugins', ['languages-plugins'], function() {
return gulp.src(paths.plugins)
.pipe(inlineRegexSource())
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('plugins'));
Expand Down