|
| 1 | + |
| 2 | + |
| 3 | +# Kirby Code Highlighter |
| 4 | + |
| 5 | +> [!NOTE] |
| 6 | +> A server-side syntax highlighter plugin for Kirby CMS, powered by [Phiki](https://github.com/phikiphp/phiki), that uses TextMate grammars and VS Code themes to generate syntax-highlighted code within code blocks and KirbyText. |
| 7 | +
|
| 8 | +## ✨ Key Features |
| 9 | +- ⚡ **Performance:** Fast and powerful syntax highlighting. |
| 10 | +- 🚀 **Integration:** Works with Kirby code blocks and KirbyText. |
| 11 | +- 🌍 **Languages:** Over 200+ programming languages. |
| 12 | +- 🎨 **Themes:** Choose from 50+ stunning themes. |
| 13 | +- 🔐 **Base64 Support:** Handles base64-encoded content. |
| 14 | + |
| 15 | +## 📦 Installation |
| 16 | + |
| 17 | +### Composer |
| 18 | + |
| 19 | +```bash |
| 20 | +composer require bogdancondorachi/kirby-code-highlighter |
| 21 | +``` |
| 22 | + |
| 23 | +### Git Submodule |
| 24 | +```bash |
| 25 | +git submodule add https://github.com/bogdancondorachi/kirby-code-highlighter.git site/plugins/code-highlighter |
| 26 | +``` |
| 27 | + |
| 28 | +### Manual |
| 29 | + |
| 30 | +[Download](https://api.github.com/repos/bogdancondorachi/kirby-code-highlighter/zipball) and extract to:<br />`/site/plugins/code-highlighter` |
| 31 | + |
| 32 | +## ⚙️ Usage |
| 33 | + |
| 34 | +### Kirby Blocks Field |
| 35 | + |
| 36 | +This plugin seamlessly integrates with Kirby's native [`code` block](https://getkirby.com/docs/reference/panel/blocks/code) replacing its default behavior: |
| 37 | + |
| 38 | +```yaml |
| 39 | +blocks: |
| 40 | + type: blocks |
| 41 | + fieldsets: |
| 42 | + - code |
| 43 | +``` |
| 44 | +
|
| 45 | +### KirbyText |
| 46 | +Embed syntax-highlighted code directly in KirbyText fields: |
| 47 | +
|
| 48 | +<pre lang="no-highlight"><code>```php |
| 49 | +echo "Hello, world!"; |
| 50 | +``` |
| 51 | +</code></pre> |
| 52 | + |
| 53 | +Or use the plugin's custom KirbyTag with support for base64-encoded content: |
| 54 | + |
| 55 | +``` |
| 56 | +(code: ZWNobyAiSGVsbG8sIHdvcmxkISI7 lang: php theme: github-light) |
| 57 | +``` |
| 58 | + |
| 59 | +## 🔧 Configuration |
| 60 | +These options allow you to customize themes, language support, line numbering, and block behavior. All options are defined in your `config.php` file. |
| 61 | + |
| 62 | +### Default Theme |
| 63 | +Set the default theme for syntax highlighting: |
| 64 | + |
| 65 | +```php |
| 66 | +'bogdancondorachi.code-highlighter' => [ |
| 67 | + 'theme' => 'github-dark-dimmed', |
| 68 | +], |
| 69 | +``` |
| 70 | + |
| 71 | +### Line Numbering |
| 72 | +Enable line numbers in your highlighted code blocks: |
| 73 | + |
| 74 | +```php |
| 75 | +'bogdancondorachi.code-highlighter' => [ |
| 76 | + 'gutter' => true, |
| 77 | +], |
| 78 | +``` |
| 79 | + |
| 80 | +### Custom Languages and Themes for Code Blocks |
| 81 | +Customize the languages and themes available in Kirby’s code blocks: |
| 82 | + |
| 83 | +```php |
| 84 | +'bogdancondorachi.code-highlighter' => [ |
| 85 | + 'block.languages' => [ |
| 86 | + 'css' => 'CSS', |
| 87 | + 'php' => 'PHP', |
| 88 | + 'js' => 'JavaScript', |
| 89 | + ], |
| 90 | + 'block.themes' => [ |
| 91 | + 'github-dark' => 'GitHub Dark', |
| 92 | + 'github-light' => 'GitHub Light', |
| 93 | + 'plastic' => 'Plastic', |
| 94 | + ], |
| 95 | +], |
| 96 | +``` |
| 97 | + |
| 98 | +### Explore Supported Options |
| 99 | +- [Supported Languages](https://shiki.matsu.io/languages) |
| 100 | +- [Supported Themes](https://shiki.matsu.io/themes) |
| 101 | + |
| 102 | +## 🙏 Credits |
| 103 | +- [Ryan Chandler](https://github.com/ryangjchandler) for his excellent work on porting Shiki to PHP via [Phiki](https://github.com/phikiphp/phiki). |
| 104 | +- [Johann Schopplich](https://github.com/johannschopplich) for his [Kirby Highlighter](https://github.com/johannschopplich/kirby-highlighter), which served as base for this project. |
| 105 | + |
| 106 | +## 📜 License |
| 107 | +[MIT License](./LICENSE) Copyright © 2024 [Bogdan Condorachi](https://github.com/bogdancondorachi) |
0 commit comments