Skip to content

Commit 294e8a1

Browse files
committed
Add AnsiRenderer for terminal output
Adds a new renderer that outputs ANSI-formatted text for terminal display. Features: - Colored headings (different colors per level, underlined h1/h2) - Bold, italic, underline, strikethrough styling - Colored inline code - Unicode box-drawing for tables - Blockquote bars with color - Bullet points (• or * fallback) - Task list checkboxes (☑/☐) - Super/subscript using Unicode characters - Symbol to emoji mapping (:heart: → ❤) - Configurable: colors, Unicode, terminal width Use cases: - CLI documentation viewers - Terminal-based Djot editors - Developer tooling - README previews in terminal 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 1031279 commit 294e8a1

File tree

3 files changed

+1244
-0
lines changed

3 files changed

+1244
-0
lines changed

examples/ansi-demo.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/**
5+
* ANSI Renderer Demo
6+
*
7+
* Run this script in a terminal to see colorized Djot output:
8+
* php examples/ansi-demo.php
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
require __DIR__ . '/../vendor/autoload.php';
14+
15+
use Djot\DjotConverter;
16+
use Djot\Renderer\AnsiRenderer;
17+
18+
$djot = <<<'DJOT'
19+
# Welcome to Djot
20+
21+
Djot is a lightweight markup language with _emphasis_, *strong*, and `inline code`.
22+
23+
## Features
24+
25+
- {=Highlighted text=} for important notes
26+
- {+Inserted+} and {-deleted-} text
27+
- Superscript: E=mc{^2^}
28+
- Subscript: H{~2~}O
29+
- Symbols: I :heart: Djot!
30+
31+
## Code Example
32+
33+
```php
34+
$converter = new DjotConverter();
35+
echo $converter->convert($djot);
36+
```
37+
38+
## Links and Images
39+
40+
Visit [the Djot website](https://djot.net) for more info.
41+
42+
![A sample image](photo.jpg)
43+
44+
## Blockquotes
45+
46+
> Djot is designed to be parsed without backtracking,
47+
> making it fast and predictable.
48+
>
49+
> — John MacFarlane
50+
51+
## Tables
52+
53+
| Feature | Markdown | Djot |
54+
|--------------|----------|------|
55+
| Highlighting | No | Yes |
56+
| Attributes | No | Yes |
57+
| Consistent | No | Yes |
58+
59+
## Definition List
60+
61+
: Djot
62+
A modern markup language designed for clarity.
63+
64+
: Markdown
65+
The predecessor with many flavors.
66+
67+
## Task List
68+
69+
- [ ] Learn Djot syntax
70+
- [x] Install djot-php
71+
- [ ] Build something awesome
72+
73+
---
74+
75+
## Footnotes
76+
77+
Here's a statement with a footnote[^1].
78+
79+
[^1]: This is the footnote content.
80+
DJOT;
81+
82+
$converter = new DjotConverter();
83+
$renderer = new AnsiRenderer();
84+
85+
// Parse and render
86+
$document = $converter->parse($djot);
87+
$output = $renderer->render($document);
88+
89+
echo $output;

0 commit comments

Comments
 (0)