Skip to content

docs: add a runnable custom conversion rule - #112

Merged
noeltock merged 1 commit into
mainfrom
codex/docs-custom-rule-109
Sep 15, 2026
Merged

noeltock merged 1 commit into
mainfrom
codex/docs-custom-rule-109

Conversation

@noeltock

@noeltock noeltock commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Problem

Developers can supply custom HTML conversion rules, but there was no runnable example showing the hook or its limits. Closes #109.

Solution

Add a small paragraph rule, a guide with the actual CLI output, and a test that imports the shipped example.

Behaviour Read first Proof
Marked paragraphs become native paragraphs with a notice class examples/custom-rule.mjs CLI example and focused test
Unmarked input keeps normal conversion dev/test/custom-rule-example.test.ts Control paragraph assertion
Rules retain the normal style and validation steps docs/extending.md Source review and zero-invalid output

Diff

+89 −0 · 3 files · no runtime or API changes

+ examples/custom-rule.mjs
+   p[data-notice] -> core/paragraph with className: notice
+ docs/extending.md
+   runnable command, output, precedence and limitations
+ dev/test/custom-rule-example.test.ts
+   imports the example; checks marked and unmarked native output

Testing & verification

Reviewed revision: 861201e0acec0b573845357e7dc728a884239ab9 · Environment: macOS, Node 22.23.1; existing matching dependencies reused.

  • npm run build — passed.
  • npx vitest run dev/test/custom-rule-example.test.ts dev/test/convert.test.ts — passed, 2 files / 6 tests.
  • npx --no-install block-runner convert '<p data-notice>Service update</p>' --config examples/custom-rule.mjs — passed; emitted the documented native paragraph with the notice class.
  • npm run typecheck and npm run check:private — passed.
  • npm run pack:check — passed; includes examples/custom-rule.mjs.
  • git diff --cached --check — passed before commit. Reviewed the new guide separately for private references because the packed-file scan excludes docs/.

A fresh installed consumer also ran npx --no-install block-runner convert '<p data-notice>Service update</p>' --config node_modules/block-runner/examples/custom-rule.mjs --json — passed with one valid native paragraph, zero invalid blocks and no warnings. Its resolved dependency tree emitted class="notice notice"; the locked checkout emits class="notice". The reported block attribute is className: "notice" in both. The guide shows the observed checkout output; this PR does not change serialization.

Not verified: real-WordPress rendering and third-party block registration. The example establishes conversion and headless validity only; it does not generate CSS. GitHub CI: all three Node lanes and the package check passed. The first WordPress run failed its native style-adapter editor check: the retained receipt records a 1278px viewport where 1280px was required. Attempt 1 evidence is retained. The same runtime code passed on #113. gh run rerun 34981527836 --failed --repo humanmade/block-runner — passed in attempt 2. All checks passed on the unchanged revision; no test threshold or runtime source was changed.

Risk / rollout

The hook forwards this example's simple paragraph content; the guide does not promise sanitisation or arbitrary rich-text support. No dependencies, website files or default rules change.

Detection: the test imports the actual example and checks both inputs. Rollback: revert this commit.

Authored by: GPT-6 via Codex.

@noeltock
noeltock merged commit fcee42d into main Sep 15, 2026
16 of 18 checks passed
@noeltock
noeltock deleted the codex/docs-custom-rule-109 branch September 15, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs: explain custom conversion rules with a runnable example

1 participant