candycore/candy-shine
最新稳定版本:v0.2.0
Composer 安装命令:
composer require candycore/candy-shine
包简介
PHP port of charmbracelet/glamour — Markdown → ANSI renderer with word-wrap, OSC 8 hyperlinks, syntax highlighting, and 8 stock themes (ansi/plain/dark/light/notty/dracula/tokyo-night/pink).
README 文档
README
CandyShine
PHP port of charmbracelet/glamour —
Markdown → ANSI renderer built on league/commonmark and CandySprinkles.
composer require sugarcraft/candy-shine
The
Rendererexposes short-form aliases on every option:theme/wordWrap/hyperlinks/baseURL/tableWrap/inlineTableLinks/preservedNewLines/emoji/standardStyle. The upstream-mirroringwith*long forms still work — pick whichever reads better at the call site.
Quickstart
use SugarCraft\Shine\Renderer; echo (new Renderer())->render(<<<MD # Welcome A few **bold** and _italic_ words, with `inline code` and a [link](https://example.com). - one - two - three ```php echo "hello world";
MD);
## Themes
Stock presets:
```php
use SugarCraft\Shine\{Renderer, Theme};
new Renderer(Theme::ansi()); // default colourful
new Renderer(Theme::plain()); // no SGR
new Renderer(Theme::notty()); // alias for plain — non-TTY fallback
new Renderer(Theme::dark()); // dark-bg optimised
new Renderer(Theme::light()); // light-bg optimised
new Renderer(Theme::dracula()); // #282a36 / #ff79c6 palette
new Renderer(Theme::tokyoNight()); // #1a1b26 / #7aa2f7
new Renderer(Theme::pink()); // playful sweet palette
Custom JSON theme:
$theme = Theme::fromJson('./themes/my-theme.json'); echo (new Renderer($theme))->render($markdown);
JSON shape: an object keyed by element name (heading1, paragraph,
bold, italic, code, codeBlock, link, blockquote,
listMarker, rule, keyword, string, number, comment,
strike, linkText, image, htmlBlock, htmlSpan,
definitionTerm, definitionDescription, text, autolink); each
value carries foreground / background (hex / ansi:N /
ansi256:N) plus the SGR flags (bold, italic, underline,
strike, faint, blink, reverse).
Word-wrap + OSC 8 hyperlinks
$renderer = (new Renderer(Theme::dark())) ->withWordWrap(80) ->withHyperlinks(true); echo $renderer->render($markdown);
withHyperlinks(true) (default) wraps every [text](url) in
OSC 8 ; ; URL ST text OSC 8 ; ; ST so terminals that support it
render real clickable links. Falls back to text (url) when off.
What it renders
- Headings 1-6, paragraphs,
**bold**,_italic_,~~strike~~. - Inline code, fenced code blocks (with regex syntax highlighting for PHP / JS / TS / JSON / Python / Go / Bash / SQL), indented code.
- Bullet + ordered + nested lists.
- Block quotes (▎-prefixed).
- GFM tables (rendered via
Sprinkles\Tablewith rounded border). - Task lists (
☑/☐). - Links (with OSC 8 hyperlinks), autolinks, images (alt + url).
- HTML blocks + inline HTML — pass through with theme styling.
- Thematic breaks.
Authoring a custom theme
A Theme is a value object — every slot is a Style (or scalar).
Build one with the constructor and feed it to new Renderer($theme):
use SugarCraft\Core\Util\Color; use SugarCraft\Shine\Theme; use SugarCraft\Sprinkles\Style; $theme = new Theme( heading1: Style::new()->bold()->underline()->foreground(Color::hex('#ff5f87')), heading2: Style::new()->bold()->foreground(Color::hex('#ffd700')), heading3: Style::new()->bold()->foreground(Color::ansi(14)), heading4: Style::new()->bold()->foreground(Color::ansi(12)), heading5: Style::new()->bold()->foreground(Color::ansi(13)), heading6: Style::new()->bold()->foreground(Color::ansi(10)), paragraph: Style::new(), bold: Style::new()->bold(), italic: Style::new()->italic(), code: Style::new()->foreground(Color::hex('#ffd700')), codeBlock: Style::new()->faint(), link: Style::new()->underline()->foreground(Color::ansi(12)), blockquote: Style::new()->italic()->foreground(Color::ansi(8)), listMarker: Style::new()->foreground(Color::hex('#ff5f87')), rule: Style::new()->foreground(Color::ansi(8)), // Element extensions: headingPrefix: '❯ ', headingCase: 'upper', paragraphPrefix: ' ', documentMargin: 1, listLevelIndent: 4, taskTickedGlyph: '✓', taskUntickedGlyph:'·', horizontalRuleGlyph: '═', horizontalRuleLength: 60, ); echo (new Renderer($theme))->render($markdown);
The full slot reference (left-to-right reading the constructor):
| Block | Slots |
|---|---|
| Headings | heading1 … heading6 (with headingPrefix, headingSuffix, headingCase) |
| Paragraphs | paragraph (+ paragraphPrefix / paragraphSuffix) |
| Inline | bold · italic · strike · code · link · linkText · autolink · image · imageText · text |
| Block | codeBlock · blockquote · rule · listMarker · htmlBlock · htmlSpan |
| Document | documentMargin · documentIndent · documentBlockPrefix / Suffix |
| Lists | orderedListMarker · unorderedListMarker · orderedListMarkerFormat · unorderedListMarkerGlyph · listLevelIndent |
| Task list | taskTickedGlyph · taskUntickedGlyph |
| Horizontal rule | horizontalRuleGlyph · horizontalRuleLength |
| Tables | tableHeader · tableCell · tableSeparator · tableCenterSeparator · tableColumnSeparator · tableRowSeparator |
| Definition lists | definitionTerm · definitionDescription · definitionList |
| Syntax highlighting | keyword · string · number · comment |
Stock themes (Theme::ansi(), Theme::dark(), Theme::dracula(),
Theme::tokyoNight(), Theme::pink(), Theme::light(), Theme::ascii(),
Theme::notty(), Theme::plain()) are good starting points — copy
the constructor call and adjust the slots you care about.
Theme::fromEnvironment(?$default) reads GLAMOUR_STYLE (case-
insensitive, hyphen / underscore tolerant) so users can override the
theme without code changes:
GLAMOUR_STYLE=tokyo-night php examples/render.php
Renderer options
new Renderer($theme) ->withWordWrap(80) // wrap paragraphs / blockquotes / lists ->withHyperlinks(true) // emit OSC 8 link envelopes ->withBaseURL('https://docs.example.com/') // prefix relative links ->withTableWrap(true) // wrap text inside table cells ->withInlineTableLinks(false) // suppress (url) suffix in cells ->withPreservedNewLines(true) // keep `\n\n+` runs from source ->withStandardStyle('dracula') // re-pick the stock theme ->withEmoji(true); // expand `:smile:` shortcodes
Renderer::renderMarkdown($md, ?Theme) is a one-shot static
convenience for ad-hoc rendering. For repeated renders with the same
theme, build a Renderer and reuse it (the parser is cached per
instance).
Test
cd candy-shine && composer install && vendor/bin/phpunit
Demos
Render
Themes
candycore/candy-shine 适用场景与选型建议
candycore/candy-shine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 05 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「markdown」 「renderer」 「terminal」 「ansi」 「commonmark」 「syntax-highlighting」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 candycore/candy-shine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 candycore/candy-shine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 candycore/candy-shine 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
A fork of runcmf/runtracy
PHP Terminal emulator controller utilizing ANSI escape sequence coding.
Bootstraps errors and handles them via reporters and renderers
Adds more BBCode
Render small SVG icons to monochrome ANSI for terminal UIs (Laravel/Prompts, Symfony Console, plain CLI).
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 55
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-07

