This very blog you are reading uses Shiki to highlight code snippets. In the browser, this will be displayed as: This is the html that Shiki will be returned: < ?php echo ' Hello World ' ? >use Spatie\ShikiPhp\Shiki Shiki :: highlight ( code : '', language : 'php', theme : 'github-light', ) Using Shiki is simple, you pass it some code, the language of the code you are passing and one of the many available themes. Here's a good first example where we are going to highlight a simple PHP script. The first package we released, spatie/shiki-php, allows you to highlight any given code snippet. My colleague Rias used that blog post as inspiration to toy with Shiki and bringing its magic to the PHP world. Miguel's blog post mentioned how you could use Shiki in a JS / Node environment. Its highlighting is near perfect, and it can even handle modern PHP Syntax. Shiki is the code renderer behind VSCode. While the highlighting provides by highlight.php/js is pretty good, it's not perfect.Ī couple of months ago, Miguel Piedrafita blogged about highlighting using Shiki. Highlight.php is inspired by hightlight.js. This renderer uses highlight.php to render code blocks in Markdown. This package offers a renderer class that can be used with the league's popular commonmark package. On this very blog, spatie.be and related sites, we have relied on our trusty commonmark-highlighter package for the past couple of years. We're already using this package to render all our documentation pages, our guidelines, and this very blog you are reading. laravel-markdown: a batteries included Laravel package that offers a Blade component to easily render Markdown with highlighted code snippets and a class to render Markdown manually. commonmark-shiki-highlighter: allows commonmark to highlight all code snippets in a markdown fragment.shiki-php: makes it easy to call Shiki from PHP to highlight a given code snippet.I'm proud to announce that we have released three new Spatie packages that make it easy to use Shiki in your PHP projects: It supports 100 languages (via our package Blade is supported too), and all VS Code themes. The code highlighting it provides is near perfect, even when using modern syntax. Shiki is the code highlighter that uses the textmate parser VSCode uses under the hood. When reading technical blogpost around the web, you might have noticed that code highlighting is not always perfect.
0 Comments
Leave a Reply. |