diff --git a/package.json b/package.json index 46a2f57..e4587ce 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/lib/syntaxHighlighting/blade.js b/src/lib/syntaxHighlighting/blade.js new file mode 100644 index 0000000..40fa4bd --- /dev/null +++ b/src/lib/syntaxHighlighting/blade.js @@ -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); +} diff --git a/src/plugins/rehype/rehypeSyntaxHighlighting.ts b/src/plugins/rehype/rehypeSyntaxHighlighting.ts index c5a1f2e..f33a2c7 100644 --- a/src/plugins/rehype/rehypeSyntaxHighlighting.ts +++ b/src/plugins/rehype/rehypeSyntaxHighlighting.ts @@ -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;