php-collective / djot-grammars
Syntax highlighting grammars for the Djot markup language
Package info
github.com/php-collective/djot-grammars
Language:JavaScript
pkg:composer/php-collective/djot-grammars
Requires
- php: >=7.4
This package is auto-updated.
Last update: 2026-03-24 16:54:42 UTC
README
Syntax highlighting grammars for the Djot markup language.
Included Grammars
TextMate Grammar
Note: As of Phiki v2.1.1, the Djot grammar is bundled with Phiki. For PHP projects, use Phiki directly - no separate grammar installation needed. This file is kept for backwards compatibility with existing Shiki/Node.js projects.
Location: textmate/djot.tmLanguage.json
Works with:
- Shiki (VitePress, Astro, etc.)
- VS Code (via TextMate support)
- TextMate and compatible editors
- IntelliJ/PhpStorm (via Djot plugin)
Usage with Shiki (Node.js)
import { createHighlighter } from 'shiki' import djotGrammar from 'djot-grammars/textmate/djot.tmLanguage.json' const highlighter = await createHighlighter({ themes: ['github-light'], langs: [djotGrammar], }) const html = highlighter.codeToHtml(code, { lang: 'djot', theme: 'github-light' })
Usage with VitePress
// .vitepress/config.ts import { defineConfig } from 'vitepress' import djotGrammar from 'djot-grammars/textmate/djot.tmLanguage.json' export default defineConfig({ markdown: { languages: [ { ...djotGrammar, name: 'djot', aliases: ['dj'] }, ], }, })
Usage with Phiki (PHP)
As of Phiki v2.1.1, Djot is bundled - just use it directly:
use Phiki\Phiki; $phiki = new Phiki(); $html = $phiki->codeToHtml($djotCode, 'djot', 'github-light');
highlight.js Grammar
Location: highlightjs/djot.js
Works with highlight.js for client-side syntax highlighting.
Usage
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script> <script src="path/to/djot-grammars/highlightjs/djot.js"></script> <script>hljs.highlightAll();</script>
<pre><code class="language-djot"> # Hello World This is *strong* and _emphasized_ text. </code></pre>
Prism.js Grammar
Location: prismjs/djot.js
Works with Prism.js for client-side syntax highlighting.
Usage
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script> <script src="path/to/djot-grammars/prismjs/djot.js"></script>
<pre><code class="language-djot"> # Hello World This is *strong* and _emphasized_ text. </code></pre>
Tiptap Integration
Location: tiptap/
WYSIWYG editor integration for Tiptap with Djot serialization.
Quick Start
import { Editor } from '@tiptap/core' import { DjotKit, serializeToDjot } from 'djot-grammars/tiptap' const editor = new Editor({ element: document.getElementById('editor'), extensions: [DjotKit], onUpdate: ({ editor }) => { const djot = serializeToDjot(editor.getJSON()) console.log(djot) }, })
Features
- DjotKit - All-in-one extension bundle with full Djot support
- Custom marks - Insert
{+text+}, Delete{-text-}, Div containers::: - Serializer - Convert editor content to Djot markup
- Tables, task lists, code blocks with language, images, links
See tiptap/README.md for full documentation. Demo.
External Grammars
These Djot grammars are maintained in other repositories:
| Grammar | Repository | Description |
|---|---|---|
| tree-sitter | treeman/tree-sitter-djot | For Neovim, Helix, and other tree-sitter editors |
| Vim | jgm/djot | Official Vim syntax file |
| Emacs | jgm/djot | Official Emacs major mode |
| Sublime Text | sorairolake/djot.sublime-syntax | Sublime Text syntax (archived) |
Supported Syntax
All grammars support the full Djot specification plus djot-php enhancements:
Block Elements
- Headings (
# Titlethrough###### Title) - Code fences (
```with optional language) - Div blocks (
:::with optional class) - Blockquotes (
> text) - Lists (bullets
-,*,+and numbered1.,1)) - Task lists (
- [ ],- [x]) - Definition lists (
: term) - Tables (
| cell | cell |with separator rows) - Line blocks (
| textfor poetry/addresses) - Horizontal rules (
---,***,___) - Block attributes (
{.class #id key=value})
Inline Elements
- Strong (
*bold*) - Emphasis (
_italic_) - Highlight (
{=text=}) - Insert (
{+text+}) - Delete (
{-text-}) - Superscript (
^text^,{^text^}) - Subscript (
~text~,{~text~}) - Inline code (
`code`) - Links (
[text](url),[text][ref]) - Images (
) - Autolinks (
<https://...>,<user@example.com>) - Footnotes (
[^note]and[^note]: definition) - Math (
$`code`$and$$`code`$$) - Symbols (
:name:) - Spans with attributes (
[text]{.class}) - Raw format markers (
`code`{=html}) - Escape sequences (
\*,\[, etc.) - Hard line breaks (
\at end of line) - Smart punctuation (
---,--,...)
djot-php Extensions
- Captions (
^ caption textfor images, tables, blockquotes) - Fenced comments (
%%%blocks) - Inline comments (
{% comment %}) - Table row/cell attributes (
| cell |{.class})
Installation
NPM
npm install djot-grammars
Composer (PHP)
composer require php-collective/djot-grammars
Manual
Download the grammar files directly from this repository.
Comparison
| Feature | TextMate | highlight.js | Prism.js | Tiptap | tree-sitter |
|---|---|---|---|---|---|
| Type | Syntax highlighting | Syntax highlighting | Syntax highlighting | WYSIWYG editor | Syntax highlighting |
| Rendering | Server/Client | Client | Client | Client | Server/Editor |
| JS required | Depends | Yes | Yes | Yes | No |
| Used by | Shiki, VS Code | highlight.js | Prism.js | Tiptap/ProseMirror | Neovim, Helix |
| Themes | VS Code themes | 90+ | 8+ | Custom CSS | Editor themes |
| Extensible | Limited | Some | Extensive | Yes | Yes |
Note: Phiki v2.1.1+ bundles the Djot grammar directly.
Testing
Run the test suite to validate all grammars:
npm run test:install # Install test dependencies npm test # Run grammar tests
The test suite validates TextMate, highlight.js, and Prism.js grammars against a comprehensive Djot syntax fixture covering all language elements.
Contributing
Contributions are welcome! Please ensure any changes maintain compatibility with the Djot specification.
License
MIT License - see LICENSE for details.
Related Projects
- Djot - The Djot markup language
- djot-php - PHP implementation
- djot.js - JavaScript implementation
- djot-intellij - IntelliJ/PhpStorm plugin