Skip to content

Commit cd8f792

Browse files
committed
add blade support
1 parent 1afeb27 commit cd8f792

File tree

3 files changed

+171
-1
lines changed

3 files changed

+171
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mintlify/mdx",
3-
"version": "0.0.49",
3+
"version": "0.0.54",
44
"description": "Markdown parser from Mintlify",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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+
blade.aliases = ['blade_php'];
12+
13+
export default function blade(Prism) {
14+
Prism.register(refractorMarkup);
15+
Prism.register(refractorPhp);
16+
17+
// (function (Prism) {
18+
// Prism.languages.blade = Prism.languages.extend('markup', {});
19+
20+
// Object.assign(Prism.languages.blade, {
21+
// comment: {
22+
// pattern: /{{--.+?--}}/s,
23+
// },
24+
25+
// 'template-variable': {
26+
// pattern: /{{[\s\S]*?}}/,
27+
// inside: {
28+
// delimiter: {
29+
// pattern: /^{{|}}$/,
30+
// alias: 'punctuation',
31+
// },
32+
// rest: {
33+
// pattern: /[\s\S]+/,
34+
// alias: 'php',
35+
// inside: Prism.languages.php,
36+
// },
37+
// },
38+
// },
39+
40+
// 'template-variable-raw': {
41+
// pattern: /{!![\s\S]*?!!}/,
42+
// inside: {
43+
// delimiter: {
44+
// pattern: /^{!!|!!}$/,
45+
// alias: 'punctuation',
46+
// },
47+
// rest: {
48+
// pattern: /[\s\S]+/,
49+
// alias: 'php',
50+
// inside: Prism.languages.php,
51+
// },
52+
// },
53+
// },
54+
// 'template-tag': [
55+
// {
56+
// pattern: /@(?:php|endphp)/,
57+
// alias: 'keyword',
58+
// },
59+
// {
60+
// pattern: /@[\w]+/,
61+
// alias: 'keyword',
62+
// },
63+
// ],
64+
65+
// 'php-block': {
66+
// pattern: /(@php\s*)([\s\S]*?)(@endphp)/,
67+
// lookbehind: true,
68+
// inside: {
69+
// rest: {
70+
// pattern: /[\s\S]+/,
71+
// alias: 'php',
72+
// inside: Prism.languages.php,
73+
// },
74+
// },
75+
// },
76+
// });
77+
78+
// Object.assign(Prism.languages.blade['template-variable'].inside.rest.inside, {
79+
// 'template-variable': Prism.languages.blade['template-variable'],
80+
// 'template-variable-raw': Prism.languages.blade['template-variable-raw'],
81+
// });
82+
83+
// Prism.languages.blade['directive-params'] = {
84+
// pattern: /(@[\w]+)(?:\(((?:[^()"]|"[^"]*")*)\))?/,
85+
// inside: {
86+
// directive: {
87+
// pattern: /@[\w]+/,
88+
// alias: 'keyword',
89+
// },
90+
// punctuation: /[()]/,
91+
// params: {
92+
// pattern: /[\s\S]+/,
93+
// alias: 'php',
94+
// inside: Prism.languages.php,
95+
// },
96+
// },
97+
// };
98+
99+
// Prism.languages['blade-php'] = Prism.languages.blade;
100+
// })(Prism);
101+
102+
(function (Prism) {
103+
Prism.languages.blade = {
104+
comment: /{{--([\s\S]*?)--}}/,
105+
106+
// Blade directives
107+
directive: {
108+
pattern: /@\w+(?:::\w+)?(?:\s*\([\s\S]*?\))?/,
109+
inside: {
110+
keyword: /@\w+/,
111+
function: /[:]\w+/,
112+
punctuation: /[():]/,
113+
},
114+
},
115+
116+
// Echo statements
117+
echo: {
118+
pattern: /\{{2,3}[\s\S]*?\}{2,3}/,
119+
inside: {
120+
delimiter: /^\{{2,3}|\}{2,3}$/,
121+
php: {
122+
pattern: /[\s\S]+/,
123+
inside: Prism.languages.php,
124+
},
125+
},
126+
},
127+
128+
// Raw PHP
129+
php: {
130+
pattern: /(?:\@php[\s\S]*?\@endphp|\<\?php[\s\S]*?\?\>)/,
131+
inside: {
132+
delimiter: {
133+
pattern: /^\@php|\@endphp|\<\?php|\?\>$/,
134+
alias: 'important',
135+
},
136+
php: {
137+
pattern: /[\s\S]+/,
138+
inside: Prism.languages.php,
139+
},
140+
},
141+
},
142+
143+
// HTML markup
144+
markup: {
145+
pattern: /<[^?]\/?(.*?)>/,
146+
inside: Prism.languages.markup,
147+
},
148+
149+
// Keywords for common Blade directives
150+
keyword:
151+
/\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/,
152+
153+
// Blade variables
154+
variable: /\$\w+/,
155+
156+
// Operators
157+
operator: /=>|->|\|\||&&|!=|==|<=|>=|[+\-*\/%<>]=?|\?:/,
158+
159+
// Punctuation
160+
punctuation: /[\[\](){}:;,]/,
161+
};
162+
163+
// Add alias for Blade files
164+
Prism.languages.blade_php = Prism.languages.blade;
165+
})(Prism);
166+
}

src/plugins/rehype/rehypeSyntaxHighlighting.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import type { Node } from 'unist';
66
import { Parent } from 'unist';
77
import { visit } from 'unist-util-visit';
88

9+
import blade from '../../lib/syntaxHighlighting/blade.js';
10+
11+
refractor.register(blade);
12+
913
export type RehypeSyntaxHighlightingOptions = {
1014
ignoreMissing?: boolean;
1115
alias?: Record<string, string[]>;

0 commit comments

Comments
 (0)