Skip to content
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f128bb6
fix(richtext)!: HTML and Markdown parsing for links and edge cases
maoberlehner Nov 7, 2025
104c75f
Merge branch 'main' into bugfix/richtext-html-parser
alexjoverm Feb 9, 2026
b1048b3
fix(richtext): convert 6 needed nodes to underscode case
alexjoverm Feb 9, 2026
055c4b6
Merge branch 'main' into bugfix/richtext-html-parser
alexjoverm Feb 12, 2026
6fc767c
chore: upgrade playground
alexjoverm Feb 12, 2026
8994436
chore: refactor marks and nodes into a centralized extensions helpers
alexjoverm Feb 12, 2026
c5855b8
chore: revamp the Richtext renderer to use extensions instead of
alexjoverm Feb 12, 2026
fb1be37
test: add edge cases to HTML tests from the registered support issues
alexjoverm Feb 12, 2026
7c6a64a
chore: Update packages/richtext/src/extensions/nodes.ts
alexjoverm Feb 12, 2026
3a32d14
chore: Update packages/richtext/playground/vanilla/.env
alexjoverm Feb 12, 2026
28fc859
chore: revert ignore
alexjoverm Feb 12, 2026
34d6d86
feat: add tiptapExtensions for modern overrides
alexjoverm Feb 12, 2026
e7c0dce
feat: generate linear list of richtext content
dipankarmaikap Feb 18, 2026
7bd2283
Merge branch main' into bugfix/richtext-html-parser
alexjoverm Feb 23, 2026
98e0811
feat!: remove custom resolvers in favor of tiptap extensions
alexjoverm Feb 23, 2026
bdc2fcd
chore: update playgrounds
alexjoverm Feb 23, 2026
df697eb
chore(richtext): add extra tests to cover both-ways functionality
alexjoverm Feb 24, 2026
2ca560c
test(richtext): clean up and purge all unnecessary tests
alexjoverm Feb 24, 2026
74555c2
qs: apply bugbot fixes
alexjoverm Feb 24, 2026
cbf6784
qs: add name and type as context
alexjoverm Feb 24, 2026
47bfdf3
test: ensure the right nodes, marks and extensions are the ones to be
alexjoverm Feb 24, 2026
457ce44
fix: mailto duplication issue
alexjoverm Feb 24, 2026
5c6bdaa
chore: update lockfile
alexjoverm Feb 24, 2026
603133e
qs: fix null outputs, add globals exclusions
alexjoverm Feb 24, 2026
c1963b2
qs: fix textStyle node, fix playgrounds
alexjoverm Feb 24, 2026
a654352
qs: lint playgrounds
alexjoverm Feb 24, 2026
6b0bfad
qs: add thead/tbody support, fix _id issue
alexjoverm Feb 24, 2026
a5c1dec
qs: fix id issue
alexjoverm Feb 24, 2026
a4edafb
chore: normalize null/undefined values, clean up personal data in tests
alexjoverm Feb 25, 2026
109b338
fix: prevent empty values on href, add asTag for better typing
alexjoverm Feb 25, 2026
d97f3c9
chore: fix test:types race condition by run it after build
alexjoverm Feb 25, 2026
45388cd
chore: revert
alexjoverm Feb 25, 2026
63438e4
chore: astro richtext playground update
dipankarmaikap Feb 26, 2026
7e651a5
refactor(astro): drop experimental richTextToHTML
dipankarmaikap Feb 26, 2026
3e37dc7
Merge branch 'main' into bugfix/richtext-html-parser
alexjoverm Mar 2, 2026
9d0e62a
Merge branch 'main' into bugfix/richtext-html-parser
alexjoverm Mar 2, 2026
e961ced
chore(richtext): add js-client dep for types import
alexjoverm Mar 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"test": {
"dependsOn": ["build"]
},
"test:types": {
"dependsOn": ["build"]
},
"lint": {
"dependsOn": ["^build"],
"cache": true
Expand Down
37 changes: 14 additions & 23 deletions packages/astro/src/lib/richTextToHTML.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
ComponentBlok,
richTextResolver,
type StoryblokRichTextNode,
type StoryblokRichTextResolvers,
type StoryblokRichTextOptions,
} from '@storyblok/js';
import { experimental_AstroContainer } from 'astro/container';
import StoryblokComponent from '@storyblok/astro/StoryblokComponent.astro';
Expand All @@ -13,13 +14,13 @@ let container: null | experimental_AstroContainer = null;
* @experimental Converts a Storyblok RichText field into an HTML string.
*
* This API is still under development and may change in future releases.
* It also relies on Astros experimental
* It also relies on Astro's experimental
* [experimental_AstroContainer](https://docs.astro.build/en/reference/container-reference/) feature.
*
* @async
* @param {StoryblokRichTextNode} richTextField - The root RichText node to convert.
* @param {StoryblokRichTextResolvers} [customResolvers] - Optional custom resolvers
* for customizing how specific nodes or marks are transformed into HTML.
* @param {StoryblokRichTextOptions['tiptapExtensions']} [tiptapExtensions] - Optional custom
* tiptap extensions for customizing how specific nodes or marks are rendered.
* @returns {Promise<string>} A promise that resolves to the HTML string representation
* of the provided RichText content.
*
Expand All @@ -36,7 +37,7 @@ let container: null | experimental_AstroContainer = null;
*/
export const richTextToHTML = async (
richTextField: StoryblokRichTextNode,
customResolvers?: StoryblokRichTextResolvers,
tiptapExtensions?: StoryblokRichTextOptions['tiptapExtensions'],
): Promise<string> => {
// Create Astro container only once
if (!container) {
Expand All @@ -45,17 +46,11 @@ export const richTextToHTML = async (

// Collect async render results keyed by placeholder ID
const asyncReplacements: Promise<{ id: string; result: string }>[] = [];
// Build the resolvers object
const resolvers: StoryblokRichTextResolvers = {
// Handle async components
blok: (node) => {
const componentBody = node.attrs?.body;
if (!Array.isArray(componentBody)) {
return '';
}

return componentBody
.map((blok) => {
const resolver = richTextResolver<string>({
tiptapExtensions: {
blok: ComponentBlok.configure({
renderComponent: (blok: Record<string, unknown>, _id?: string) => {
if (!blok || typeof blok !== 'object' || !container) {
return '';
}
Expand All @@ -77,15 +72,11 @@ export const richTextToHTML = async (

asyncReplacements.push(promise);
return placeholder;
})
.join('\n');
},
}),
...tiptapExtensions,
},

// Add custom resolvers if provided
...customResolvers,
};

const resolver = richTextResolver({ resolvers });
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified file is dead code after export removal

Low Severity

richTextToHTML.ts was updated to use the new tiptap extension pattern, but the same PR removes it from viteStaticCopy targets and from the client.ts re-export, and drops its type declaration from public.d.ts. The file is now unreachable dead code that was modified unnecessarily. It either needs to be deleted or re-exported if still intended to be part of the public API.

Additional Locations (1)

Fix in Cursor Fix in Web

});

let html = resolver.render(richTextField);
// Wait for all async renders
Expand Down
9 changes: 4 additions & 5 deletions packages/astro/src/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ declare module '@storyblok/astro/client' {
import type {
StoryblokClient,
StoryblokRichTextNode,
StoryblokRichTextResolvers,
} from '@storyblok/astro';
/**
* @experimental Converts a Storyblok RichText field into an HTML string.
*
* This API is still under development and may change in future releases.
* It also relies on Astros experimental
* It also relies on Astro's experimental
* [experimental_AstroContainer](https://docs.astro.build/en/reference/container-reference/) feature.
*
* @async
* @param {StoryblokRichTextNode} richTextField - The root RichText node to convert.
* @param {StoryblokRichTextResolvers} [customResolvers] - Optional custom resolvers
* for customizing how specific nodes or marks are transformed into HTML.
* @param {Record<string, any>} [tiptapExtensions] - Optional custom tiptap extensions
* for customizing how specific nodes or marks are rendered.
* @returns {Promise<string>} A promise that resolves to the HTML string representation
* of the provided RichText content.
*
Expand All @@ -49,7 +48,7 @@ declare module '@storyblok/astro/client' {
*/
export function richTextToHTML(
richTextField: StoryblokRichTextNode,
customResolvers?: StoryblokRichTextResolvers
tiptapExtensions?: Record<string, any>
): Promise<string>;

/**
Expand Down
2 changes: 0 additions & 2 deletions packages/astro/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ export type {
StoryblokRichTextDocumentNode,
StoryblokRichTextImageOptimizationOptions,
StoryblokRichTextNode,
StoryblokRichTextNodeResolver,
StoryblokRichTextNodeTypes,
StoryblokRichTextOptions,
StoryblokRichTextResolvers,
TextTypes,
} from '@storyblok/js';
2 changes: 1 addition & 1 deletion packages/js/cypress/e2e/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('@storyblok/js', () => {
cy.get('@consoleError').should('not.be.called');
cy.get('#rich-text-container').should(
'have.html',
'<p></p><p>Hola<strong>in bold</strong></p><p><button href="hola@alvarosaburido.dev" target="null">hola@alvarosaburido.dev</button></p><span blok="[object Object]" id="undefined" style="display: none"></span><p></p><p>paragraph after empty line</p><p></p><ul><li><p>an item in a list</p></li><li><p>another item</p></li></ul><p></p><ol order="1"><li><p>item in another list</p></li><li><p>another item</p></li></ol><p></p><blockquote><p>this is a quote</p></blockquote><p></p><hr><p></p><p>some words after an &lt;hr&gt;</p><p></p><p><em>italic text</em></p><p></p><p><s>strikethrough</s></p><p></p><p><u>underlined</u></p><p></p><p><sup>superscript</sup></p><p></p><p><sub>subscript</sub></p><p></p><p><code>inline code</code> </p>',
'<p></p><p>Hola<strong>in bold</strong></p><p><button href="jane@example.com">jane@example.com</button></p><span data-blok="{&quot;component&quot;:&quot;custom_component&quot;,&quot;message&quot;:&quot;hey John&quot;}" style="display: none"></span><p></p><p>paragraph after empty line</p><p></p><ul><li><p>an item in a list</p></li><li><p>another item</p></li></ul><p></p><ol order="1"><li><p>item in another list</p></li><li><p>another item</p></li></ol><p></p><blockquote><p>this is a quote</p></blockquote><p></p><hr><p></p><p>some words after an &lt;hr&gt;</p><p></p><p><em>italic text</em></p><p></p><p><s>strikethrough</s></p><p></p><p><u>underlined</u></p><p></p><p><sup>superscript</sup></p><p></p><p><sub>subscript</sub></p><p></p><p><code>inline code</code> </p>',
);
});
});
Expand Down
16 changes: 10 additions & 6 deletions packages/js/playground/vanilla/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/* eslint-disable no-console */
import { Mark } from '@tiptap/core';
import type {
StoryblokRichTextNode,
StoryblokRichTextOptions,
} from '@storyblok/js';
import {
apiPlugin,
loadStoryblokBridge,
MarkTypes,
renderRichText,
storyblokInit,
useStoryblokBridge,
Expand Down Expand Up @@ -52,12 +51,17 @@ window.loadStoryblokBridgeScript = () => {
loadStoryblokBridge();
};

const CustomLink = Mark.create({
name: 'link',
renderHTML({ HTMLAttributes }: { HTMLAttributes: Record<string, string> }) {
return ['button', { href: HTMLAttributes.href, target: HTMLAttributes.target }, 0];
},
});

window.renderRichText = () => {
const options: StoryblokRichTextOptions = {
resolvers: {
[MarkTypes.LINK]: (node: StoryblokRichTextNode<string>) => {
return `<button href="${node.attrs?.href}" target="${node.attrs?.target}">${node.attrs?.href}</button>`;
},
tiptapExtensions: {
link: CustomLink,
},
};
const html = renderRichText(richTextFixture as any, options);
Expand Down
4 changes: 2 additions & 2 deletions packages/js/src/fixtures/richTextObject.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
"type": "paragraph",
"content": [
{
"text": "hola@alvarosaburido.dev",
"text": "jane@example.com",
"type": "text",
"marks": [
{
"type": "link",
"attrs": {
"href": "hola@alvarosaburido.dev",
"href": "jane@example.com",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was checking if example.com is safe to use - it is!

example.com (served at https://example.com/) is a reserved “example” domain that’s maintained by the Internet Assigned Numbers Authority (IANA) for documentation/testing examples, and it’s not available for public registration or transfer.

Nice!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, honestly it's a big coincidence hahahaha. Great to know!

"uuid": null,
"anchor": null,
"target": null,
Expand Down
33 changes: 14 additions & 19 deletions packages/js/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { loadBridge } from './bridge';

const renderMock = vi.fn(() => '<p>Rendered HTML</p>');
vi.mock('@storyblok/richtext', () => {
return {
richTextResolver: vi.fn(() => ({
render: renderMock,
})),
};
const { renderMock, richTextResolverMock } = vi.hoisted(() => {
const renderMock = vi.fn(() => '<p>Rendered HTML</p>');
const richTextResolverMock = vi.fn(() => ({ render: renderMock }));
return { renderMock, richTextResolverMock };
});
vi.mock('@storyblok/richtext', () => ({
richTextResolver: richTextResolverMock,
}));
describe('@storyblok/js', () => {
afterEach(() => {
vi.restoreAllMocks();
Expand Down Expand Up @@ -299,29 +299,24 @@ describe('@storyblok/js', () => {
vi.clearAllMocks();
});

it('should call richTextResolver with correct options', () => {
it('should call render with the provided data', () => {
const data = { type: 'doc', content: [] } as StoryblokRichTextNode<string>;
const options = {
resolvers: {
paragraph: () => '<p>test</p>',
},
};

renderRichText(data, options);
renderRichText(data);

expect(richTextResolverMock).toHaveBeenCalledWith(undefined);
expect(renderMock).toHaveBeenCalledWith(data);
});

it('calls render with the provided data', () => {
it('should forward tiptapExtensions to richTextResolver', () => {
const data = { type: 'doc', content: [] } as StoryblokRichTextNode<string>;
const options = {
resolvers: {
paragraph: () => '<p>test</p>',
},
tiptapExtensions: { link: { name: 'link' } },
};

renderRichText(data, options);
renderRichText(data, options as any);

expect(richTextResolverMock).toHaveBeenCalledWith(options);
expect(renderMock).toHaveBeenCalledWith(data);
});
});
Expand Down
5 changes: 3 additions & 2 deletions packages/js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,17 @@ export * from './types';

// New Richtext Resolver
export {
asTag,
BlockTypes,
ComponentBlok,
LinkTypes,
MarkTypes,
richTextResolver,
type StoryblokRichTextDocumentNode,
type StoryblokRichTextImageOptimizationOptions,
type StoryblokRichTextNode,
type StoryblokRichTextNodeResolver,
type StoryblokRichTextNodeTypes,
type StoryblokRichTextOptions,
type StoryblokRichTextResolvers,
TextTypes,
} from '@storyblok/richtext';

Expand Down
34 changes: 13 additions & 21 deletions packages/nuxt/playground/app/pages/richtext.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { NuxtLink } from '#components';
import { MarkTypes, type StoryblokRichTextNode } from '@storyblok/vue';
import { Mark } from '@tiptap/core';

const { story } = await useAsyncStoryblok('vue/test-richtext', {
api: {
Expand All @@ -9,33 +9,25 @@ const { story } = await useAsyncStoryblok('vue/test-richtext', {
bridge: {},
});

const resolvers = {
[MarkTypes.LINK]: (node: StoryblokRichTextNode<VNode>) => {
return node.attrs?.linktype === 'STORY'
? h(
NuxtLink,
{
to: node.attrs?.href,
target: node.attrs?.target,
},
node.text,
)
: h(
'a',
{
href: node.attrs?.href,
target: node.attrs?.target,
},
node.text,
);
const CustomLink = Mark.create({
name: 'link',
renderHTML({ HTMLAttributes }: { HTMLAttributes: Record<string, string> }) {
if (HTMLAttributes.linktype === 'story') {
return [asTag(NuxtLink), { to: HTMLAttributes.href }, 0];
}
return ['a', { href: HTMLAttributes.href, target: HTMLAttributes.target }, 0];
},
});

const tiptapExtensions = {
link: CustomLink,
};
</script>

<template>
<StoryblokRichText
v-if="story?.content.richText"
:doc="story.content.richText"
:resolvers="resolvers"
:tiptap-extensions="tiptapExtensions"
/>
</template>
55 changes: 55 additions & 0 deletions packages/nuxt/playground/app/storyblok/EmojiRandomizer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<script setup lang="ts">
import { ref } from 'vue';
import type { SbBlokData } from '@storyblok/vue';

interface EmojiRandomizerBlok extends SbBlokData {
label?: string;
}

interface Props {
blok: EmojiRandomizerBlok;
}

defineProps<Props>();

// List of fun emojis to randomly choose from
const emojis = ['😊', '🎉', '🚀', '✨', '🌈', '🎨', '🎸', '🎮', '🍕', '🌺'];

// Reactive state to track current emoji
const currentEmoji = ref<string>(
emojis[Math.floor(Math.random() * emojis.length)],
);

/**
* Generates a new random emoji different from the current one
*/
const randomizeEmoji = (): void => {
let newEmoji: string;
do {
newEmoji = emojis[Math.floor(Math.random() * emojis.length)];
} while (newEmoji === currentEmoji.value);

currentEmoji.value = newEmoji;
};
</script>

<template>
<div
v-editable="blok"
class="flex flex-col items-center gap-6 p-4 bg-gray-100 dark:bg-gray-900 rounded-lg"
data-test="emoji-randomizer"
>
<!-- Large emoji display -->
<div class="text-6xl">
{{ currentEmoji }}
</div>

<!-- Randomize button -->
<button
class="px-6 py-3 rounded-lg bg-blue-500 hover:bg-blue-600 active:bg-blue-700 text-white font-small transition-colors duration-200 dark:bg-blue-600 dark:hover:bg-blue-700 dark:active:bg-blue-800"
@click="randomizeEmoji"
>
{{ blok.label || 'Randomize Emoji' }}
</button>
</div>
</template>
6 changes: 3 additions & 3 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ export default defineNuxtModule<AllModuleOptions>({
'MarkTypes',
'BlockTypes',
'LinkTypes',
'AssetTypes',
'StoryblokRichTextResolvers',
'TextTypes',
'ComponentBlok',
'asTag',
'StoryblokRichTextDocumentNode',
'StoryblokRichTextImageOptimizationOptions',
'StoryblokRichTextNode',
'StoryblokRichTextNodeResolver',
'StoryblokRichTextNodeTypes',
'StoryblokRichTextOptions',
];
Expand Down
Loading
Loading