Skip to content

Commit 6476f3e

Browse files
committed
Add a docs file for agents
1 parent 9bb13b7 commit 6476f3e

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

AGENTS.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Agent Notes for django-prose-editor
2+
3+
This document contains information for AI agents working on this project.
4+
5+
## Project Structure
6+
7+
- **Python/Django Backend**: Django app in `django_prose_editor/`
8+
- **JavaScript/TypeScript Frontend**: Tiptap editor extensions in `src/`
9+
- **Tests**: Python tests in `tests/`, uses Playwright for E2E tests
10+
- **Documentation**: ReStructuredText files in `docs/`
11+
12+
## Running Tests
13+
14+
Use `tox` to run tests:
15+
16+
```bash
17+
# Run tests with Python 3.13 and Django 5.2
18+
tox -e py313-dj52
19+
```
20+
21+
Tests include both unit tests and Playwright E2E tests. The test suite will automatically install Chromium if needed.
22+
23+
## JavaScript Development
24+
25+
The project uses:
26+
- **Tiptap** for the rich text editor
27+
- **rslib** for building JavaScript modules
28+
- **prek** for linting and formatting (Rust-based pre-commit alternative, runs Biome and other tools)
29+
30+
JavaScript source files are in `src/` and get built into `django_prose_editor/static/`.
31+
32+
## Documentation
33+
34+
Documentation is written in ReStructuredText (`.rst`) format in the `docs/` directory.
35+
36+
When modifying extensions or features:
37+
1. Update the relevant `.rst` file in `docs/`
38+
2. Include code examples in both Python and JavaScript
39+
3. Document configuration options, usage patterns, and HTML output
40+
41+
## Code Organization
42+
43+
### Tiptap Extensions
44+
45+
- Extensions are in `src/`
46+
- Each extension typically exports a Tiptap extension object
47+
- Extensions can add attributes to nodes/marks using `addGlobalAttributes()`
48+
- Menu items are added via `addMenuItems({ buttons, menu })`
49+
50+
### Key Patterns
51+
52+
**Distinguishing Nodes vs Marks:**
53+
```javascript
54+
const isNodeType = (editor, typeName) => {
55+
return !!editor.state.schema.nodes[typeName]
56+
}
57+
```
58+
59+
**Getting Applicable Items:**
60+
- For nodes: Walk up the document tree from the selection
61+
- For marks: Check marks at the current selection position
62+
63+
**Menu Items:**
64+
- Use `active()` to determine if option should be highlighted
65+
- Use `hidden()` to determine if option should be shown
66+
- For marks: Hide when selection is empty or mark type not active
67+
- For nodes: Hide when node type is not in ancestor chain
68+
69+
## Testing Workflow
70+
71+
1. Make code changes
72+
2. Run linting/formatting: `prek run --all-files` (or let it run on commit)
73+
3. Run tests: `tox -e py313-dj52`
74+
4. Verify all tests pass (32 tests expected)
75+
5. Update documentation if needed
76+
77+
## Common Tasks
78+
79+
### Adding Support for Both Nodes and Marks
80+
81+
When an extension needs to support both nodes and marks:
82+
83+
1. Use a single configuration object (e.g., `cssClasses`)
84+
2. Check the schema at runtime to determine if type is node or mark
85+
3. Handle nodes with `setNodeAttribute()` and transactions
86+
4. Handle marks with `setMark()` and `isActive()`
87+
5. Update menu `hidden()` logic appropriately for each type
88+
89+
### Configuration Options
90+
91+
Extensions are configured in two ways:
92+
- **Python**: Via `ProseEditorField(extensions={...})`
93+
- **JavaScript**: Via `Extension.configure({...})`
94+
95+
Keep both configuration methods documented and in sync.

0 commit comments

Comments
 (0)