Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mintlify/mdx",
"version": "0.0.49",
"version": "0.0.54",
"description": "Markdown parser from Mintlify",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
69 changes: 69 additions & 0 deletions src/lib/syntaxHighlighting/blade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Sources:
* 1. https://github.com/PrismJS/prism/blob/master/components/prism-php.js
* 2. https://github.com/Medalink/laravel-blade/blob/main/Syntaxes/Blade.sublime-syntax
* 3. https://github.com/miken32/highlightjs-blade/blob/main/src/languages/blade.js
*/
import refractorMarkup from 'refractor/lang/markup.js';
import refractorPhp from 'refractor/lang/php.js';

blade.displayName = 'blade';

export default function blade(Prism) {
Prism.register(refractorMarkup);
Prism.register(refractorPhp);

(function (Prism) {
Prism.languages.blade = {
comment: /{{--([\s\S]*?)--}}/,

directive: {
pattern: /@\w+(?:::\w+)?(?:\s*\([\s\S]*?\))?/,
inside: {
keyword: /@\w+/,
function: /[:]\w+/,
punctuation: /[():]/,
},
},

echo: {
pattern: /\{{2,3}[\s\S]*?\}{2,3}/,
inside: {
delimiter: /^\{{2,3}|\}{2,3}$/,
php: {
pattern: /[\s\S]+/,
inside: Prism.languages.php,
},
},
},

php: {
pattern: /(?:\@php[\s\S]*?\@endphp|\<\?php[\s\S]*?\?\>)/,
inside: {
delimiter: {
pattern: /^\@php|\@endphp|\<\?php|\?\>$/,
alias: 'important',
},
php: {
pattern: /[\s\S]+/,
inside: Prism.languages.php,
},
},
},

markup: {
pattern: /<[^?]\/?(.*?)>/,
inside: Prism.languages.markup,
},

keyword:
/\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/,

variable: /\$\w+/,

operator: /=>|->|\|\||&&|!=|==|<=|>=|[+\-*\/%<>]=?|\?:/,

punctuation: /[\[\](){}:;,]/,
};
})(Prism);
}
4 changes: 4 additions & 0 deletions src/plugins/rehype/rehypeSyntaxHighlighting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import type { Node } from 'unist';
import { Parent } from 'unist';
import { visit } from 'unist-util-visit';

import blade from '../../lib/syntaxHighlighting/blade.js';

refractor.register(blade);

export type RehypeSyntaxHighlightingOptions = {
ignoreMissing?: boolean;
alias?: Record<string, string[]>;
Expand Down