Skip to content

Commit 80f43c6

Browse files
Merge pull request #2365 from redis/DOC-5931-hier-diagram-hook
DOC-5931 "hierarchy" diagram hook
2 parents e87175e + d621529 commit 80f43c6

File tree

9 files changed

+1307
-30
lines changed

9 files changed

+1307
-30
lines changed

build/render_hook_docs/AI_RENDER_HOOK_LESSONS.md

Lines changed: 431 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
# Hierarchy Format Guide
2+
3+
This document describes the YAML-based format for representing hierarchies (class inheritance, filesystem trees, etc.) in Redis documentation.
4+
5+
## Overview
6+
7+
Hierarchies are written in YAML format within a code block with the language identifier `hierarchy`. The render hook preserves the YAML source for AI agents while JavaScript generates a visual diagram for users.
8+
9+
## Basic Syntax
10+
11+
### Simple Hierarchy
12+
13+
```yaml
14+
Parent:
15+
Child1:
16+
Child2:
17+
Grandchild1:
18+
Grandchild2:
19+
```
20+
21+
This represents:
22+
```
23+
Parent
24+
├── Child1
25+
├── Child2
26+
│ ├── Grandchild1
27+
│ └── Grandchild2
28+
```
29+
30+
### Quoted Names
31+
32+
Use quotes for names containing special characters (spaces, punctuation, etc.):
33+
34+
```yaml
35+
"Top-level folder":
36+
"file1.js":
37+
"file2.png":
38+
"Inner folder":
39+
"file3.jpg":
40+
```
41+
42+
This is especially important for:
43+
- Filenames with extensions (`.js`, `.png`, etc.)
44+
- Names with spaces
45+
- Names with hyphens or other punctuation
46+
47+
## Metadata
48+
49+
Add metadata to any item using the special `_meta` key:
50+
51+
```yaml
52+
"Exception":
53+
_meta:
54+
description: "Base exception class"
55+
"RuntimeException":
56+
"IOException":
57+
```
58+
59+
Currently supported metadata fields:
60+
- `description`: A brief description of the item (displayed as italic text after the item name)
61+
- `ellipsis`: Boolean indicating this is a placeholder for omitted items
62+
63+
## Ellipsis (Omitted Items)
64+
65+
Use an ellipsis item to indicate that some items are not shown:
66+
67+
```yaml
68+
"RedisError":
69+
"ConnectionError":
70+
"ResponseError":
71+
"InvalidResponse":
72+
"...":
73+
_meta:
74+
ellipsis: true
75+
description: "Other exception types"
76+
```
77+
78+
The `_meta` with `ellipsis: true` tells the renderer to display this as "..." and not expand it further. The ellipsis item is rendered with a dotted vertical line below it to indicate continuation. You can optionally add a `description` to provide context about the omitted items.
79+
80+
## Complete Example: Exception Hierarchy
81+
82+
```yaml
83+
"RedisError":
84+
_meta:
85+
description: "Base class for all redis-py exceptions"
86+
"ConnectionError":
87+
_meta:
88+
description: "Connection-related errors"
89+
"TimeoutError":
90+
"BusyLoadingError":
91+
"ResponseError":
92+
"InvalidResponse":
93+
"DataError":
94+
"PubSubError":
95+
"...":
96+
_meta:
97+
ellipsis: true
98+
description: "Other exception types"
99+
```
100+
101+
This represents an exception hierarchy with:
102+
- A base exception class with description
103+
- Nested exception types
104+
- An ellipsis indicating additional exception types not shown
105+
106+
## Complete Example: Filesystem Hierarchy
107+
108+
```yaml
109+
"(root)":
110+
"config.yaml":
111+
_meta:
112+
description: "Main configuration file"
113+
"jobs":
114+
_meta:
115+
description: "Folder containing job definitions"
116+
"default-job.yaml":
117+
_meta:
118+
description: "Default job configuration"
119+
"job1.yaml":
120+
"...":
121+
_meta:
122+
ellipsis: true
123+
description: "Other job files"
124+
```
125+
126+
This represents a filesystem structure with:
127+
- A root folder containing configuration files
128+
- Nested directories and files
129+
- Descriptions for each item
130+
- An ellipsis indicating additional files not shown
131+
132+
When `type="filesystem"` is used, the renderer displays file and folder icons next to each item.
133+
134+
## Usage in Markdown
135+
136+
### Code Block Syntax
137+
138+
~~~
139+
```hierarchy {type="filesystem"}
140+
Parent:
141+
Child1:
142+
Child2:
143+
```
144+
~~~
145+
146+
### Attributes
147+
148+
- `type` (optional): Indicates the kind of hierarchy. Common values:
149+
- `type="exception"` - Exception/error hierarchy
150+
- `type="filesystem"` - Filesystem or directory structure
151+
- `type="generic"` - Generic hierarchy (default if omitted)
152+
153+
The type helps the renderer apply appropriate styling and helps AI agents understand the context.
154+
155+
- `noicons` (optional): Disables icon rendering for filesystem hierarchies. Use `noicons="true"` to hide file/folder icons.
156+
- Only applies to `type="filesystem"`
157+
- Default: icons are shown
158+
159+
### Placement
160+
161+
Place the hierarchy code block where you want the diagram to appear in the rendered HTML. The render hook will:
162+
1. Preserve the YAML source in a `<pre>` element (for AI agents)
163+
2. Generate a visual diagram below it (for users with JavaScript)
164+
165+
## Best Practices
166+
167+
### Naming
168+
169+
- Use clear, descriptive names
170+
- Use quotes for any names with special characters
171+
- Keep names concise but meaningful
172+
173+
### Organization
174+
175+
- Order items logically (alphabetically, by importance, etc.)
176+
- Use ellipsis to indicate omitted items rather than showing everything
177+
- Group related items together
178+
179+
### Metadata
180+
181+
- Add metadata only when it provides useful information
182+
- Use consistent metadata field names across similar hierarchies
183+
- Keep descriptions brief (one sentence)
184+
185+
## Metadata Reference
186+
187+
### Supported Fields
188+
189+
| Field | Type | Purpose | Example |
190+
|-------|------|---------|---------|
191+
| `description` | string | Brief description of the item (displayed as italic text) | `"Base exception class"` |
192+
| `ellipsis` | boolean | Marks as placeholder for omitted items | `true` |
193+
194+
### Notes
195+
196+
- The `description` field is displayed as italic text after the item name in the rendered diagram
197+
- The `ellipsis` field should be set to `true` for items representing omitted content (typically named `"..."`)
198+
- Other metadata fields may be added in the future
199+
200+
## Rendering
201+
202+
### For Users (HTML)
203+
204+
The render hook generates a visual SVG diagram with:
205+
- ASCII art-style tree structure with indented text
206+
- Connected tree lines showing parent-child relationships
207+
- File and folder icons for filesystem hierarchies (when `type="filesystem"`)
208+
- Descriptions displayed as italic text after item names
209+
- Dotted vertical lines for ellipsis items indicating continuation
210+
- Space Mono font matching Redis documentation style
211+
212+
### For AI Agents (Markdown)
213+
214+
AI agents accessing the `.html.md` version see the raw YAML:
215+
- Clean, structured format
216+
- Easy to parse and understand
217+
- Metadata preserved for context
218+
- Descriptions available for understanding item purposes
219+
220+
## Validation
221+
222+
The YAML must be valid according to the YAML 1.2 specification:
223+
- Proper indentation (spaces, not tabs)
224+
- Quoted strings for special characters
225+
- Valid YAML syntax
226+
227+
Invalid YAML will cause rendering errors. Use a YAML validator to check your syntax.
228+
229+
## Real-World Examples
230+
231+
See the following files for real-world examples:
232+
- `content/develop/clients/redis-py/error-handling.md` - Exception hierarchy with descriptions
233+
- `content/integrate/redis-data-integration/data-pipelines/_index.md` - Filesystem hierarchy with file/folder icons
234+

0 commit comments

Comments
 (0)