Skip to content

Commit f77b40b

Browse files
committed
Haml: Combine both multiline-comment regexps + handle \r\n and \r
1 parent aa757f6 commit f77b40b

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

components/prism-haml.js

+14-21
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,22 @@
1010
Prism.languages.haml = {
1111
// Multiline stuff should appear before the rest
1212

13-
'multiline-comment': [
14-
{
15-
pattern: /((?:^|\n)([\t ]*))\/.*(\n\2[\t ]+.+)*/,
16-
lookbehind: true,
17-
alias: 'comment'
18-
},
19-
{
20-
pattern: /((?:^|\n)([\t ]*))-#.*(\n\2[\t ]+.+)*/,
21-
lookbehind: true,
22-
alias: 'comment'
23-
}
24-
],
13+
'multiline-comment': {
14+
pattern: /((?:^|\r?\n|\r)([\t ]*))(?:\/|-#).*((?:\r?\n|\r)\2[\t ]+.+)*/,
15+
lookbehind: true,
16+
alias: 'comment'
17+
},
2518

2619
'multiline-code': [
2720
{
28-
pattern: /((?:^|\n)([\t ]*)(?:[~-]|[&!]?=)).*,[\t ]*(\n\2[\t ]+.*,[\t ]*)*(\n\2[\t ]+.+)/,
21+
pattern: /((?:^|\r?\n|\r)([\t ]*)(?:[~-]|[&!]?=)).*,[\t ]*((?:\r?\n|\r)\2[\t ]+.*,[\t ]*)*((?:\r?\n|\r)\2[\t ]+.+)/,
2922
lookbehind: true,
3023
inside: {
3124
rest: Prism.languages.ruby
3225
}
3326
},
3427
{
35-
pattern: /((?:^|\n)([\t ]*)(?:[~-]|[&!]?=)).*\|[\t ]*(\n\2[\t ]+.*\|[\t ]*)*/,
28+
pattern: /((?:^|\r?\n|\r)([\t ]*)(?:[~-]|[&!]?=)).*\|[\t ]*((?:\r?\n|\r)\2[\t ]+.*\|[\t ]*)*/,
3629
lookbehind: true,
3730
inside: {
3831
rest: Prism.languages.ruby
@@ -42,7 +35,7 @@
4235

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

5548
'markup': {
56-
pattern: /((?:^|\n)[\t ]*)<.+/,
49+
pattern: /((?:^|\r?\n|\r)[\t ]*)<.+/,
5750
lookbehind: true,
5851
inside: {
5952
rest: Prism.languages.markup
6053
}
6154
},
6255
'doctype': {
63-
pattern: /((?:^|\n)[\t ]*)!!!(?: .+)?/,
56+
pattern: /((?:^|\r?\n|\r)[\t ]*)!!!(?: .+)?/,
6457
lookbehind: true
6558
},
6659
'tag': {
6760
// Allows for one nested group of braces
68-
pattern: /((?:^|\n)[\t ]*)[%.#][\w\-#.]*[\w\-](?:\([^)]+\)|\{(?:\{[^}]+\}|[^}])+\}|\[[^\]]+\])*[\/<>]*/,
61+
pattern: /((?:^|\r?\n|\r)[\t ]*)[%.#][\w\-#.]*[\w\-](?:\([^)]+\)|\{(?:\{[^}]+\}|[^}])+\}|\[[^\]]+\])*[\/<>]*/,
6962
lookbehind: true,
7063
inside: {
7164
'attributes': [
@@ -100,7 +93,7 @@
10093
}
10194
},
10295
'code': {
103-
pattern: /((?:^|\n)[\t ]*(?:[~-]|[&!]?=)).+/,
96+
pattern: /((?:^|\r?\n|\r)[\t ]*(?:[~-]|[&!]?=)).+/,
10497
lookbehind: true,
10598
inside: {
10699
rest: Prism.languages.ruby
@@ -118,12 +111,12 @@
118111
}
119112
},
120113
'punctuation': {
121-
pattern: /((?:^|\n)[\t ]*)[~=\-&!]/,
114+
pattern: /((?:^|\r?\n|\r)[\t ]*)[~=\-&!]/,
122115
lookbehind: true
123116
}
124117
};
125118

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

128121
// Non exhaustive list of available filters and associated languages
129122
var filters = [

components/prism-haml.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)