Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(component): enable custom text rendering in PortableText #165

Merged
merged 3 commits into from
Nov 27, 2024

Conversation

theisel
Copy link
Owner

@theisel theisel commented Nov 27, 2024

Provides users with fine-grained control over text node output via the new text option.

// pages/some-page.astro
---
import { PortableText } from "astro-portabletext";
import TextReplace from '@/components/TextReplace.astro';
---

<PortableText value={/* Portable Text blocks */} components={{text: TextReplace}}/>
// TextReplace.astro
---
import type { TextNode, Props as $ } from "astro-portabletext/types";

export type Props = $<TextNode>;

const { node } = Astro.props;
const replacedText = node.text.replace('panda', '🐼');
---

{replacedText}

Provides users with fine-grained control over text node output via the new `text` option
- Consolidate fallback component handling
- Add safer default rendering with fallbacks
- Streamline type checking and style assignment
Fix text node rendering and add fallbacks for unknown components
@theisel theisel merged commit 80c147a into main Nov 27, 2024
2 checks passed
@theisel theisel deleted the feat--text-component branch November 27, 2024 03:38
@github-actions github-actions bot mentioned this pull request Nov 27, 2024
This was referenced Dec 18, 2024
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