# Add a Custom Code Block Renderer to an Obsidian Plugin

Yes. An agent registers a code block processor in your Obsidian plugin that renders a fenced block as a table, with a pure parser, a test and styles, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-code-block-processor/obsidian-plugin/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the plugin's shape before adding to it. In a plugin laid out like obsidianmd/obsidian-sample-plugin, `src/main.ts` holds `MyPlugin extends Plugin`, whose `onload` registers a ribbon icon, a status bar item, three commands (`open-modal-simple`, `replace-selected` with an `editorCallback`, and `open-modal-complex` with a `checkCallback`), a `SampleSettingTab`, a DOM click listener through `registerDomEvent` and a five-minute `registerInterval`; `src/settings.ts` has `MyPluginSettings` with one string field and the tab that edits it. `styles.css` is an empty comment. `manifest.json` names the plugin `sample-plugin` with `minAppVersion` 1.0.0 and `isDesktopOnly: false`. `esbuild.config.mjs` bundles `src/main.ts` to `main.js` as CommonJS targeting ES2021, with `obsidian`, `electron` and the CodeMirror packages external, and `npm run build` runs `tsc -noEmit -skipLibCheck` first. `eslint.config.mts` loads `eslint-plugin-obsidianmd`'s recommended rules with the TypeScript project service, `tsconfig.json` is `strict` with `noUncheckedIndexedAccess`, and `.github/workflows/lint.yml` runs `npm ci`, the build and `npm run lint` on Node 20, 22 and 24. `AGENTS.md` asks for small modules outside `main.ts`, `register*` helpers for anything needing cleanup, sentence case in UI text and no network calls.

The feature is a `csv` code block that renders as a table, which is the shape most custom blocks take: text in, DOM out. The parser goes in `src/processors/csv-parse.ts` as a pure function with no `obsidian` import, splitting lines, honouring double-quoted fields that contain commas, and returning rows of strings. The renderer in `src/processors/csv.ts` exports `registerCsvBlock(plugin)`, which calls `plugin.registerMarkdownCodeBlockProcessor('csv', (source, el, ctx) => ...)`, parses `source`, and builds a `table` with `el.createEl`, a `thead` from the first row when the new `firstRowIsHeader` setting is on and a `tbody` for the rest, each cell set with `setText` so no block content is ever treated as HTML. An empty block renders a short `div` with a class and a sentence-case message instead of an empty table. `main.ts` changes by one call in `onload`, and `settings.ts` gains the boolean with a toggle in the tab, defaulting to on.

The parser being pure is what makes it testable without Obsidian. `test/csv-parse.test.ts` uses `node:test` and covers a plain row, a quoted field with a comma, trailing blank lines and an empty source, and `package.json` gets `"test": "node --test --experimental-strip-types test/"`, which runs TypeScript directly on Node 22 and 24 without a transpile step and without a new dependency. Because the lint workflow's matrix still includes Node 20, where that flag does not exist, the agent adds the `npm test` step to `lint.yml` with a condition that skips it on the 20.x entry rather than dropping the version from the matrix. `styles.css` gets rules for the table's class so the plugin's CSS follows Obsidian's theme variables rather than fixed colours.

No bump of `minAppVersion` is needed, since `registerMarkdownCodeBlockProcessor` long predates the 1.0.0 the manifest already requires, and the pull request says so. `README.md` gains a short section with an example block. The agent runs `npm ci`, `npm run build`, `npm run lint` and `npm test` in its sandbox and checks that `main.js` stays uncommitted as `.gitignore` and `AGENTS.md` require.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add a custom code block renderer to this Obsidian plugin. Read src/main.ts, src/settings.ts, styles.css, manifest.json, esbuild.config.mjs, eslint.config.mts, tsconfig.json, .github/workflows/lint.yml and AGENTS.md first. Register a processor for csv fenced blocks that renders a table: put a pure parser with no obsidian import in src/processors/csv-parse.ts that handles double-quoted fields containing commas and blank lines, put the renderer in src/processors/csv.ts and call it from onload with one line. Build the DOM with createEl and setText, never innerHTML. Add a firstRowIsHeader setting with a toggle in the settings tab, defaulting to on, and render an empty block as a short message. Add node:test tests for the parser under test/ with a test script using --experimental-strip-types and no new dependencies, and add npm test to lint.yml skipped on Node 20. Add table styles to styles.css using Obsidian's CSS variables and a README section with an example block. Do not change minAppVersion. Run npm ci, npm run build, npm run lint and npm test, and open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The pull request adds `src/processors/csv-parse.ts`, `src/processors/csv.ts` and `test/csv-parse.test.ts`, adds the setting to `src/settings.ts`, the one-line registration to `src/main.ts`, table rules to `styles.css`, a `test` script to `package.json`, a conditional step to `lint.yml` and a usage section to `README.md`. Its description shows the build, lint and test output from the sandbox and a sample block with the table it produces, described in words since the sandbox has no Obsidian to screenshot.

Before merging, a reviewer loads `main.js` into a test vault to see the table in reading view and live preview, decides whether `csv` is the right language name or a plugin-specific one avoids clashing with other plugins, and whether the header toggle belongs in settings or as a parameter on the block itself.

## Run it on every plugin repository

A developer who maintains several plugins from the same template sends this body once per repository from their own server, each a `POST /o/{org}/sessions` with that repository in `resources` and a `request_id` that is a UUID v5 of the repository's full name, so a retried call returns the run already started. Each run reads its own `main.ts`: a plugin that already has a `processors` folder gets the new file beside the others, and one whose `lint.yml` has no Node 20 entry gets the test step without the condition.

Once the block exists, an automation on the Project with a `github` trigger on `pull_request.opened` and the prompt "if this pull request changes anything under src/processors, run npm test and npm run lint and comment with the result" starts one run per pull request. The trigger adds the pull request after the prompt, and only work by an owner, member or collaborator fires it.

## Why run it on Rush?

A code block processor is a small API with a few ways to go wrong that only show up at review time: content pasted in as HTML, a parser tangled with the DOM so nothing can be tested, a `minAppVersion` bumped for no reason. The agent reads the template's own `AGENTS.md` conventions and the lint rules the repository already enforces, and writes the feature to pass them.

The build, lint and test output stay with the run, so a reviewer sees that the strict type check and the Obsidian lint rules pass before loading the plugin into a vault. The same request runs across every plugin a developer keeps, each in its own sandbox.

## Frequently asked questions

### Why keep the parser separate from the renderer?

The renderer needs Obsidian's `Plugin` and DOM helpers, which only exist inside the app. A parser with no `obsidian` import runs under `node --test`, so the quoting and blank-line cases are covered in CI without an Obsidian build. It also keeps `main.ts` to the lifecycle code `AGENTS.md` asks for.

### Does it need innerHTML or a Markdown library?

No. Each cell is created with `createEl` and filled with `setText`, so a comma-separated value that looks like a tag is shown as text. Nothing is parsed as HTML, and the bundle gains no dependency.

### Will the test step break the Node 20 job?

The test script relies on `--experimental-strip-types`, which Node 20 lacks, so the step carries a condition that skips it on that matrix entry. The build and lint still run on all three versions, and the description notes that dropping 20 from the matrix later removes the condition.

### Does minAppVersion change?

No. The processor API is older than the 1.0.0 the manifest already requires, and `AGENTS.md` asks to keep the value accurate rather than high. The `versions.json` map is untouched because no release is cut by this change.

## More Obsidian plugin jobs

- [Add Context Menu Items to an Obsidian Plugin](https://getrush.ai/run/add-context-menu/obsidian-plugin/)
- [Add a Custom Sidebar View to an Obsidian Plugin](https://getrush.ai/run/add-custom-view/obsidian-plugin/)
- [Add Dependabot to an Obsidian Plugin](https://getrush.ai/run/add-dependabot/obsidian-plugin/)

## More jobs like this: Hand off a long task

- [Add Route-Based Code Splitting to a React App](https://getrush.ai/run/add-code-splitting/react/)
- [Check sqlc Generated Code in CI With sqlc diff and sqlc vet](https://getrush.ai/run/add-codegen-check-to-ci/sqlc/)
- [Add CodeQL Scanning to a CMake C++ Project](https://getrush.ai/run/add-codeql-scanning/cmake/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
