Skip to content

Comments

feat: extract @portabletext/html package from block-tools#2225

Draft
christianhg wants to merge 3 commits intomainfrom
feat/html-package
Draft

feat: extract @portabletext/html package from block-tools#2225
christianhg wants to merge 3 commits intomainfrom
feat/html-package

Conversation

@christianhg
Copy link
Member

@christianhg christianhg commented Feb 20, 2026

Extract HTML-to-Portable Text conversion from @portabletext/block-tools into a new @portabletext/html package, mirroring the @portabletext/markdown API.

Block-tools has always been a thin wrapper around code that does not depend on @sanity/* types. This makes that split explicit: the new package owns the deserializer, rules, preprocessors, and all tests. Block-tools becomes a ~50-line legacy adapter that converts ArraySchemaType to Schema and delegates.

Changes:

  • New @portabletext/html package with htmlToPortableText(html, options?). Schema moves from positional arg into options. unstable_whitespaceOnPasteMode renamed to whitespace.
  • @portabletext/block-tools gutted to adapter: preserves htmlToBlocks signature, re-exports from html package.
  • Editor converters (converter.text-html.ts, converter.text-plain.ts) import from @portabletext/html directly.
  • HtmlDeserializer tests rewritten to use defineSchema/compileSchema from @portabletext/schema instead of Sanity schema fixtures.

@vercel
Copy link

vercel bot commented Feb 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
portable-text-editor-documentation Ready Ready Preview, Comment Feb 23, 2026 3:13pm
portable-text-example-basic Ready Ready Preview, Comment Feb 23, 2026 3:13pm
portable-text-playground Ready Ready Preview, Comment Feb 23, 2026 3:13pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 20, 2026

🦋 Changeset detected

Latest commit: 59a42e7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@portabletext/html Minor
@portabletext/block-tools Minor
@portabletext/editor Patch
@portabletext/plugin-character-pair-decorator Patch
@portabletext/plugin-emoji-picker Patch
@portabletext/plugin-input-rule Patch
@portabletext/plugin-markdown-shortcuts Patch
@portabletext/plugin-one-line Patch
@portabletext/plugin-paste-link Patch
@portabletext/plugin-sdk-value Patch
@portabletext/plugin-typeahead-picker Patch
@portabletext/plugin-typography Patch
@portabletext/toolbar Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Extract HTML-to-Portable Text conversion into a new @portabletext/html
package, mirroring the @portabletext/markdown API pattern.

New package (@portabletext/html):
- htmlToPortableText(html, options?) — schema in options, not positional
- Default schema via compileSchema(defineSchema({...}))
- whitespace option (renamed from unstable_whitespaceOnPasteMode)
- Zero @sanity/* dependencies
- All source code moved from block-tools (HtmlDeserializer, rules,
  preprocessors, normalizeBlock, etc.)
- All tests migrated: 134 tests across 22 test files

Legacy adapter (@portabletext/block-tools):
- Thin ~50-line adapter preserving htmlToBlocks(html, schema, options)
- Converts ArraySchemaType → Schema via sanity-bridge
- Maps unstable_whitespaceOnPasteMode → whitespace
- Re-exports everything from @portabletext/html
- 3 adapter tests (Schema, ArraySchemaType, whitespace passthrough)

Editor package:
- Converters import htmlToPortableText from @portabletext/html
- Uses snapshot.context.schema directly (no legacy schema traversal)
- Test imports updated
The HTML test fixtures moved from packages/block-tools/test/ to
packages/html/test/. The prettierignore entry needs to match the
new location.
The playground resolves workspace packages via Vite aliases to src/.
After extracting @portabletext/html, block-tools/rules re-exports from
@portabletext/html/rules. Add aliases for both the html package and
the block-tools/rules subpath so Vite can resolve them correctly.
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.

1 participant