Skip to content

Add Portable Text ↔ Markdown rule, fix legacy references#17

Closed
kmelve wants to merge 1 commit intomainfrom
add-pte-markdown-rule
Closed

Add Portable Text ↔ Markdown rule, fix legacy references#17
kmelve wants to merge 1 commit intomainfrom
add-pte-markdown-rule

Conversation

@kmelve
Copy link
Copy Markdown
Member

@kmelve kmelve commented Feb 12, 2026

What

Adds a new best practice rule for bidirectional Portable Text ↔ Markdown conversion using @portabletext/markdown, and fixes a legacy package reference in sanity-migration.mdc.

New rule: pte-to-markdown.md

Covers the full @portabletext/markdown v1.1.2 API:

  • portableTextToMarkdown with custom renderers (block, marks, types)
  • markdownToPortableText with schema-aware matchers
  • Built-in renderers: DefaultCodeBlockRenderer, DefaultImageRenderer, DefaultHorizontalRuleRenderer, DefaultTableRenderer
  • @portabletext/sanity-bridge for Sanity schema integration
  • Next.js route handler for AI-friendly markdown endpoints
  • Why this matters for AI agents and LLMs

Fix: sanity-migration.mdc

  • Replaces deprecated @sanity/block-content-to-markdown reference with @portabletext/markdown
  • Recommends markdownToPortableText for direct Markdown → PT conversion
  • Keeps HTML → PT path as alternative for complex cases

References

New rule: pte-to-markdown.md
- Bidirectional conversion with @portabletext/markdown v1.1.2
- portableTextToMarkdown with custom renderers (not serializers)
- markdownToPortableText with schema-aware matchers
- Built-in DefaultCodeBlockRenderer, DefaultImageRenderer, etc.
- @portabletext/sanity-bridge for Sanity schema integration
- Next.js route handler for AI-friendly markdown endpoints

Fix: sanity-migration.mdc
- Replace deprecated @sanity/block-content-to-markdown reference
- Recommend @portabletext/markdown for direct Markdown → PT conversion
- Keep HTML → PT path as alternative for complex cases

Based on:
- Package README: https://github.com/portabletext/editor/tree/main/packages/markdown
- Sanity Learn: https://www.sanity.io/learn/course/markdown-routes-with-nextjs
@kmelve
Copy link
Copy Markdown
Member Author

kmelve commented Feb 12, 2026

Closing in favor of #16 which is more comprehensive. Will fold the sanity-migration.mdc fix and API accuracy improvements into #16.

@kmelve kmelve closed this Feb 12, 2026
@kmelve kmelve deleted the add-pte-markdown-rule branch February 12, 2026 01:15
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