From 41aa5885f86e9ff4cbd16353f3a130954a08f9a7 Mon Sep 17 00:00:00 2001 From: Allen Date: Thu, 9 Jan 2025 18:25:45 +0800 Subject: [PATCH] feat: update blade highlight --- resources/ts/highlight-blade.ts | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/resources/ts/highlight-blade.ts b/resources/ts/highlight-blade.ts index 117ec63f..ff587d21 100644 --- a/resources/ts/highlight-blade.ts +++ b/resources/ts/highlight-blade.ts @@ -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: /(?\{\{)/, beginScope: 'template-variable', - end: /}}/, + end: /(?}})/, endScope: 'template-variable', subLanguage: 'php', }; // {{ $unescaped ? '

true

' : '

false

' }} const UNESCAPED_TEMPLATE_VARIABLE = { - begin: /\{!!/, + begin: /(?\{!!)/, beginScope: 'template-variable', - end: /!!}/, + end: /(?!!})/, endScope: 'template-variable', subLanguage: 'php', }; @@ -23,26 +23,35 @@ export default function (hljs: HLJSApi): Language { // $foo = 'bar'; // @endphp const RAW_PHP = { - begin: /@php/, + begin: /(?@php)/, beginScope: 'keyword', - end: /@endphp/, + end: /(?@endphp)/, endScope: 'keyword', subLanguage: 'php', }; + // :blade-value="$phpVar" + const BLADE_COMPONENT_ATTRIBUTE = { + begin: /(?<=\s)(?:[\w-]+=")/, + excludeBegin: true, + end: /(?")/, + excludeEnd: true, + subLanguage: 'php', + }; + // @somethingLikeThis const BLADE_DIRECTIVES = { scope: 'keyword', - match: /@[a-zA-Z]+/, + 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?)(?\()/, excludeBegin: true, - end: /\)/, + end: /(?\))/, excludeEnd: true, subLanguage: 'php', }; @@ -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, ],