@portabletext/markdown 1.0.3 → 1.0.5
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.
- package/dist/index.d.ts +112 -107
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +8 -9
- package/src/default-schema.ts +0 -166
- package/src/example-document.md +0 -237
- package/src/example-document.out.md +0 -235
- package/src/example-document.terse-pt.json +0 -124
- package/src/example-document.test.ts +0 -87
- package/src/from-portable-text/build-list-index-map.ts +0 -133
- package/src/from-portable-text/portable-text-to-markdown.ts +0 -135
- package/src/from-portable-text/render-node.ts +0 -176
- package/src/from-portable-text/renderers/block-spacing.ts +0 -39
- package/src/from-portable-text/renderers/hard-break.ts +0 -4
- package/src/from-portable-text/renderers/list-item.ts +0 -32
- package/src/from-portable-text/renderers/marks.ts +0 -113
- package/src/from-portable-text/renderers/style.ts +0 -79
- package/src/from-portable-text/renderers/type.ts +0 -126
- package/src/from-portable-text/types.ts +0 -240
- package/src/index.ts +0 -51
- package/src/key-generator.ts +0 -32
- package/src/markdown-to-portable-text.test.ts +0 -3273
- package/src/portable-text-to-markdown.test.ts +0 -803
- package/src/to-portable-text/markdown-to-portable-text.ts +0 -1204
- package/src/to-portable-text/matchers.ts +0 -192
package/src/default-schema.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
compileSchema,
|
|
3
|
-
defineSchema,
|
|
4
|
-
type AnnotationDefinition,
|
|
5
|
-
type BlockObjectDefinition,
|
|
6
|
-
type DecoratorDefinition,
|
|
7
|
-
type ListDefinition,
|
|
8
|
-
type StyleDefinition,
|
|
9
|
-
} from '@portabletext/schema'
|
|
10
|
-
|
|
11
|
-
/********************
|
|
12
|
-
* Default style definitions
|
|
13
|
-
********************/
|
|
14
|
-
|
|
15
|
-
export const normalStyleDefinition = {
|
|
16
|
-
name: 'normal',
|
|
17
|
-
} as const satisfies StyleDefinition
|
|
18
|
-
|
|
19
|
-
export const h1StyleDefinition = {
|
|
20
|
-
name: 'h1',
|
|
21
|
-
} as const satisfies StyleDefinition
|
|
22
|
-
|
|
23
|
-
export const h2StyleDefinition = {
|
|
24
|
-
name: 'h2',
|
|
25
|
-
} as const satisfies StyleDefinition
|
|
26
|
-
|
|
27
|
-
export const h3StyleDefinition = {
|
|
28
|
-
name: 'h3',
|
|
29
|
-
} as const satisfies StyleDefinition
|
|
30
|
-
|
|
31
|
-
export const h4StyleDefinition = {
|
|
32
|
-
name: 'h4',
|
|
33
|
-
} as const satisfies StyleDefinition
|
|
34
|
-
|
|
35
|
-
export const h5StyleDefinition = {
|
|
36
|
-
name: 'h5',
|
|
37
|
-
} as const satisfies StyleDefinition
|
|
38
|
-
|
|
39
|
-
export const h6StyleDefinition = {
|
|
40
|
-
name: 'h6',
|
|
41
|
-
} as const satisfies StyleDefinition
|
|
42
|
-
|
|
43
|
-
export const blockquoteStyleDefinition = {
|
|
44
|
-
name: 'blockquote',
|
|
45
|
-
} as const satisfies StyleDefinition
|
|
46
|
-
|
|
47
|
-
/********************
|
|
48
|
-
* Default list definitions
|
|
49
|
-
********************/
|
|
50
|
-
|
|
51
|
-
export const defaultOrderedListItemDefinition = {
|
|
52
|
-
name: 'number',
|
|
53
|
-
} as const satisfies ListDefinition
|
|
54
|
-
|
|
55
|
-
export const defaultUnorderedListItemDefinition = {
|
|
56
|
-
name: 'bullet',
|
|
57
|
-
} as const satisfies ListDefinition
|
|
58
|
-
|
|
59
|
-
/********************
|
|
60
|
-
* Default decorator definitions
|
|
61
|
-
********************/
|
|
62
|
-
|
|
63
|
-
export const defaultStrongDecoratorDefinition = {
|
|
64
|
-
name: 'strong',
|
|
65
|
-
} as const satisfies DecoratorDefinition
|
|
66
|
-
|
|
67
|
-
export const defaultEmDecoratorDefinition = {
|
|
68
|
-
name: 'em',
|
|
69
|
-
} as const satisfies DecoratorDefinition
|
|
70
|
-
|
|
71
|
-
export const defaultCodeDecoratorDefinition = {
|
|
72
|
-
name: 'code',
|
|
73
|
-
} as const satisfies DecoratorDefinition
|
|
74
|
-
|
|
75
|
-
export const defaultStrikeThroughDecoratorDefinition = {
|
|
76
|
-
name: 'strike-through',
|
|
77
|
-
} as const satisfies DecoratorDefinition
|
|
78
|
-
|
|
79
|
-
/********************
|
|
80
|
-
* Default annotation definitions
|
|
81
|
-
********************/
|
|
82
|
-
|
|
83
|
-
export const defaultLinkObjectDefinition = {
|
|
84
|
-
name: 'link',
|
|
85
|
-
fields: [
|
|
86
|
-
{name: 'href', type: 'string'},
|
|
87
|
-
{name: 'title', type: 'string'},
|
|
88
|
-
],
|
|
89
|
-
} as const satisfies AnnotationDefinition
|
|
90
|
-
|
|
91
|
-
/********************
|
|
92
|
-
* Default object definitions
|
|
93
|
-
********************/
|
|
94
|
-
|
|
95
|
-
export const defaultCodeObjectDefinition = {
|
|
96
|
-
name: 'code',
|
|
97
|
-
fields: [
|
|
98
|
-
{name: 'language', type: 'string'},
|
|
99
|
-
{name: 'code', type: 'string'},
|
|
100
|
-
],
|
|
101
|
-
} as const satisfies BlockObjectDefinition
|
|
102
|
-
|
|
103
|
-
export const defaultImageObjectDefinition = {
|
|
104
|
-
name: 'image',
|
|
105
|
-
fields: [
|
|
106
|
-
{name: 'src', type: 'string'},
|
|
107
|
-
{name: 'alt', type: 'string'},
|
|
108
|
-
{name: 'title', type: 'string'},
|
|
109
|
-
],
|
|
110
|
-
} as const satisfies BlockObjectDefinition
|
|
111
|
-
|
|
112
|
-
export const defaultHorizontalRuleObjectDefinition = {
|
|
113
|
-
name: 'horizontal-rule',
|
|
114
|
-
} as const satisfies BlockObjectDefinition
|
|
115
|
-
|
|
116
|
-
export const defaultHtmlObjectDefinition = {
|
|
117
|
-
name: 'html',
|
|
118
|
-
fields: [{name: 'html', type: 'string'}],
|
|
119
|
-
} as const satisfies BlockObjectDefinition
|
|
120
|
-
|
|
121
|
-
export const defaultTableObjectDefinition = {
|
|
122
|
-
name: 'table',
|
|
123
|
-
fields: [
|
|
124
|
-
{name: 'headerRows', type: 'number'},
|
|
125
|
-
{name: 'rows', type: 'array'},
|
|
126
|
-
],
|
|
127
|
-
} as const satisfies BlockObjectDefinition
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* The default schema for converting markdown to Portable Text.
|
|
131
|
-
*
|
|
132
|
-
* @public
|
|
133
|
-
*/
|
|
134
|
-
export const defaultSchema = compileSchema(
|
|
135
|
-
defineSchema({
|
|
136
|
-
styles: [
|
|
137
|
-
normalStyleDefinition,
|
|
138
|
-
h1StyleDefinition,
|
|
139
|
-
h2StyleDefinition,
|
|
140
|
-
h3StyleDefinition,
|
|
141
|
-
h4StyleDefinition,
|
|
142
|
-
h5StyleDefinition,
|
|
143
|
-
h6StyleDefinition,
|
|
144
|
-
blockquoteStyleDefinition,
|
|
145
|
-
],
|
|
146
|
-
lists: [
|
|
147
|
-
defaultOrderedListItemDefinition,
|
|
148
|
-
defaultUnorderedListItemDefinition,
|
|
149
|
-
],
|
|
150
|
-
decorators: [
|
|
151
|
-
defaultStrongDecoratorDefinition,
|
|
152
|
-
defaultEmDecoratorDefinition,
|
|
153
|
-
defaultCodeDecoratorDefinition,
|
|
154
|
-
defaultStrikeThroughDecoratorDefinition,
|
|
155
|
-
],
|
|
156
|
-
annotations: [defaultLinkObjectDefinition],
|
|
157
|
-
blockObjects: [
|
|
158
|
-
defaultCodeObjectDefinition,
|
|
159
|
-
defaultHorizontalRuleObjectDefinition,
|
|
160
|
-
defaultImageObjectDefinition,
|
|
161
|
-
defaultHtmlObjectDefinition,
|
|
162
|
-
defaultTableObjectDefinition,
|
|
163
|
-
],
|
|
164
|
-
inlineObjects: [defaultImageObjectDefinition],
|
|
165
|
-
}),
|
|
166
|
-
)
|
package/src/example-document.md
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
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
|
-

|
|
30
|
-
|
|
31
|
-
Here's an inline image in text:  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  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 `&`, `<`, and `>` 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_
|
|
@@ -1,235 +0,0 @@
|
|
|
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
|
-

|
|
30
|
-
|
|
31
|
-
Here's an inline image in text:  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  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 `&`, `<`, and `>` 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_
|