定制 php-collective/djot-grammars 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

php-collective/djot-grammars

Composer 安装命令:

composer require php-collective/djot-grammars

包简介

Syntax highlighting grammars for the Djot markup language

README 文档

README

Tests

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 (# Title through ###### Title)
  • Code fences (``` with optional language)
  • Div blocks (::: with optional class)
  • Blockquotes (> text)
  • Lists (bullets -, *, + and numbered 1., 1))
  • Task lists (- [ ], - [x])
  • Definition lists (: term)
  • Tables (| cell | cell | with separator rows)
  • Line blocks (| text for 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 (![alt](url))
  • 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 text for 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

php-collective/djot-grammars 适用场景与选型建议

php-collective/djot-grammars 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 329 次下载、GitHub Stars 达 2, 最近一次更新时间为 2026 年 03 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「grammar」 「syntax-highlighting」 「textmate」 「djot」 「phiki」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 php-collective/djot-grammars 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 php-collective/djot-grammars 我们能提供哪些服务?
定制开发 / 二次开发

基于 php-collective/djot-grammars 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 329
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 33
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-16