|
| 1 | +/** |
| 2 | + * Sources: |
| 3 | + * 1. https://github.com/PrismJS/prism/blob/master/components/prism-php.js |
| 4 | + * 2. https://github.com/Medalink/laravel-blade/blob/main/Syntaxes/Blade.sublime-syntax |
| 5 | + * 3. https://github.com/miken32/highlightjs-blade/blob/main/src/languages/blade.js |
| 6 | + */ |
| 7 | +import refractorMarkup from 'refractor/lang/markup.js'; |
| 8 | +import refractorPhp from 'refractor/lang/php.js'; |
| 9 | + |
| 10 | +blade.displayName = 'blade'; |
| 11 | + |
| 12 | +export default function blade(Prism) { |
| 13 | + Prism.register(refractorMarkup); |
| 14 | + Prism.register(refractorPhp); |
| 15 | + |
| 16 | + (function (Prism) { |
| 17 | + Prism.languages.blade = { |
| 18 | + comment: /{{--([\s\S]*?)--}}/, |
| 19 | + |
| 20 | + directive: { |
| 21 | + pattern: /@\w+(?:::\w+)?(?:\s*\([\s\S]*?\))?/, |
| 22 | + inside: { |
| 23 | + keyword: /@\w+/, |
| 24 | + function: /[:]\w+/, |
| 25 | + punctuation: /[():]/, |
| 26 | + }, |
| 27 | + }, |
| 28 | + |
| 29 | + echo: { |
| 30 | + pattern: /\{{2,3}[\s\S]*?\}{2,3}/, |
| 31 | + inside: { |
| 32 | + delimiter: /^\{{2,3}|\}{2,3}$/, |
| 33 | + php: { |
| 34 | + pattern: /[\s\S]+/, |
| 35 | + inside: Prism.languages.php, |
| 36 | + }, |
| 37 | + }, |
| 38 | + }, |
| 39 | + |
| 40 | + php: { |
| 41 | + pattern: /(?:\@php[\s\S]*?\@endphp|\<\?php[\s\S]*?\?\>)/, |
| 42 | + inside: { |
| 43 | + delimiter: { |
| 44 | + pattern: /^\@php|\@endphp|\<\?php|\?\>$/, |
| 45 | + alias: 'important', |
| 46 | + }, |
| 47 | + php: { |
| 48 | + pattern: /[\s\S]+/, |
| 49 | + inside: Prism.languages.php, |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + |
| 54 | + markup: { |
| 55 | + pattern: /<[^?]\/?(.*?)>/, |
| 56 | + inside: Prism.languages.markup, |
| 57 | + }, |
| 58 | + |
| 59 | + keyword: |
| 60 | + /\b(?:@if|@else|@elseif|@endif|@foreach|@endforeach|@for|@endfor|@while|@endwhile|@unless|@endunless|@isset|@endisset|@empty|@endempty|@switch|@case|@break|@default|@endswitch|@include|@extends|@section|@endsection|@yield|@stack|@push|@endpush|@auth|@guest|@endauth|@endguest)\b/, |
| 61 | + |
| 62 | + variable: /\$\w+/, |
| 63 | + |
| 64 | + operator: /=>|->|\|\||&&|!=|==|<=|>=|[+\-*\/%<>]=?|\?:/, |
| 65 | + |
| 66 | + punctuation: /[\[\](){}:;,]/, |
| 67 | + }; |
| 68 | + })(Prism); |
| 69 | +} |
0 commit comments