Skip to content

Commit

Permalink
Merge pull request #4485 from tinacms/nested-object-mdx-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDevAU committed May 1, 2024
2 parents e95dd99 + 598bb59 commit 322a201
Show file tree
Hide file tree
Showing 19 changed files with 452 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .changeset/old-bananas-walk.md
@@ -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.

@@ -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' }],
},
],
},
],
},
],
},
],
}
@@ -0,0 +1,13 @@
Hello

<Table rows={[
{
columns: [
{
content: {
description: "# Hello"
}
}
]
}
]} />
@@ -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))
})
@@ -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"
}
]
}
]
}
}
}
]
}
]
}
}
]
}
@@ -0,0 +1,3 @@
Hello

<Table rows={[{ columns: [{ content: { description: "# Hello\n" } }] }]} />
@@ -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: [] }],
},
],
},
],
},
],
},
],
}
@@ -0,0 +1,11 @@
Hello

<Table rows={[
{
columns: [
{
content: "# Hello <World />"
}
]
}
]} />
@@ -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))
})
@@ -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": {}
}
]
}
]
}
}
]
}
]
}
}
]
}
@@ -0,0 +1,3 @@
Hello

<Table rows={[{ columns: [{ content: "# Hello <World />\n" }] }]} />
@@ -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',
},
],
},
],
},
],
},
],
}
@@ -0,0 +1,11 @@
Hello

<Table rows={[
{
columns: [
{
content: "# Hello"
}
]
}
]} />
@@ -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))
})
@@ -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"
}
]
}
]
}
}
]
}
]
}
}
]
}
@@ -0,0 +1,3 @@
Hello

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

0 comments on commit 322a201

Please sign in to comment.