Skip to content

Commit

Permalink
Jade: Add todo list + remove single-line comment pattern + simplified…
Browse files Browse the repository at this point in the history
… most patterns with m flag + handle \r\n and \r
  • Loading branch information
Golmote committed Aug 24, 2015
1 parent cae2cef commit a79e838
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
64 changes: 33 additions & 31 deletions components/prism-jade.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
(function(Prism) {
// TODO:
// - Add CSS highlighting inside <style> tags
// - Add support for multi-line code blocks
// - Add support for interpolation #{} and !{}
// - Add support for tag interpolation #[]
// - Add explicit support for plain text using |
// - Add support for markup embedded in plain text

Prism.languages.jade = {

// Multiline stuff should appear before the rest

'multiline-comment': {
pattern: /((?:^|\n)([\t ]*))\/\/.*(\n\2[\t ]+.+)*/,
lookbehind: true,
alias: 'comment'
// This handles both single-line and multi-line comments
'comment': {
pattern: /(^([\t ]*))\/\/.*((?:\r?\n|\r)\2[\t ]+.+)*/m,
lookbehind: true
},

// All the tag-related part is in lookbehind
// so that it can be highlighted by the "tag" pattern
'multiline-script': {
pattern: /((?:^|\n)([\t ]*)script\b.*\.[\t ]*)(\n(?:\2[\t ]+.+|\s*?(?=\n)))+/,
pattern: /(^([\t ]*)script\b.*\.[\t ]*)((?:\r?\n|\r(?!\n))(?:\2[\t ]+.+|\s*?(?=\r?\n|\r)))+/m,
lookbehind: true,
inside: {
rest: Prism.languages.javascript
Expand All @@ -21,7 +29,7 @@

// See at the end of the file for known filters
'filter': {
pattern: /((?:^|\n)([\t ]*)):.+(\n(?:\2[\t ]+.+|\s*?(?=\n)))+/,
pattern: /(^([\t ]*)):.+((?:\r?\n|\r(?!\n))(?:\2[\t ]+.+|\s*?(?=\r?\n|\r)))+/m,
lookbehind: true,
inside: {
'filter-name': {
Expand All @@ -32,54 +40,48 @@
},

'multiline-plain-text': {
pattern: /((?:^|\n)([\t ]*)[\w\-#.]+\.[\t ]*)(\n(?:\2[\t ]+.+|\s*?(?=\n)))+/,
pattern: /(^([\t ]*)[\w\-#.]+\.[\t ]*)((?:\r?\n|\r(?!\n))(?:\2[\t ]+.+|\s*?(?=\r?\n|\r)))+/m,
lookbehind: true
},
'markup': {
pattern: /((?:^|\n)[\t ]*)<.+/,
pattern: /(^[\t ]*)<.+/m,
lookbehind: true,
inside: {
rest: Prism.languages.markup
}
},
'comment': {
pattern: /((?:^|\n)[\t ]*)\/\/.+/,
lookbehind: true
},
'doctype': {
pattern: /((?:^|\n)[\t ]*)doctype(?: .+)?/,
lookbehind: true
},

// This handle all conditional and loop keywords
'flow-control': {
pattern: /((?:^|\n)[\t ]*)(?:if|unless|else|case|when|default|each|while)(?: .+)?/,
pattern: /(^[\t ]*)(?:if|unless|else|case|when|default|each|while)\b(?: .+)?/m,
lookbehind: true,
inside: {
'each': {
pattern: /((?:^|\n)[\t ]*)each .+? in\b/,
lookbehind: true,
pattern: /^each .+? in\b/,
inside: {
'keyword': /\b(?:each|in)\b/,
'punctuation': /,/
}
},
'branch': {
pattern: /((?:^|\n)[\t ]*)(?:if|unless|else|case|when|default|while)/,
lookbehind: true,
pattern: /^(?:if|unless|else|case|when|default|while)\b/,
alias: 'keyword'
},
rest: Prism.languages.javascript
}
},
'keyword': {
pattern: /((?:^|\n)[\t ]*)(?:block|extends|include|append|prepend)\b.+/,
pattern: /(^[\t ]*)(?:block|extends|include|append|prepend)\b.+/m,
lookbehind: true
},
'mixin': [
// Declaration
{
pattern: /((?:^|\n)[\t ]*)mixin .+/,
pattern: /(^[\t ]*)mixin .+/m,
lookbehind: true,
inside: {
'keyword': /^mixin/,
Expand All @@ -89,7 +91,7 @@
},
// Usage
{
pattern: /((?:^|\n)[\t ]*)\+.+/,
pattern: /(^[\t ]*)\+.+/m,
lookbehind: true,
inside: {
'name': {
Expand All @@ -101,19 +103,19 @@
}
],
'script': {
pattern: /((?:^|\n)[\t ]*script(?:(?:&[^(]+)?\([^)]+\))*) .+/,
pattern: /(^[\t ]*script(?:(?:&[^(]+)?\([^)]+\))*[\t ]+).+/m,
lookbehind: true,
inside: {
rest: Prism.languages.javascript
}
},

'plain-text': {
pattern: /((?:^|\n)[\t ]*(?!-)[\w\-#.]*[\w\-](?:(?:&[^(]+)?\([^)]+\))*\/?[\t ]+).+/,
lookbehind: true
pattern: /(^[\t ]*(?!-)[\w\-#.]*[\w\-](?:(?:&[^(]+)?\([^)]+\))*\/?[\t ]+).+/m,
lookbehind: true
},
'tag': {
pattern: /((?:^|\n)[\t ]*)(?!-)[\w\-#.]*[\w\-](?:(?:&[^(]+)?\([^)]+\))*\/?:?/,
pattern: /(^[\t ]*)(?!-)[\w\-#.]*[\w\-](?:(?:&[^(]+)?\([^)]+\))*\/?:?/m,
lookbehind: true,
inside: {
'attributes': [
Expand All @@ -127,33 +129,33 @@
pattern: /\([^)]+\)/,
inside: {
'attr-value': {
pattern: /(=\s*)(?:\{[^}]*\}|[^,)\n]+)/,
pattern: /(=\s*)(?:\{[^}]*\}|[^,)\r\n]+)/,
lookbehind: true,
inside: {
rest: Prism.languages.javascript
}
},
'attr-name': /[\w-]+(?=\s*!?=|\s*[,)])/,
'punctuation': /[!=(),]/
'punctuation': /[!=(),]+/
}
}
],
'punctuation': /[:]/
'punctuation': /:/
}
},
'code': [
{
pattern: /((?:^|\n)[\t ]*(?:-|!?=)).+/,
pattern: /(^[\t ]*(?:-|!?=)).+/m,
lookbehind: true,
inside: {
rest: Prism.languages.javascript
}
}
],
'punctuation': /[.\-!=|]/
'punctuation': /[.\-!=|]+/
};

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

// Non exhaustive list of available filters and associated languages
var filters = [
Expand All @@ -178,7 +180,7 @@
filter = typeof filter === 'string' ? {filter: filter, language: filter} : filter;
if (Prism.languages[filter.language]) {
all_filters['filter-' + filter.filter] = {
pattern: RegExp(filter_pattern.replace('{{filter_name}}', filter.filter)),
pattern: RegExp(filter_pattern.replace('{{filter_name}}', filter.filter), 'm'),
lookbehind: true,
inside: {
'filter-name': {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-jade.min.js

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

0 comments on commit a79e838

Please sign in to comment.