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

Fix issue with rich-text when nested in jsx objects #4485

Merged
merged 15 commits into from
May 1, 2024
6 changes: 6 additions & 0 deletions .changeset/old-bananas-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@tinacms/mdx": patch
tinacms: patch
---

Fix issue where rich-text nested inside JSX objects wasn't being parsed/stringified properly.
2 changes: 1 addition & 1 deletion experimental-examples/kitchen-sink/tina/tina-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { RichTextField } from '@tinacms/schema-tools'

export const field: RichTextField = {
name: 'body',
type: 'rich-text',
parser: { type: 'mdx' },
templates: [
{
name: 'Table',
fields: [
{
name: 'rows',
type: 'object',
list: true,
fields: [
{
name: 'columns',
type: 'object',
list: true,
fields: [
{
name: 'content',
type: 'object',
fields: [{ name: 'description', type: 'rich-text' }],
},
],
},
],
},
],
},
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Hello

<Table rows={[
{
columns: [
{
content: {
description: "# Hello"
}
}
]
}
]} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { it, expect } from 'vitest'
import { parseMDX } from '../../../parse'
import { stringifyMDX } from '../../../stringify'
import { field } from './field'
import input from './in.md?raw'
import * as util from '../util'

it('matches input', () => {
const tree = parseMDX(input, field, (v) => v)
expect(util.print(tree)).toMatchFile(util.nodePath(__dirname))
const string = stringifyMDX(tree, field, (v) => v)
expect(string).toMatchFile(util.mdPath(__dirname))
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"type": "root",
"children": [
{
"type": "p",
"children": [
{
"type": "text",
"text": "Hello"
}
]
},
{
"type": "mdxJsxFlowElement",
"name": "Table",
"children": [
{
"type": "text",
"text": ""
}
],
"props": {
"rows": [
{
"columns": [
{
"content": {
"description": {
"type": "root",
"children": [
{
"type": "h1",
"children": [
{
"type": "text",
"text": "Hello"
}
]
}
]
}
}
}
]
}
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Hello

<Table rows={[{ columns: [{ content: { description: "# Hello\n" } }] }]} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { RichTextField } from '@tinacms/schema-tools'

export const field: RichTextField = {
name: 'body',
type: 'rich-text',
parser: { type: 'mdx' },
templates: [
{
name: 'Table',
fields: [
{
name: 'rows',
type: 'object',
list: true,
fields: [
{
name: 'columns',
type: 'object',
list: true,
fields: [
{
name: 'content',
type: 'rich-text',
templates: [{ name: 'World', fields: [] }],
},
],
},
],
},
],
},
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Hello

<Table rows={[
{
columns: [
{
content: "# Hello <World />"
}
]
}
]} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { it, expect } from 'vitest'
import { parseMDX } from '../../../parse'
import { stringifyMDX } from '../../../stringify'
import { field } from './field'
import input from './in.md?raw'
import * as util from '../util'

it('matches input', () => {
const tree = parseMDX(input, field, (v) => v)
expect(util.print(tree)).toMatchFile(util.nodePath(__dirname))
const string = stringifyMDX(tree, field, (v) => v)
expect(string).toMatchFile(util.mdPath(__dirname))
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"type": "root",
"children": [
{
"type": "p",
"children": [
{
"type": "text",
"text": "Hello"
}
]
},
{
"type": "mdxJsxFlowElement",
"name": "Table",
"children": [
{
"type": "text",
"text": ""
}
],
"props": {
"rows": [
{
"columns": [
{
"content": {
"type": "root",
"children": [
{
"type": "h1",
"children": [
{
"type": "text",
"text": "Hello "
},
{
"type": "mdxJsxTextElement",
"name": "World",
"children": [
{
"type": "text",
"text": ""
}
],
"props": {}
}
]
}
]
}
}
]
}
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Hello

<Table rows={[{ columns: [{ content: "# Hello <World />\n" }] }]} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { RichTextField } from '@tinacms/schema-tools'

export const field: RichTextField = {
name: 'body',
type: 'rich-text',
parser: { type: 'mdx' },
templates: [
{
name: 'Table',
fields: [
{
name: 'rows',
type: 'object',
list: true,
fields: [
{
name: 'columns',
type: 'object',
list: true,
fields: [
{
name: 'content',
type: 'rich-text',
},
],
},
],
},
],
},
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Hello

<Table rows={[
{
columns: [
{
content: "# Hello"
}
]
}
]} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { it, expect } from 'vitest'
import { parseMDX } from '../../../parse'
import { stringifyMDX } from '../../../stringify'
import { field } from './field'
import input from './in.md?raw'
import * as util from '../util'

it('matches input', () => {
const tree = parseMDX(input, field, (v) => v)
expect(util.print(tree)).toMatchFile(util.nodePath(__dirname))
const string = stringifyMDX(tree, field, (v) => v)
expect(string).toMatchFile(util.mdPath(__dirname))
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"type": "root",
"children": [
{
"type": "p",
"children": [
{
"type": "text",
"text": "Hello"
}
]
},
{
"type": "mdxJsxFlowElement",
"name": "Table",
"children": [
{
"type": "text",
"text": ""
}
],
"props": {
"rows": [
{
"columns": [
{
"content": {
"type": "root",
"children": [
{
"type": "h1",
"children": [
{
"type": "text",
"text": "Hello"
}
]
}
]
}
}
]
}
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Hello

<Table rows={[{ columns: [{ content: "# Hello\n" }] }]} />