Skip to content

Commit e2c0a12

Browse files
authored
docs: Add dedicated syntax highlighting cookbook page (#98)
* docs: Add dedicated syntax highlighting cookbook page - Create comprehensive syntax-highlighting.md covering Shiki, highlight.js, and Prism.js - Document canonical sources for Djot grammars (TextMate from djot-intellij, hljs from this repo) - Note known limitations in hljs grammar vs TextMate grammar - Add comparison table and recommendations for different use cases - Update cookbook index to link to new page - Add to sidebar navigation * Remove 'Syntax Highlighting' section from index Removed the 'Syntax Highlighting' section and its link from the cookbook index.
1 parent 0490149 commit e2c0a12

3 files changed

Lines changed: 380 additions & 32 deletions

File tree

docs/.vitepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export default defineConfig({
8181
text: 'Cookbook',
8282
items: [
8383
{ text: 'HTML Customization', link: '/cookbook/' },
84+
{ text: 'Syntax Highlighting', link: '/cookbook/syntax-highlighting' },
8485
{ text: 'PlainText Renderer', link: '/cookbook/plaintext' },
8586
{ text: 'Markdown Renderer', link: '/cookbook/markdown' },
8687
{ text: 'ANSI Renderer', link: '/cookbook/ansi' },

docs/cookbook/index.md

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Common recipes and customizations for djot-php.
88
- [Custom Emoji/Symbols](#custom-emojisymbols)
99
- [Unicode Codepoints](#unicode-codepoints)
1010
- [Abbreviations](#abbreviations)
11-
- [Syntax Highlighting](#syntax-highlighting)
1211
- [Table of Contents Generation](#table-of-contents-generation)
1312
- [Image Processing](#image-processing)
1413
- [Custom Admonitions](#custom-admonitions)
@@ -329,37 +328,6 @@ Output:
329328
This uses standard djot span syntax with attributes, so no custom parsing is needed.
330329
You can combine with other attributes: `[CSS]{abbr="Cascading Style Sheets" .tech-term}`.
331330

332-
## Syntax Highlighting
333-
334-
Add syntax highlighting classes for a JS library like Prism or Highlight.js:
335-
336-
```php
337-
use Djot\DjotConverter;
338-
use Djot\Event\RenderEvent;
339-
use Djot\Node\Block\CodeBlock;
340-
341-
$converter = new DjotConverter();
342-
343-
$converter->on('render.code_block', function (RenderEvent $event): void {
344-
$block = $event->getNode();
345-
if (!$block instanceof CodeBlock) {
346-
return;
347-
}
348-
349-
$lang = $block->getLanguage();
350-
$code = htmlspecialchars($block->getContent(), ENT_QUOTES, 'UTF-8');
351-
352-
if ($lang) {
353-
// For Prism.js
354-
$html = '<pre class="language-' . $lang . '"><code class="language-' . $lang . '">' . $code . '</code></pre>' . "\n";
355-
} else {
356-
$html = '<pre><code>' . $code . '</code></pre>' . "\n";
357-
}
358-
359-
$event->setHtml($html);
360-
});
361-
```
362-
363331
## Table of Contents Generation
364332

365333
> **Tip:** Use the built-in [TableOfContentsExtension](/extensions/#tableofcontentsextension) for common cases.

0 commit comments

Comments
 (0)