Skip to content

Commit

Permalink
feat: update blade highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
yilanboy committed Jan 9, 2025
1 parent 918594e commit 41aa588
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions resources/ts/highlight-blade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import type { HLJSApi, Language } from 'highlight.js';
export default function (hljs: HLJSApi): Language {
// {{ $escaped ? 'true' : 'false' }}
const ESCAPED_TEMPLATE_VARIABLE = {
begin: /\{\{/,
begin: /(?<begin>\{\{)/,
beginScope: 'template-variable',
end: /}}/,
end: /(?<end>}})/,
endScope: 'template-variable',
subLanguage: 'php',
};

// {{ $unescaped ? '<p>true</p>' : '<p>false</p>' }}
const UNESCAPED_TEMPLATE_VARIABLE = {
begin: /\{!!/,
begin: /(?<begin>\{!!)/,
beginScope: 'template-variable',
end: /!!}/,
end: /(?<end>!!})/,
endScope: 'template-variable',
subLanguage: 'php',
};
Expand All @@ -23,26 +23,35 @@ export default function (hljs: HLJSApi): Language {
// $foo = 'bar';
// @endphp
const RAW_PHP = {
begin: /@php/,
begin: /(?<begin>@php)/,
beginScope: 'keyword',
end: /@endphp/,
end: /(?<end>@endphp)/,
endScope: 'keyword',
subLanguage: 'php',
};

// :blade-value="$phpVar"
const BLADE_COMPONENT_ATTRIBUTE = {
begin: /(?<=\s)(?<begin>:[\w-]+=")/,
excludeBegin: true,
end: /(?<end>")/,
excludeEnd: true,
subLanguage: 'php',
};

// @somethingLikeThis
const BLADE_DIRECTIVES = {
scope: 'keyword',
match: /@[a-zA-Z]+/,
match: /(?<match>@[a-zA-Z]+)/,
};

// @foreach ($list as $item)
// or
// @foreach($list as $item)
const STATEMENT_AFTER_BLADE_DIRECTIVES = {
begin: /(?<=@[a-zA-Z]+\s?)\(/,
begin: /(?<=@[a-zA-Z]+\s?)(?<begin>\()/,
excludeBegin: true,
end: /\)/,
end: /(?<end>\))/,
excludeEnd: true,
subLanguage: 'php',
};
Expand All @@ -56,6 +65,7 @@ export default function (hljs: HLJSApi): Language {
ESCAPED_TEMPLATE_VARIABLE,
UNESCAPED_TEMPLATE_VARIABLE,
RAW_PHP,
BLADE_COMPONENT_ATTRIBUTE,
BLADE_DIRECTIVES,
STATEMENT_AFTER_BLADE_DIRECTIVES,
],
Expand Down

0 comments on commit 41aa588

Please sign in to comment.