markdown-editor
AGENTS.md428 starsChanged 2 years agoMITView on GitHub
Where this file says nothing, copy the closest existing example in the repository: folder structure, file names, names of variables, functions, types and constants, class structure, React components and hooks, styles and CSS class names, i18n keys, exports, tests, demo stories. Add a new kind of file only if the repository already has one like it. Always run visual (Playwright) tests in Docker. Never run them locally. Their setup, commands and screenshot rules are in demo/AGENTS.md; read it before writing…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 33,315 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository3 other files it gives its agents.
- demo/AGENTS.mdAGENTS.md
- .claude/CLAUDE.mdCLAUDE.md
- demo/CLAUDE.mdCLAUDE.md
The file
We split this AGENTS.md into the rules it gives an agent
8 rules. About 0 are common, 4 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 13
Test names (it, test, and parameterized cases) must start with should , followed by a base-form verb.
- Very specific: line 18
Check source API contracts with the package's typecheck command.
- Distinctive: line 19
Use explicit type assignments to check result types, methods, and overloads.
- Very specific: line 20
Use @ts-expect-error for inputs or assignments that must be rejected.
- Distinctive: line 21
Keep each contract check in a small function or type alias.
- Distinctive: line 33
Never format code by hand, and never reformat lines you did not change.
- Distinctive: line 34
Read git status after a fix run and commit only the files your change belongs to.
- Very specific: line 36
Write code the way the linter wants it from the start: T[] instead of Array<T>, object shorthand ({foo} instead of {foo: foo}), inline type …
≈ “Common” is an estimate: at least 1 in 5 of the 42,283 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md — gravity-ui/markdown-editor
Following existing code
Where this file says nothing, copy the closest existing example in the repository: folder structure, file names, names of variables, functions, types and constants, class structure, React components and hooks, styles and CSS class names, i18n keys, exports, tests, demo stories. Add a new kind of file only if the repository already has one like it.
Testing
Always run visual (Playwright) tests in Docker. Never run them locally. Their setup, commands and screenshot rules are in demo/AGENTS.md; read it before writing or running a visual test.
Unit tests use Vitest and run with pnpm test from the root. Import describe, it, expect, hooks, and vi explicitly from vitest; globals are disabled.
Test names (it, test, and parameterized cases) must start with should , followed by a base-form verb.
Type contract tests follow the same rules in every package:
- Store them in the package's
tests/types/directory as*.types.ts. - Check source API contracts with the package's
typecheckcommand. Contracts that import the built package may use a separate TypeScript configuration and command, run after a fresh build as part of package tests and CI. This does not require a build intypecheck. - Use explicit type assignments to check result types, methods, and overloads.
- Use
@ts-expect-errorfor inputs or assignments that must be rejected. The check must fail if the expected error disappears. - Keep each contract check in a small function or type alias. These files are checked without execution; runtime behavior belongs in Vitest tests.
Code style
Prettier owns formatting, ESLint and Stylelint own the rest. One command applies the fixes of all three:
pnpm fix:lintIt covers *.{js,jsx,mjs,ts,tsx,css,scss} across the whole repository. Its output lists every file Prettier went through along with the problems that need a human. pnpm lint reports the problems alone, without touching files, and is what CI runs on every pull request.
- Never format code by hand, and never reformat lines you did not change.
- Read
git statusafter a fix run and commit only the files your change belongs to. - An
eslint-disablecomment that no longer suppresses anything is an error. Remove it instead of keeping it for safety. - Write code the way the linter wants it from the start:
T[]instead ofArray<T>, object shorthand ({foo}instead of{foo: foo}), inline type imports (import {type Foo} from './foo'). - Where the linter is silent, follow the file you are editing.
- Shared rules live in
infra/linters/; per-package overrides are in the rooteslint.config.mjs.
Extensions
An extension Block in packages/editor/src/extensions/ has this layout:
Block/
BlockSpecs/
index.ts
const.ts
BlockSpecs.ts
BlockNodeView/
components/
<React components>
index.ts
BlockNodeView.ts
plugins/
BlockPlugin/
index.ts
plugin.ts
Block.ts
index.tsBlock.tsholds the extension; everyindex.tsonly re-exports.BlockSpecs/holds the schema, the parser and the serializer;const.tsholds node and attribute names.- A NodeView is a class in
BlockNodeView/; its React components live incomponents/. - Class names come from
cn; element state is a modifier. - A markdown-it plugin emits one token stream; extra data goes to
token.meta. - A markdown-it plugin only parses. The serializer lives in the extension and writes through
state.
Package naming
Published @gravity-ui/* packages live directly in packages/. The npm name starts with the target (editor, viewer or plugin), and the entity name comes before its kind:
| Package | npm name | Directory |
| Editor extension | @gravity-ui/markdown-editor-<name>-extension | packages/editor-<name>-extension |
| Viewer extension | @gravity-ui/markdown-viewer-<name>-extension | packages/viewer-<name>-extension |
| markdown-it plugin | @gravity-ui/markdown-plugin-<name> | packages/plugin-<name> |
- The directory name is the npm name without the
@gravity-ui/markdown-prefix. - Examples:
packages/editor-header-extensionandpackages/plugin-header.
Package structure
New editor packages split code by mode:
src/
wysiwyg/
extensions/
<Extension>/
markup/
commands/
<command>.ts
toolbar/
view/
items.ts
wysiwyg/
items.ts
presets.ts # optional
markup/
items.ts
presets.ts # optional
items.ts # both modes
presets.ts # both modes, optionalExports in package.json:
| Export | Contents |
. | Toolbars, WYSIWYG and markup entities |
./wysiwyg | WYSIWYG entities only: extensions, toolbar items without markup |
./wysiwyg/specs | WYSIWYG specs only: spec extensions, constants |
./wysiwyg/utils | WYSIWYG utils, optional |
./markup | Markup entities only: CodeMirror commands and extensions, toolbar items without wysiwyg |
./markup/utils | Markup utils, optional |
./wysiwyg/core | WYSIWYG core, root editor package only |
./pm/*, ./cm/* | ProseMirror and CodeMirror re-exports, root editor package only |
Documentation
Project docs live in docs/. Read the relevant file before working on the corresponding area:
| When you're working on… | Read |
| Visual / Playwright tests | docs/how-to-add-visual-test.md |
| Creating a new extension | docs/how-to-create-extension.md |
| Core exporters | docs/core-exporters.md |
| Adding Markdown text bindings | docs/how-to-add-text-binding-extension-in-markdown.md |
| Customizing toolbars | docs/how-to-customize-toolbars.md |
| Customizing the editor | docs/how-to-customize-the-editor.md |
| Adding preview | docs/how-to-add-preview.md |
| GPT / AI extensions | docs/how-to-connect-gpt-extensions.md |
| Contributing guidelines | docs/guidelines-contributions.md |
Stack
- TypeScript, React 18
- CodeMirror 6, ProseMirror
- Vitest (unit), Playwright (visual/e2e)
- pnpm + nx monorepo
- Podman / Docker for containerized test runs
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

