Created
January 12, 2025 11:12
-
-
Save fulopattila122/bbceea3d09d8c7356d53065c6f3e223c to your computer and use it in GitHub Desktop.
PrismJS Blade Highlighter (minimal feature set)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prism.languages.blade = { | |
'comment': /^\{\{\-\-[\s\S]*?\-\-\}\}$/, | |
'directive-name': { | |
pattern: /^@[\w]+/, | |
alias: 'keyword' | |
}, | |
'keyword': /\b(?:if|elseif|else|endif|foreach|endforeach|for|endfor|forelse|endforelse|unless|endunless|isset|endisset|empty|endempty|auth|endauth|guest|endguest|production|endproduction|env|endenv|session|endession|while|endwhile|switch|endswitch|case|default|continue|break|class|php|endphp|checked|selected|disabled|readonly|required|include|each|once|push|endpush)\b/, | |
'string': { | |
pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/, | |
inside: { | |
'punctuation': /^['"]|['"]$/ | |
} | |
}, | |
'boolean': /\b(?:false|null|true)\b/, | |
'number': /\b0x[\dA-Fa-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][-+]?\d+)?/, | |
'operator': [ | |
{ | |
pattern: /(\s)(?:and|b-and|b-or|b-xor|ends with|in|is|matches|not|or|same as|starts with)(?=\s)/, | |
lookbehind: true | |
}, | |
/[=<>]=?|!=|\*\*?|\/\/?|\?:?|[-+~%|]/ | |
], | |
'punctuation': /[()\[\]{}:.,]/ | |
}; | |
Prism.hooks.add('before-tokenize', function (env) { | |
if (env.language !== 'blade') { | |
return; | |
} | |
var pattern = /\{(?:\{[\s\S]*?\}|\!\![\s\S]*?\!\!|\{[\s\S]*?\})\}|@[\w]+/g; | |
Prism.languages['markup-templating'].buildPlaceholders(env, 'blade', pattern); | |
}); | |
Prism.hooks.add('after-tokenize', function (env) { | |
Prism.languages['markup-templating'].tokenizePlaceholders(env, 'blade'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See: PrismJS/prism#2403