Skip to content

Commit 4eb7618

Browse files
authored
Merge pull request #9 from mintlify/sam/support-blade-syntax-highlighting
Support Blade (Laravel)
2 parents 1afeb27 + a385049 commit 4eb7618

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-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: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
}

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)