@portabletext/markdown 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,237 @@
1
+ # Markdown to Portable Text: A Complete Guide
2
+
3
+ Converting markdown to Portable Text is a **powerful** way to bridge the gap between _simple text formatting_ and **_structured content_**.
4
+
5
+ ## Why Portable Text?
6
+
7
+ Portable Text is a **specification** for _rich text_ that is:
8
+
9
+ - Platform **agnostic**
10
+ - **Structured** and _queryable_
11
+ - Designed for **_modern content workflows_**
12
+
13
+ Visit <https://portabletext.org> for more information, or check out the [official documentation](https://github.com/portabletext/portabletext 'Portable Text Spec').
14
+
15
+ ---
16
+
17
+ ## Supported Features
18
+
19
+ ### Text Formatting
20
+
21
+ You can use **bold text**, _italic text_, `inline code`, and even ~~strikethrough~~ text. The parser handles **_nested formatting_** gracefully, including **_bold and italic_** combined.
22
+
23
+ Here's some `code with **bold inside**` and **text with `code inside`** to test edge cases.
24
+
25
+ ### Links and Images
26
+
27
+ Reference-style links work too! Check out this [example link][ref1] that uses references defined elsewhere.
28
+
29
+ ![A beautiful diagram](https://example.com/diagram.png 'Markdown to PT Flow')
30
+
31
+ Here's an inline image in text: ![icon](https://example.com/icon.png) followed by more text.
32
+
33
+ ### Code Blocks
34
+
35
+ Fenced code blocks with syntax highlighting:
36
+
37
+ ```javascript
38
+ function markdownToPortableText(markdown) {
39
+ const tokens = parseMarkdown(markdown)
40
+ return transformToPortableText(tokens)
41
+ }
42
+ ```
43
+
44
+ Indented code blocks also work:
45
+
46
+ const simple = "code block";
47
+ console.log(simple);
48
+
49
+ ### Blockquotes
50
+
51
+ > Markdown is a lightweight markup language for creating formatted text.
52
+ >
53
+ > It was created by John Gruber in 2004.
54
+
55
+ Nested blockquotes are supported:
56
+
57
+ > This is the outer quote
58
+ >
59
+ > > And this is nested deeper
60
+ > >
61
+ > > With multiple paragraphs
62
+
63
+ ### Lists
64
+
65
+ #### Unordered Lists
66
+
67
+ - **Bold item** in a list
68
+ - _Italic item_ with [a link](https://example.com)
69
+ - Item with `inline code`
70
+ - Nested item one
71
+ - Nested item two
72
+ - Even deeper nesting
73
+ - Back to top level
74
+
75
+ #### Ordered Lists
76
+
77
+ 1. First step: Parse the markdown
78
+ 2. Second step: Generate tokens
79
+ 3. Third step: Transform to Portable Text
80
+ 1. Map block types
81
+ 2. Handle inline formatting
82
+ 3. Preserve structure
83
+
84
+ #### Mixed Lists
85
+
86
+ 1. Ordered parent
87
+ - Unordered child
88
+ - Another unordered
89
+ 1. Back to ordered
90
+ 2. Still ordered
91
+ 2. Continue ordered parent
92
+
93
+ ### Tables
94
+
95
+ Here's a comparison of different content formats:
96
+
97
+ | Format | Structured | Portable | Query-able |
98
+ | ----------------- | ---------- | -------- | ---------- |
99
+ | **Markdown** | ✗ | ✓ | ✗ |
100
+ | **HTML** | ~ | ✗ | ✗ |
101
+ | **Portable Text** | ✓ | ✓ | ✓ |
102
+ | Plain Text | ✗ | ✓ | ✗ |
103
+
104
+ Feature support matrix:
105
+
106
+ | Feature | Basic | Advanced | Notes |
107
+ | ---------- | ----- | -------- | ------------------- |
108
+ | Paragraphs | ✓ | ✓ | Full support |
109
+ | **Bold** | ✓ | ✓ | Including nested |
110
+ | _Italic_ | ✓ | ✓ | Works everywhere |
111
+ | `Code` | ✓ | ✓ | Inline and blocks |
112
+ | Links | ✓ | ✓ | All types supported |
113
+ | Images | ~ | ✓ | Block and inline |
114
+
115
+ ### Horizontal Rules
116
+
117
+ You can separate sections with horizontal rules:
118
+
119
+ ---
120
+
121
+ They create visual breaks in the content.
122
+
123
+ ---
124
+
125
+ ### All Heading Levels
126
+
127
+ # Heading 1
128
+
129
+ ## Heading 2
130
+
131
+ ### Heading 3
132
+
133
+ #### Heading 4
134
+
135
+ ##### Heading 5
136
+
137
+ ###### Heading 6
138
+
139
+ ## Advanced Examples
140
+
141
+ ### Overlapping Formatting
142
+
143
+ This paragraph contains **bold with _italic inside_** and _italic with **bold inside**_ to test proper nesting.
144
+
145
+ You can also have **bold with `code`** and _italic with `code`_ and even `code with **bold** and _italic_` (though the formatting inside code should be preserved as-is).
146
+
147
+ ### Links with Formatting
148
+
149
+ Here's a [**bold link**](https://example.com) and an [_italic link_](https://example.com) and even a [`code link`](https://example.com).
150
+
151
+ ### Complex List Items
152
+
153
+ - Item with **bold**, _italic_, and `code`
154
+ - Item with a [link to **bold** content](https://example.com 'Link Title')
155
+ - Item with an inline image ![small icon](https://example.com/icon.png) in the middle
156
+ - Nested **bold item** with _italic_ and `code`
157
+ - Another nested item
158
+
159
+ ### Line Breaks
160
+
161
+ This is a line with a hard break
162
+ that continues on the next line but stays in the same paragraph.
163
+
164
+ Another paragraph with a break
165
+ and more content.
166
+
167
+ ### Autolinks
168
+
169
+ Check out these autolinks: <https://example.com> and <mailto:hello@example.com> for quick linking.
170
+
171
+ ### HTML Passthrough
172
+
173
+ <div class="custom-block">
174
+ <p>This is raw HTML that gets preserved</p>
175
+ </div>
176
+
177
+ Inline HTML like <span class="highlight">highlighted text</span> can be handled too.
178
+
179
+ ### Reference Links
180
+
181
+ This is [reference link one][ref1] and this is [reference link two][ref2].
182
+
183
+ You can also use [implicit references] by just using the text as the reference.
184
+
185
+ [ref1]: https://portabletext.org 'Portable Text Homepage'
186
+ [ref2]: https://github.com/portabletext/editor 'Portable Text Editor'
187
+ [implicit references]: https://example.com 'Implicit Reference Example'
188
+
189
+ ## Implementation Notes
190
+
191
+ The transformation process involves several key steps:
192
+
193
+ 1. **Lexical Analysis**: Parse markdown into tokens
194
+ 2. **Syntax Tree Building**: Construct an AST from tokens
195
+ 3. **Transformation**: Map markdown AST to Portable Text structure
196
+ 4. **Validation**: Ensure output conforms to schema
197
+
198
+ ### Edge Cases
199
+
200
+ #### Empty Blocks
201
+
202
+ Sometimes you have empty paragraphs:
203
+
204
+ Or consecutive horizontal rules:
205
+
206
+ ---
207
+
208
+ ---
209
+
210
+ #### Special Characters
211
+
212
+ Text with special characters like `&amp;`, `&lt;`, and `&gt;` should be handled correctly.
213
+
214
+ #### URLs in Text
215
+
216
+ Raw URLs like https://example.com (without angle brackets) may or may not become links depending on the parser configuration.
217
+
218
+ ## Conclusion
219
+
220
+ This document demonstrates the **comprehensive** support for _markdown features_ in the `markdown-to-portable-text` converter. With proper handling of:
221
+
222
+ - All basic formatting
223
+ - Complex nesting
224
+ - Various link types
225
+ - Images (block and inline)
226
+ - Code blocks
227
+ - Lists of all types
228
+ - Tables
229
+ - And much more!
230
+
231
+ The result is **_robust, reliable_** content transformation that preserves both structure and semantics.
232
+
233
+ ---
234
+
235
+ **Happy converting!** 🎉
236
+
237
+ _Last updated: 2025_
@@ -0,0 +1,235 @@
1
+ # Markdown to Portable Text: A Complete Guide
2
+
3
+ Converting markdown to Portable Text is a **powerful** way to bridge the gap between _simple text formatting_ and **_structured content_**.
4
+
5
+ ## Why Portable Text?
6
+
7
+ Portable Text is a **specification** for _rich text_ that is:
8
+
9
+ - Platform **agnostic**
10
+ - **Structured** and _queryable_
11
+ - Designed for **_modern content workflows_**
12
+
13
+ Visit [https://portabletext.org](https://portabletext.org) for more information, or check out the [official documentation](https://github.com/portabletext/portabletext "Portable Text Spec").
14
+
15
+ ---
16
+
17
+ ## Supported Features
18
+
19
+ ### Text Formatting
20
+
21
+ You can use **bold text**, _italic text_, `inline code`, and even ~~strikethrough~~ text. The parser handles **_nested formatting_** gracefully, including **_bold and italic_** combined.
22
+
23
+ Here's some `code with **bold inside**` and **text with `code inside`** to test edge cases.
24
+
25
+ ### Links and Images
26
+
27
+ Reference-style links work too! Check out this [example link](https://portabletext.org "Portable Text Homepage") that uses references defined elsewhere.
28
+
29
+ ![A beautiful diagram](https://example.com/diagram.png "Markdown to PT Flow")
30
+
31
+ Here's an inline image in text: ![icon](https://example.com/icon.png) followed by more text.
32
+
33
+ ### Code Blocks
34
+
35
+ Fenced code blocks with syntax highlighting:
36
+
37
+ ```javascript
38
+ function markdownToPortableText(markdown) {
39
+ const tokens = parseMarkdown(markdown)
40
+ return transformToPortableText(tokens)
41
+ }
42
+ ```
43
+
44
+ Indented code blocks also work:
45
+
46
+ ```
47
+ const simple = "code block";
48
+ console.log(simple);
49
+ ```
50
+
51
+ ### Blockquotes
52
+
53
+ > Markdown is a lightweight markup language for creating formatted text.
54
+ >
55
+ > It was created by John Gruber in 2004.
56
+
57
+ Nested blockquotes are supported:
58
+
59
+ > This is the outer quote
60
+ >
61
+ > And this is nested deeper
62
+ >
63
+ > With multiple paragraphs
64
+
65
+ ### Lists
66
+
67
+ #### Unordered Lists
68
+
69
+ - **Bold item** in a list
70
+ - _Italic item_ with [a link](https://example.com)
71
+ - Item with `inline code`
72
+ - Nested item one
73
+ - Nested item two
74
+ - Even deeper nesting
75
+ - Back to top level
76
+
77
+ #### Ordered Lists
78
+
79
+ 1. First step: Parse the markdown
80
+ 2. Second step: Generate tokens
81
+ 3. Third step: Transform to Portable Text
82
+ 1. Map block types
83
+ 2. Handle inline formatting
84
+ 3. Preserve structure
85
+
86
+ #### Mixed Lists
87
+
88
+ 1. Ordered parent
89
+ - Unordered child
90
+ - Another unordered
91
+ 1. Back to ordered
92
+ 2. Still ordered
93
+ 2. Continue ordered parent
94
+
95
+ ### Tables
96
+
97
+ Here's a comparison of different content formats:
98
+
99
+ | Format | Structured | Portable | Query-able |
100
+ | --- | --- | --- | --- |
101
+ | **Markdown** | ✗ | ✓ | ✗ |
102
+ | **HTML** | ~ | ✗ | ✗ |
103
+ | **Portable Text** | ✓ | ✓ | ✓ |
104
+ | Plain Text | ✗ | ✓ | ✗ |
105
+
106
+ Feature support matrix:
107
+
108
+ | Feature | Basic | Advanced | Notes |
109
+ | --- | --- | --- | --- |
110
+ | Paragraphs | ✓ | ✓ | Full support |
111
+ | **Bold** | ✓ | ✓ | Including nested |
112
+ | _Italic_ | ✓ | ✓ | Works everywhere |
113
+ | `Code` | ✓ | ✓ | Inline and blocks |
114
+ | Links | ✓ | ✓ | All types supported |
115
+ | Images | ~ | ✓ | Block and inline |
116
+
117
+ ### Horizontal Rules
118
+
119
+ You can separate sections with horizontal rules:
120
+
121
+ ---
122
+
123
+ They create visual breaks in the content.
124
+
125
+ ---
126
+
127
+ ### All Heading Levels
128
+
129
+ # Heading 1
130
+
131
+ ## Heading 2
132
+
133
+ ### Heading 3
134
+
135
+ #### Heading 4
136
+
137
+ ##### Heading 5
138
+
139
+ ###### Heading 6
140
+
141
+ ## Advanced Examples
142
+
143
+ ### Overlapping Formatting
144
+
145
+ This paragraph contains **bold with _italic inside_** and _italic with **bold inside**_ to test proper nesting.
146
+
147
+ You can also have **bold with `code`** and _italic with `code`_ and even `code with **bold** and _italic_` (though the formatting inside code should be preserved as-is).
148
+
149
+ ### Links with Formatting
150
+
151
+ Here's a [**bold link**](https://example.com) and an [_italic link_](https://example.com) and even a [`code link`](https://example.com).
152
+
153
+ ### Complex List Items
154
+
155
+ - Item with **bold**, _italic_, and `code`
156
+ - Item with a [link to **bold** content](https://example.com "Link Title")
157
+ - Item with an inline image ![small icon](https://example.com/icon.png) in the middle
158
+ - Nested **bold item** with _italic_ and `code`
159
+ - Another nested item
160
+
161
+ ### Line Breaks
162
+
163
+ This is a line with a hard break
164
+ that continues on the next line but stays in the same paragraph.
165
+
166
+ Another paragraph with a break
167
+ and more content.
168
+
169
+ ### Autolinks
170
+
171
+ Check out these autolinks: [https://example.com](https://example.com) and [mailto:hello@example.com](mailto:hello@example.com) for quick linking.
172
+
173
+ ### HTML Passthrough
174
+
175
+ <div class="custom-block">
176
+ <p>This is raw HTML that gets preserved</p>
177
+ </div>
178
+
179
+ Inline HTML like <span class="highlight">highlighted text</span> can be handled too.
180
+
181
+ ### Reference Links
182
+
183
+ This is [reference link one](https://portabletext.org "Portable Text Homepage") and this is [reference link two](https://github.com/portabletext/editor "Portable Text Editor").
184
+
185
+ You can also use [implicit references](https://example.com "Implicit Reference Example") by just using the text as the reference.
186
+
187
+ ## Implementation Notes
188
+
189
+ The transformation process involves several key steps:
190
+
191
+ 1. **Lexical Analysis**: Parse markdown into tokens
192
+ 2. **Syntax Tree Building**: Construct an AST from tokens
193
+ 3. **Transformation**: Map markdown AST to Portable Text structure
194
+ 4. **Validation**: Ensure output conforms to schema
195
+
196
+ ### Edge Cases
197
+
198
+ #### Empty Blocks
199
+
200
+ Sometimes you have empty paragraphs:
201
+
202
+ Or consecutive horizontal rules:
203
+
204
+ ---
205
+
206
+ ---
207
+
208
+ #### Special Characters
209
+
210
+ Text with special characters like `&amp;`, `&lt;`, and `&gt;` should be handled correctly.
211
+
212
+ #### URLs in Text
213
+
214
+ Raw URLs like [https://example.com](https://example.com) (without angle brackets) may or may not become links depending on the parser configuration.
215
+
216
+ ## Conclusion
217
+
218
+ This document demonstrates the **comprehensive** support for _markdown features_ in the `markdown-to-portable-text` converter. With proper handling of:
219
+
220
+ - All basic formatting
221
+ - Complex nesting
222
+ - Various link types
223
+ - Images (block and inline)
224
+ - Code blocks
225
+ - Lists of all types
226
+ - Tables
227
+ - And much more!
228
+
229
+ The result is **_robust, reliable_** content transformation that preserves both structure and semantics.
230
+
231
+ ---
232
+
233
+ **Happy converting!** 🎉
234
+
235
+ _Last updated: 2025_
@@ -0,0 +1,124 @@
1
+ [
2
+ "h1:Markdown to Portable Text: A Complete Guide",
3
+ "Converting markdown to Portable Text is a ,powerful, way to bridge the gap between ,simple text formatting, and ,structured content,.",
4
+ "h2:Why Portable Text?",
5
+ "Portable Text is a ,specification, for ,rich text, that is:",
6
+ ">-:Platform ,agnostic",
7
+ ">-:Structured, and ,queryable",
8
+ ">-:Designed for ,modern content workflows",
9
+ "Visit ,https://portabletext.org, for more information, or check out the ,official documentation,.",
10
+ "{horizontal-rule}",
11
+ "h2:Supported Features",
12
+ "h3:Text Formatting",
13
+ "You can use ,bold text,, ,italic text,, ,inline code,, and even ,strikethrough, text. The parser handles ,nested formatting, gracefully, including ,bold and italic, combined.",
14
+ "Here's some ,code with **bold inside**, and ,text with ,code inside, to test edge cases.",
15
+ "h3:Links and Images",
16
+ "Reference-style links work too! Check out this ,example link, that uses references defined elsewhere.",
17
+ "{image}",
18
+ "Here's an inline image in text: ,{image}, followed by more text.",
19
+ "h3:Code Blocks",
20
+ "Fenced code blocks with syntax highlighting:",
21
+ "{code}",
22
+ "Indented code blocks also work:",
23
+ "{code}",
24
+ "h3:Blockquotes",
25
+ "q:Markdown is a lightweight markup language for creating formatted text.",
26
+ "q:It was created by John Gruber in 2004.",
27
+ "Nested blockquotes are supported:",
28
+ "q:This is the outer quote",
29
+ "q:And this is nested deeper",
30
+ "q:With multiple paragraphs",
31
+ "h3:Lists",
32
+ "h4:Unordered Lists",
33
+ ">-:Bold item, in a list",
34
+ ">-:Italic item, with ,a link",
35
+ ">-:Item with ,inline code",
36
+ ">>-:Nested item one",
37
+ ">>-:Nested item two",
38
+ ">>>-:Even deeper nesting",
39
+ ">-:Back to top level",
40
+ "h4:Ordered Lists",
41
+ ">#:First step: Parse the markdown",
42
+ ">#:Second step: Generate tokens",
43
+ ">#:Third step: Transform to Portable Text",
44
+ ">>#:Map block types",
45
+ ">>#:Handle inline formatting",
46
+ ">>#:Preserve structure",
47
+ "h4:Mixed Lists",
48
+ ">#:Ordered parent",
49
+ ">>-:Unordered child",
50
+ ">>-:Another unordered",
51
+ ">>>#:Back to ordered",
52
+ ">>>#:Still ordered",
53
+ ">#:Continue ordered parent",
54
+ "h3:Tables",
55
+ "Here's a comparison of different content formats:",
56
+ "{table}",
57
+ "Feature support matrix:",
58
+ "{table}",
59
+ "h3:Horizontal Rules",
60
+ "You can separate sections with horizontal rules:",
61
+ "{horizontal-rule}",
62
+ "They create visual breaks in the content.",
63
+ "{horizontal-rule}",
64
+ "h3:All Heading Levels",
65
+ "h1:Heading 1",
66
+ "h2:Heading 2",
67
+ "h3:Heading 3",
68
+ "h4:Heading 4",
69
+ "h5:Heading 5",
70
+ "h6:Heading 6",
71
+ "h2:Advanced Examples",
72
+ "h3:Overlapping Formatting",
73
+ "This paragraph contains ,bold with ,italic inside, and ,italic with ,bold inside, to test proper nesting.",
74
+ "You can also have ,bold with ,code, and ,italic with ,code, and even ,code with **bold** and _italic_, (though the formatting inside code should be preserved as-is).",
75
+ "h3:Links with Formatting",
76
+ "Here's a ,bold link, and an ,italic link, and even a ,code link,.",
77
+ "h3:Complex List Items",
78
+ ">-:Item with ,bold,, ,italic,, and ,code",
79
+ ">-:Item with a ,link to ,bold, content",
80
+ ">-:Item with an inline image ,{image}, in the middle",
81
+ ">>-:Nested ,bold item, with ,italic, and ,code",
82
+ ">>-:Another nested item",
83
+ "h3:Line Breaks",
84
+ "This is a line with a hard break\nthat continues on the next line but stays in the same paragraph.",
85
+ "Another paragraph with a break\nand more content.",
86
+ "h3:Autolinks",
87
+ "Check out these autolinks: ,https://example.com, and ,mailto:hello@example.com, for quick linking.",
88
+ "h3:HTML Passthrough",
89
+ "{html}",
90
+ "Inline HTML like highlighted text can be handled too.",
91
+ "h3:Reference Links",
92
+ "This is ,reference link one, and this is ,reference link two,.",
93
+ "You can also use ,implicit references, by just using the text as the reference.",
94
+ "h2:Implementation Notes",
95
+ "The transformation process involves several key steps:",
96
+ ">#:Lexical Analysis,: Parse markdown into tokens",
97
+ ">#:Syntax Tree Building,: Construct an AST from tokens",
98
+ ">#:Transformation,: Map markdown AST to Portable Text structure",
99
+ ">#:Validation,: Ensure output conforms to schema",
100
+ "h3:Edge Cases",
101
+ "h4:Empty Blocks",
102
+ "Sometimes you have empty paragraphs:",
103
+ "Or consecutive horizontal rules:",
104
+ "{horizontal-rule}",
105
+ "{horizontal-rule}",
106
+ "h4:Special Characters",
107
+ "Text with special characters like ,&amp;,, ,&lt;,, and ,&gt;, should be handled correctly.",
108
+ "h4:URLs in Text",
109
+ "Raw URLs like ,https://example.com, (without angle brackets) may or may not become links depending on the parser configuration.",
110
+ "h2:Conclusion",
111
+ "This document demonstrates the ,comprehensive, support for ,markdown features, in the ,markdown-to-portable-text, converter. With proper handling of:",
112
+ ">-:All basic formatting",
113
+ ">-:Complex nesting",
114
+ ">-:Various link types",
115
+ ">-:Images (block and inline)",
116
+ ">-:Code blocks",
117
+ ">-:Lists of all types",
118
+ ">-:Tables",
119
+ ">-:And much more!",
120
+ "The result is ,robust, reliable, content transformation that preserves both structure and semantics.",
121
+ "{horizontal-rule}",
122
+ "Happy converting!, 🎉",
123
+ "Last updated: 2025"
124
+ ]
@@ -0,0 +1,87 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import type {BlockObjectDefinition} from '@portabletext/schema'
4
+ import {createTestKeyGenerator, getTersePt} from '@portabletext/test'
5
+ import {describe, expect, test} from 'vitest'
6
+ import {defaultSchema} from './default-schema'
7
+ import {portableTextToMarkdown} from './from-portable-text/portable-text-to-markdown'
8
+ import {
9
+ DefaultCodeBlockRenderer,
10
+ DefaultTableRenderer,
11
+ } from './from-portable-text/renderers/type'
12
+ import {markdownToPortableText} from './to-portable-text/markdown-to-portable-text'
13
+ import {buildObjectMatcher} from './to-portable-text/matchers'
14
+
15
+ const exampleDocumentMarkdown = fs.readFileSync(
16
+ path.resolve(__dirname, 'example-document.md'),
17
+ 'utf-8',
18
+ )
19
+ const exampleDocumentMarkdownOut = fs
20
+ .readFileSync(path.resolve(__dirname, 'example-document.out.md'), 'utf-8')
21
+ // Account for hard break spaces that may be stripped by editors/tools
22
+ .replace('hard break\nthat continues', 'hard break \nthat continues')
23
+ .replace('with a break\nand more', 'with a break \nand more')
24
+ const exampleDocumentTersePt = JSON.parse(
25
+ fs.readFileSync(
26
+ path.resolve(__dirname, 'example-document.terse-pt.json'),
27
+ 'utf-8',
28
+ ),
29
+ )
30
+
31
+ const tableObjectDefinition = {
32
+ name: 'table',
33
+ fields: [
34
+ {name: 'headerRows', type: 'number'},
35
+ {name: 'rows', type: 'array'},
36
+ ],
37
+ } as const satisfies BlockObjectDefinition
38
+
39
+ const tableObjectMatcher = buildObjectMatcher(tableObjectDefinition)
40
+
41
+ describe('example document', () => {
42
+ test('markdown to portable text', () => {
43
+ const keyGenerator = createTestKeyGenerator()
44
+ const blocks = markdownToPortableText(exampleDocumentMarkdown, {
45
+ keyGenerator,
46
+ schema: {
47
+ ...defaultSchema,
48
+ blockObjects: [...defaultSchema.blockObjects, tableObjectDefinition],
49
+ },
50
+ types: {
51
+ table: tableObjectMatcher,
52
+ },
53
+ })
54
+ const tersePt = getTersePt({schema: defaultSchema, value: blocks})
55
+
56
+ expect(tersePt).toEqual(exampleDocumentTersePt)
57
+ })
58
+
59
+ test('portable text to markdown', () => {
60
+ const keyGenerator = createTestKeyGenerator()
61
+ const blocks = markdownToPortableText(exampleDocumentMarkdown, {
62
+ keyGenerator,
63
+ schema: {
64
+ ...defaultSchema,
65
+ blockObjects: [...defaultSchema.blockObjects, tableObjectDefinition],
66
+ },
67
+ types: {
68
+ table: tableObjectMatcher,
69
+ },
70
+ html: {
71
+ inline: 'text',
72
+ },
73
+ })
74
+ const markdown = portableTextToMarkdown(blocks, {
75
+ types: {
76
+ 'horizontal-rule': () => '---',
77
+ 'table': DefaultTableRenderer,
78
+ 'code': DefaultCodeBlockRenderer,
79
+ 'html': ({value}) => value.html || '',
80
+ 'image': ({value}) =>
81
+ `![${value.alt}](${value.src}${value.title ? ` "${value.title}"` : ''})`,
82
+ },
83
+ })
84
+
85
+ expect(`${markdown}\n`).toBe(exampleDocumentMarkdownOut)
86
+ })
87
+ })