-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,63 @@ | ||
import { HLJSApi } from 'highlight.js'; | ||
import type { HLJSApi, Language } from 'highlight.js'; | ||
|
||
export default function (hljs: HLJSApi): Language { | ||
// {{ $escaped ? 'true' : 'false' }} | ||
const ESCAPED_TEMPLATE_VARIABLE = { | ||
begin: /\{\{/, | ||
beginScope: 'template-variable', | ||
end: /}}/, | ||
endScope: 'template-variable', | ||
subLanguage: 'php', | ||
}; | ||
|
||
// {{ $unescaped ? '<p>true</p>' : '<p>false</p>' }} | ||
const UNESCAPED_TEMPLATE_VARIABLE = { | ||
begin: /\{!!/, | ||
beginScope: 'template-variable', | ||
end: /!!}/, | ||
endScope: 'template-variable', | ||
subLanguage: 'php', | ||
}; | ||
|
||
// @php | ||
// $foo = 'bar'; | ||
// @endphp | ||
const RAW_PHP = { | ||
begin: /@php/, | ||
beginScope: 'keyword', | ||
end: /@endphp/, | ||
endScope: 'keyword', | ||
subLanguage: 'php', | ||
}; | ||
|
||
// @somethingLikeThis | ||
const BLADE_DIRECTIVES = { | ||
scope: 'keyword', | ||
match: /@[a-zA-Z]+/, | ||
}; | ||
|
||
// @foreach ($list as $item) | ||
// or | ||
// @foreach($list as $item) | ||
const STATEMENT_AFTER_BLADE_DIRECTIVES = { | ||
begin: /(?<=@[a-zA-Z]+\s?)\(/, | ||
excludeBegin: true, | ||
end: /\)/, | ||
excludeEnd: true, | ||
subLanguage: 'php', | ||
}; | ||
|
||
export default function (hljs: HLJSApi) { | ||
return { | ||
aliases: ['blade'], | ||
case_insensitive: false, | ||
subLanguage: 'xml', | ||
contains: [ | ||
hljs.COMMENT(/\{\{--/, /--}}/), | ||
|
||
// output with HTML escaping | ||
{ | ||
begin: /\{\{/, | ||
beginScope: 'template-tag', | ||
end: /}}/, | ||
endScope: 'template-tag', | ||
subLanguage: 'php', | ||
}, | ||
|
||
// output with no HTML escaping | ||
{ | ||
begin: /\{!!/, | ||
beginScope: 'template-tag', | ||
end: /!!}/, | ||
endScope: 'template-tag', | ||
subLanguage: 'php', | ||
}, | ||
|
||
// directly inserted PHP code | ||
{ | ||
begin: /@php/, | ||
beginScope: 'keyword', | ||
end: /@endphp/, | ||
endScope: 'keyword', | ||
subLanguage: 'php', | ||
}, | ||
|
||
// blade syntax | ||
{ | ||
scope: 'keyword', | ||
match: /@[a-zA-Z]+/, | ||
}, | ||
|
||
// parameter in blade syntax | ||
{ | ||
begin: /(?<=@[a-zA-Z]+\s?)\(/, | ||
excludeBegin: true, | ||
end: /\)/, | ||
excludeEnd: true, | ||
subLanguage: 'php', | ||
}, | ||
ESCAPED_TEMPLATE_VARIABLE, | ||
UNESCAPED_TEMPLATE_VARIABLE, | ||
RAW_PHP, | ||
BLADE_DIRECTIVES, | ||
STATEMENT_AFTER_BLADE_DIRECTIVES, | ||
], | ||
}; | ||
} |