Skip to content

Commit

Permalink
feat: support blade highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
yilanboy committed Jan 6, 2025
1 parent 84e10c9 commit 8119466
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions resources/ts/ckeditor/ckeditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ ClassicEditor.defaultConfig = {
languages: [
{ language: 'text', label: 'Plain text' }, // The default language.
{ language: 'bash', label: 'Bash' },
{ language: 'blade', label: 'Blade' },
{ language: 'c', label: 'C' },
{ language: 'cs', label: 'C#' },
{ language: 'cpp', label: 'C++' },
Expand Down
54 changes: 54 additions & 0 deletions resources/ts/highlight-blade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { HLJSApi } from 'highlight.js';

export default function (hljs: HLJSApi) {
return {
aliases: ['blade'],
case_insensitive: false,
subLanguage: 'xml',
contains: [
hljs.COMMENT(/\{\{--/, /--}}/),

// output with HTML escaping
{
scope: 'template-variable',
subLanguage: 'php',
begin: /\{\{/,
end: /}}/,
excludeEnd: false,
},

// output with no HTML escaping
{
scope: 'template-variable',
subLanguage: 'php',
begin: /\{!!/,
end: /!!}/,
excludeEnd: false,
},

// 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',
},
],
};
}
2 changes: 2 additions & 0 deletions resources/ts/highlight.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import hljs from 'highlight.js/lib/core';
import bash from 'highlight.js/lib/languages/bash';
import blade from './highlight-blade.js';
import c from 'highlight.js/lib/languages/c';
import cs from 'highlight.js/lib/languages/csharp';
import cpp from 'highlight.js/lib/languages/cpp';
Expand Down Expand Up @@ -33,6 +34,7 @@ declare global {
}

hljs.registerLanguage('bash', bash);
hljs.registerLanguage('blade', blade);
hljs.registerLanguage('c', c);
hljs.registerLanguage('cs', cs);
hljs.registerLanguage('cpp', cpp);
Expand Down

0 comments on commit 8119466

Please sign in to comment.