Skip to content

Commit

Permalink
Haml: Combine both multiline-comment regexps + handle \r\n and \r
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Aug 22, 2015
1 parent aa757f6 commit f77b40b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
35 changes: 14 additions & 21 deletions components/prism-haml.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,22 @@
Prism.languages.haml = {
// Multiline stuff should appear before the rest

'multiline-comment': [
{
pattern: /((?:^|\n)([\t ]*))\/.*(\n\2[\t ]+.+)*/,
lookbehind: true,
alias: 'comment'
},
{
pattern: /((?:^|\n)([\t ]*))-#.*(\n\2[\t ]+.+)*/,
lookbehind: true,
alias: 'comment'
}
],
'multiline-comment': {
pattern: /((?:^|\r?\n|\r)([\t ]*))(?:\/|-#).*((?:\r?\n|\r)\2[\t ]+.+)*/,
lookbehind: true,
alias: 'comment'
},

'multiline-code': [
{
pattern: /((?:^|\n)([\t ]*)(?:[~-]|[&!]?=)).*,[\t ]*(\n\2[\t ]+.*,[\t ]*)*(\n\2[\t ]+.+)/,
pattern: /((?:^|\r?\n|\r)([\t ]*)(?:[~-]|[&!]?=)).*,[\t ]*((?:\r?\n|\r)\2[\t ]+.*,[\t ]*)*((?:\r?\n|\r)\2[\t ]+.+)/,
lookbehind: true,
inside: {
rest: Prism.languages.ruby
}
},
{
pattern: /((?:^|\n)([\t ]*)(?:[~-]|[&!]?=)).*\|[\t ]*(\n\2[\t ]+.*\|[\t ]*)*/,
pattern: /((?:^|\r?\n|\r)([\t ]*)(?:[~-]|[&!]?=)).*\|[\t ]*((?:\r?\n|\r)\2[\t ]+.*\|[\t ]*)*/,
lookbehind: true,
inside: {
rest: Prism.languages.ruby
Expand All @@ -42,7 +35,7 @@

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

'markup': {
pattern: /((?:^|\n)[\t ]*)<.+/,
pattern: /((?:^|\r?\n|\r)[\t ]*)<.+/,
lookbehind: true,
inside: {
rest: Prism.languages.markup
}
},
'doctype': {
pattern: /((?:^|\n)[\t ]*)!!!(?: .+)?/,
pattern: /((?:^|\r?\n|\r)[\t ]*)!!!(?: .+)?/,
lookbehind: true
},
'tag': {
// Allows for one nested group of braces
pattern: /((?:^|\n)[\t ]*)[%.#][\w\-#.]*[\w\-](?:\([^)]+\)|\{(?:\{[^}]+\}|[^}])+\}|\[[^\]]+\])*[\/<>]*/,
pattern: /((?:^|\r?\n|\r)[\t ]*)[%.#][\w\-#.]*[\w\-](?:\([^)]+\)|\{(?:\{[^}]+\}|[^}])+\}|\[[^\]]+\])*[\/<>]*/,
lookbehind: true,
inside: {
'attributes': [
Expand Down Expand Up @@ -100,7 +93,7 @@
}
},
'code': {
pattern: /((?:^|\n)[\t ]*(?:[~-]|[&!]?=)).+/,
pattern: /((?:^|\r?\n|\r)[\t ]*(?:[~-]|[&!]?=)).+/,
lookbehind: true,
inside: {
rest: Prism.languages.ruby
Expand All @@ -118,12 +111,12 @@
}
},
'punctuation': {
pattern: /((?:^|\n)[\t ]*)[~=\-&!]/,
pattern: /((?:^|\r?\n|\r)[\t ]*)[~=\-&!]/,
lookbehind: true
}
};

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

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

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

0 comments on commit f77b40b

Please sign in to comment.