@blocknote/core 0.25.2 → 0.27.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.
- package/dist/blocknote.cjs +11 -10
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +3722 -9856
- package/dist/blocknote.js.map +1 -1
- package/dist/comments.cjs +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +45 -44
- package/dist/comments.js.map +1 -1
- package/dist/en-B7ycW7c8.js +360 -0
- package/dist/en-B7ycW7c8.js.map +1 -0
- package/dist/en-D4taoCs4.cjs +2 -0
- package/dist/en-D4taoCs4.cjs.map +1 -0
- package/dist/locales.cjs +2 -0
- package/dist/locales.cjs.map +1 -0
- package/dist/locales.js +6129 -0
- package/dist/locales.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +36 -27
- package/src/api/clipboard/__snapshots__/internal/basicBlocks.html +1 -1
- package/src/api/clipboard/__snapshots__/internal/basicBlocksWithProps.html +1 -1
- package/src/api/clipboard/clipboardExternal.test.ts +1 -1
- package/src/api/clipboard/clipboardInternal.test.ts +1 -1
- package/src/api/clipboard/fromClipboard/acceptedMIMETypes.ts +1 -0
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +96 -42
- package/src/api/exporters/html/__snapshots__/codeBlock/contains-newlines/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/codeBlock/contains-newlines/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/codeBlock/defaultLanguage/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/codeBlock/defaultLanguage/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/codeBlock/empty/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/codeBlock/empty/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/codeBlock/python/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/codeBlock/python/internal.html +1 -1
- package/src/api/exporters/html/htmlConversion.test.ts +2 -2
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +4 -4
- package/src/api/exporters/markdown/__snapshots__/codeBlock/defaultLanguage/markdown.md +1 -1
- package/src/api/exporters/markdown/__snapshots__/codeBlock/empty/markdown.md +1 -1
- package/src/api/exporters/markdown/__snapshots__/complex/misc/markdown.md +1 -1
- package/src/api/exporters/markdown/__snapshots__/lists/basic/markdown.md +8 -6
- package/src/api/exporters/markdown/__snapshots__/lists/nested/markdown.md +6 -6
- package/src/api/exporters/markdown/markdownExporter.test.ts +2 -2
- package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +2 -2
- package/src/api/nodeConversions/nodeToBlock.ts +1 -0
- package/src/api/parsers/html/__snapshots__/parse-2-tables.json +129 -0
- package/src/api/parsers/html/__snapshots__/parse-codeblocks.json +1 -1
- package/src/api/parsers/html/parseHTML.test.ts +36 -1
- package/src/api/parsers/markdown/__snapshots__/pasted/whitespace bold.json +42 -0
- package/src/api/parsers/markdown/__snapshots__/whitespace bold.json +19 -0
- package/src/api/parsers/markdown/detectMarkdown.ts +60 -0
- package/src/api/parsers/markdown/parseMarkdown.test.ts +7 -2
- package/src/api/parsers/markdown/parseMarkdown.ts +19 -18
- package/src/api/testUtil/cases/defaultSchema.ts +13 -0
- package/src/blocks/CodeBlockContent/CodeBlockContent.ts +100 -69
- package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +98 -0
- package/src/blocks/TableBlockContent/TableExtension.ts +1 -1
- package/src/blocks/defaultBlocks.ts +2 -2
- package/src/comments/threadstore/yjs/YjsThreadStore.ts +1 -0
- package/src/comments/threadstore/yjs/yjsHelpers.ts +3 -1
- package/src/comments/types.ts +4 -0
- package/src/editor/Block.css +14 -1
- package/src/editor/BlockNoteEditor.ts +103 -11
- package/src/editor/BlockNoteExtensions.ts +18 -4
- package/src/editor/BlockNoteTipTapEditor.ts +18 -7
- package/src/extensions/Comments/CommentsPlugin.ts +77 -30
- package/src/extensions/HardBreak/HardBreak.ts +35 -0
- package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +100 -3
- package/src/extensions/SideMenu/dragging.ts +13 -0
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +3 -1
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +18 -2
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +24 -23
- package/src/i18n/index.ts +2 -0
- package/src/i18n/locales/ar.ts +10 -0
- package/src/i18n/locales/de.ts +21 -1
- package/src/i18n/locales/en.ts +10 -0
- package/src/i18n/locales/es.ts +21 -1
- package/src/i18n/locales/fr.ts +10 -0
- package/src/i18n/locales/hr.ts +27 -4
- package/src/i18n/locales/is.ts +10 -0
- package/src/i18n/locales/it.ts +21 -1
- package/src/i18n/locales/ja.ts +10 -0
- package/src/i18n/locales/ko.ts +10 -0
- package/src/i18n/locales/nl.ts +10 -0
- package/src/i18n/locales/no.ts +10 -0
- package/src/i18n/locales/pl.ts +10 -0
- package/src/i18n/locales/pt.ts +10 -0
- package/src/i18n/locales/ru.ts +10 -0
- package/src/i18n/locales/uk.ts +10 -0
- package/src/i18n/locales/vi.ts +10 -0
- package/src/i18n/locales/zh.ts +10 -0
- package/src/index.ts +2 -3
- package/src/locales.ts +1 -0
- package/src/schema/blocks/types.ts +1 -0
- package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.d.ts +1 -1
- package/types/src/api/blockManipulation/setupTestEnv.d.ts +34 -2
- package/types/src/api/clipboard/fromClipboard/acceptedMIMETypes.d.ts +1 -1
- package/types/src/api/clipboard/fromClipboard/fileDropExtension.d.ts +2 -2
- package/types/src/api/clipboard/fromClipboard/pasteExtension.d.ts +3 -3
- package/types/src/api/clipboard/testUtil.d.ts +66 -34
- package/types/src/api/clipboard/toClipboard/copyExtension.d.ts +1 -1
- package/types/src/api/exporters/html/externalHTMLExporter.d.ts +2 -2
- package/types/src/api/exporters/html/internalHTMLSerializer.d.ts +2 -2
- package/types/src/api/exporters/html/util/serializeBlocksExternalHTML.d.ts +1 -1
- package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +1 -1
- package/types/src/api/parsers/markdown/detectMarkdown.d.ts +6 -0
- package/types/src/api/parsers/markdown/parseMarkdown.d.ts +1 -0
- package/types/src/api/testUtil/cases/customBlocks.d.ts +72 -40
- package/types/src/api/testUtil/cases/customInlineContent.d.ts +34 -2
- package/types/src/api/testUtil/cases/customStyles.d.ts +34 -2
- package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +3 -3
- package/types/src/blocks/CodeBlockContent/CodeBlockContent.d.ts +46 -34
- package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +3 -3
- package/types/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.d.ts +1 -1
- package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +2 -2
- package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +2 -2
- package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +2 -2
- package/types/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.d.ts +2 -2
- package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +2 -2
- package/types/src/blocks/PageBreakBlockContent/PageBreakBlockContent.d.ts +2 -2
- package/types/src/blocks/PageBreakBlockContent/schema.d.ts +13 -13
- package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +2 -2
- package/types/src/blocks/QuoteBlockContent/QuoteBlockContent.d.ts +52 -0
- package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +2 -2
- package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +2 -2
- package/types/src/blocks/defaultBlockHelpers.d.ts +2 -2
- package/types/src/blocks/defaultBlocks.d.ts +107 -44
- package/types/src/comments/threadstore/yjs/YjsThreadStore.d.ts +3 -3
- package/types/src/comments/types.d.ts +4 -0
- package/types/src/editor/BlockNoteEditor.d.ts +58 -0
- package/types/src/editor/BlockNoteExtensions.d.ts +3 -2
- package/types/src/editor/BlockNoteTipTapEditor.d.ts +2 -1
- package/types/src/exporter/mapping.d.ts +2 -2
- package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +1 -1
- package/types/src/extensions/Collaboration/createCollaborationExtensions.d.ts +1 -1
- package/types/src/extensions/Comments/CommentsPlugin.d.ts +16 -1
- package/types/src/extensions/HardBreak/HardBreak.d.ts +2 -0
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +4 -4
- package/types/src/extensions/TextColor/TextColorMark.d.ts +1 -1
- package/types/src/i18n/index.d.ts +2 -0
- package/types/src/i18n/locales/de.d.ts +2 -304
- package/types/src/i18n/locales/en.d.ts +11 -1
- package/types/src/i18n/locales/es.d.ts +2 -269
- package/types/src/i18n/locales/hr.d.ts +2 -266
- package/types/src/i18n/locales/it.d.ts +2 -269
- package/types/src/index.d.ts +1 -2
- package/types/src/locales.d.ts +1 -0
- package/types/src/pm-nodes/BlockContainer.d.ts +2 -7
- package/types/src/pm-nodes/BlockGroup.d.ts +2 -7
- package/types/src/schema/blocks/types.d.ts +1 -0
- package/types/src/schema/inlineContent/internal.d.ts +1 -1
- package/README.md +0 -125
- package/src/blocks/CodeBlockContent/defaultSupportedLanguages.ts +0 -116
- package/types/src/blocks/CodeBlockContent/shiki.bundle.d.ts +0 -82
|
@@ -699,7 +699,7 @@ exports[`Test BlockNote-Prosemirror conversion > Case: default schema > Convert
|
|
|
699
699
|
"content": [
|
|
700
700
|
{
|
|
701
701
|
"attrs": {
|
|
702
|
-
"language": "
|
|
702
|
+
"language": "text",
|
|
703
703
|
},
|
|
704
704
|
"content": [
|
|
705
705
|
{
|
|
@@ -724,7 +724,7 @@ exports[`Test BlockNote-Prosemirror conversion > Case: default schema > Convert
|
|
|
724
724
|
"content": [
|
|
725
725
|
{
|
|
726
726
|
"attrs": {
|
|
727
|
-
"language": "
|
|
727
|
+
"language": "text",
|
|
728
728
|
},
|
|
729
729
|
"type": "codeBlock",
|
|
730
730
|
},
|
|
@@ -82,6 +82,7 @@ export function contentNodeToTableContent<
|
|
|
82
82
|
|
|
83
83
|
// Only merge if the last and first content are both styled text nodes and have the same styles
|
|
84
84
|
if (
|
|
85
|
+
first &&
|
|
85
86
|
isStyledTextInlineContent(last) &&
|
|
86
87
|
isStyledTextInlineContent(first) &&
|
|
87
88
|
JSON.stringify(last.styles) === JSON.stringify(first.styles)
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "1",
|
|
4
|
+
"type": "table",
|
|
5
|
+
"props": {
|
|
6
|
+
"textColor": "default"
|
|
7
|
+
},
|
|
8
|
+
"content": {
|
|
9
|
+
"type": "tableContent",
|
|
10
|
+
"columnWidths": [
|
|
11
|
+
null
|
|
12
|
+
],
|
|
13
|
+
"rows": [
|
|
14
|
+
{
|
|
15
|
+
"cells": [
|
|
16
|
+
{
|
|
17
|
+
"type": "tableCell",
|
|
18
|
+
"content": [
|
|
19
|
+
{
|
|
20
|
+
"type": "text",
|
|
21
|
+
"text": "Company",
|
|
22
|
+
"styles": {
|
|
23
|
+
"underline": true
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"props": {
|
|
28
|
+
"colspan": 1,
|
|
29
|
+
"rowspan": 1,
|
|
30
|
+
"backgroundColor": "default",
|
|
31
|
+
"textColor": "default",
|
|
32
|
+
"textAlignment": "left"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"cells": [
|
|
39
|
+
{
|
|
40
|
+
"type": "tableCell",
|
|
41
|
+
"content": [
|
|
42
|
+
{
|
|
43
|
+
"type": "text",
|
|
44
|
+
"text": "Example Company Inc.",
|
|
45
|
+
"styles": {
|
|
46
|
+
"bold": true
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"type": "text",
|
|
51
|
+
"text": "\n \nName: [Company Representative]\nTitle: Chief Executive Officer",
|
|
52
|
+
"styles": {}
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
"props": {
|
|
56
|
+
"colspan": 1,
|
|
57
|
+
"rowspan": 1,
|
|
58
|
+
"backgroundColor": "default",
|
|
59
|
+
"textColor": "default",
|
|
60
|
+
"textAlignment": "left"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
"children": []
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"id": "2",
|
|
71
|
+
"type": "table",
|
|
72
|
+
"props": {
|
|
73
|
+
"textColor": "default"
|
|
74
|
+
},
|
|
75
|
+
"content": {
|
|
76
|
+
"type": "tableContent",
|
|
77
|
+
"columnWidths": [
|
|
78
|
+
null
|
|
79
|
+
],
|
|
80
|
+
"rows": [
|
|
81
|
+
{
|
|
82
|
+
"cells": [
|
|
83
|
+
{
|
|
84
|
+
"type": "tableCell",
|
|
85
|
+
"content": [
|
|
86
|
+
{
|
|
87
|
+
"type": "text",
|
|
88
|
+
"text": "Advisor",
|
|
89
|
+
"styles": {
|
|
90
|
+
"underline": true
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
"props": {
|
|
95
|
+
"colspan": 1,
|
|
96
|
+
"rowspan": 1,
|
|
97
|
+
"backgroundColor": "default",
|
|
98
|
+
"textColor": "default",
|
|
99
|
+
"textAlignment": "left"
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"cells": [
|
|
106
|
+
{
|
|
107
|
+
"type": "tableCell",
|
|
108
|
+
"content": [
|
|
109
|
+
{
|
|
110
|
+
"type": "text",
|
|
111
|
+
"text": "[Advisor Name]",
|
|
112
|
+
"styles": {}
|
|
113
|
+
}
|
|
114
|
+
],
|
|
115
|
+
"props": {
|
|
116
|
+
"colspan": 1,
|
|
117
|
+
"rowspan": 1,
|
|
118
|
+
"backgroundColor": "default",
|
|
119
|
+
"textColor": "default",
|
|
120
|
+
"textAlignment": "left"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
},
|
|
127
|
+
"children": []
|
|
128
|
+
}
|
|
129
|
+
]
|
|
@@ -13,7 +13,7 @@ async function parseHTMLAndCompareSnapshots(
|
|
|
13
13
|
const blocks = await editor.tryParseHTMLToBlocks(html);
|
|
14
14
|
|
|
15
15
|
const snapshotPath = "./__snapshots__/" + snapshotName + ".json";
|
|
16
|
-
expect(JSON.stringify(blocks, undefined, 2)).toMatchFileSnapshot(
|
|
16
|
+
await expect(JSON.stringify(blocks, undefined, 2)).toMatchFileSnapshot(
|
|
17
17
|
snapshotPath
|
|
18
18
|
);
|
|
19
19
|
|
|
@@ -346,6 +346,41 @@ describe("Parse HTML", () => {
|
|
|
346
346
|
await parseHTMLAndCompareSnapshots(html, "parse-div-with-inline-content");
|
|
347
347
|
});
|
|
348
348
|
|
|
349
|
+
it("Parses 2 tables", async () => {
|
|
350
|
+
const html = `
|
|
351
|
+
<table style="border-collapse:collapse;margin-left:255.478pt" cellspacing="0">
|
|
352
|
+
<tr style="height:22pt">
|
|
353
|
+
<td style="width:203pt">
|
|
354
|
+
<p data-text-alignment="left" data-text-indent="0pt"><u>Company</u></p>
|
|
355
|
+
</td>
|
|
356
|
+
</tr>
|
|
357
|
+
<tr style="height:86pt">
|
|
358
|
+
<td style="width:203pt">
|
|
359
|
+
<p data-text-alignment="left" data-text-indent="0pt"><b>Example Company Inc.</b></p>
|
|
360
|
+
<p data-text-alignment="left" data-text-indent="0pt">
|
|
361
|
+
<p>Name: [Company Representative]</p>
|
|
362
|
+
</p>
|
|
363
|
+
<p data-text-alignment="left" data-text-indent="0pt">Title: Chief Executive Officer</p>
|
|
364
|
+
</td>
|
|
365
|
+
</tr>
|
|
366
|
+
</table>
|
|
367
|
+
|
|
368
|
+
<table style="border-collapse:collapse;margin-left:256.5pt" cellspacing="0">
|
|
369
|
+
<tr style="height:58pt">
|
|
370
|
+
<td style="width:209pt;border-bottom-style:solid;border-bottom-width:2pt">
|
|
371
|
+
<p data-text-alignment="left" data-text-indent="0pt"><u>Advisor</u></p>
|
|
372
|
+
</td>
|
|
373
|
+
</tr>
|
|
374
|
+
<tr style="height:13pt">
|
|
375
|
+
<td style="width:209pt;border-top-style:solid;border-top-width:2pt">
|
|
376
|
+
<p data-text-alignment="left" data-text-indent="0pt">[Advisor Name]</p>
|
|
377
|
+
</td>
|
|
378
|
+
</tr>
|
|
379
|
+
</table>`;
|
|
380
|
+
|
|
381
|
+
await parseHTMLAndCompareSnapshots(html, "parse-2-tables");
|
|
382
|
+
});
|
|
383
|
+
|
|
349
384
|
it("Parse Notion HTML", async () => {
|
|
350
385
|
// A few notes on Notion output HTML:
|
|
351
386
|
// - Does not preserve text/background colors
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "0",
|
|
4
|
+
"type": "paragraph",
|
|
5
|
+
"props": {
|
|
6
|
+
"textColor": "default",
|
|
7
|
+
"backgroundColor": "default",
|
|
8
|
+
"textAlignment": "left"
|
|
9
|
+
},
|
|
10
|
+
"content": [
|
|
11
|
+
{
|
|
12
|
+
"type": "text",
|
|
13
|
+
"text": "hello ",
|
|
14
|
+
"styles": {}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"type": "text",
|
|
18
|
+
"text": "beautiful ",
|
|
19
|
+
"styles": {
|
|
20
|
+
"bold": true
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"type": "text",
|
|
25
|
+
"text": " world",
|
|
26
|
+
"styles": {}
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"children": []
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"id": "2",
|
|
33
|
+
"type": "paragraph",
|
|
34
|
+
"props": {
|
|
35
|
+
"textColor": "default",
|
|
36
|
+
"backgroundColor": "default",
|
|
37
|
+
"textAlignment": "left"
|
|
38
|
+
},
|
|
39
|
+
"content": [],
|
|
40
|
+
"children": []
|
|
41
|
+
}
|
|
42
|
+
]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "1",
|
|
4
|
+
"type": "paragraph",
|
|
5
|
+
"props": {
|
|
6
|
+
"textColor": "default",
|
|
7
|
+
"backgroundColor": "default",
|
|
8
|
+
"textAlignment": "left"
|
|
9
|
+
},
|
|
10
|
+
"content": [
|
|
11
|
+
{
|
|
12
|
+
"type": "text",
|
|
13
|
+
"text": "hello **beautiful ** world",
|
|
14
|
+
"styles": {}
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"children": []
|
|
18
|
+
}
|
|
19
|
+
]
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Headings H1-H6.
|
|
2
|
+
const h1 = /(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/;
|
|
3
|
+
|
|
4
|
+
// Bold, italic, underline, strikethrough, highlight.
|
|
5
|
+
const bold = /(?:\s|^)(_|__|\*|\*\*|~~|==|\+\+)(?!\s).{1,64}(?<!\s)(?=\1)/;
|
|
6
|
+
|
|
7
|
+
// Basic inline link (also captures images).
|
|
8
|
+
const link = /\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/;
|
|
9
|
+
|
|
10
|
+
// Inline code.
|
|
11
|
+
const code = /(?:\s|^)`(?!\s)[^`]{1,48}(?<!\s)`([^\w]|$)/;
|
|
12
|
+
|
|
13
|
+
// Unordered list.
|
|
14
|
+
const ul = /(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/;
|
|
15
|
+
|
|
16
|
+
// Ordered list.
|
|
17
|
+
const ol = /(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/;
|
|
18
|
+
|
|
19
|
+
// Horizontal rule.
|
|
20
|
+
const hr = /\n{2} {0,3}-{2,48}\n{2}/;
|
|
21
|
+
|
|
22
|
+
// Fenced code block.
|
|
23
|
+
const fences =
|
|
24
|
+
/(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/;
|
|
25
|
+
|
|
26
|
+
// Classical underlined H1 and H2 headings.
|
|
27
|
+
const title = /(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/;
|
|
28
|
+
|
|
29
|
+
// Blockquote.
|
|
30
|
+
const blockquote =
|
|
31
|
+
/(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/;
|
|
32
|
+
|
|
33
|
+
// Table Header
|
|
34
|
+
const tableHeader = /^\s*\|(.+\|)+\s*$/m;
|
|
35
|
+
|
|
36
|
+
// Table Divider
|
|
37
|
+
const tableDivider = /^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m;
|
|
38
|
+
|
|
39
|
+
// Table Row
|
|
40
|
+
const tableRow = /^\s*\|(.+\|)+\s*$/m;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns `true` if the source text might be a markdown document.
|
|
44
|
+
*
|
|
45
|
+
* @param src Source text to analyze.
|
|
46
|
+
*/
|
|
47
|
+
export const isMarkdown = (src: string): boolean =>
|
|
48
|
+
h1.test(src) ||
|
|
49
|
+
bold.test(src) ||
|
|
50
|
+
link.test(src) ||
|
|
51
|
+
code.test(src) ||
|
|
52
|
+
ul.test(src) ||
|
|
53
|
+
ol.test(src) ||
|
|
54
|
+
hr.test(src) ||
|
|
55
|
+
fences.test(src) ||
|
|
56
|
+
title.test(src) ||
|
|
57
|
+
blockquote.test(src) ||
|
|
58
|
+
tableHeader.test(src) ||
|
|
59
|
+
tableDivider.test(src) ||
|
|
60
|
+
tableRow.test(src);
|
|
@@ -12,7 +12,7 @@ async function parseMarkdownAndCompareSnapshots(
|
|
|
12
12
|
const blocks = await editor.tryParseMarkdownToBlocks(md);
|
|
13
13
|
|
|
14
14
|
const snapshotPath = "./__snapshots__/" + snapshotName + ".json";
|
|
15
|
-
expect(JSON.stringify(blocks, undefined, 2)).toMatchFileSnapshot(
|
|
15
|
+
await expect(JSON.stringify(blocks, undefined, 2)).toMatchFileSnapshot(
|
|
16
16
|
snapshotPath
|
|
17
17
|
);
|
|
18
18
|
|
|
@@ -23,7 +23,7 @@ async function parseMarkdownAndCompareSnapshots(
|
|
|
23
23
|
doPaste(editor.prosemirrorView, md, null, true, new ClipboardEvent("paste"));
|
|
24
24
|
|
|
25
25
|
const pastedSnapshotPath = "./__snapshots__/pasted/" + snapshotName + ".json";
|
|
26
|
-
expect(JSON.stringify(editor.document, undefined, 2)).toMatchFileSnapshot(
|
|
26
|
+
await expect(JSON.stringify(editor.document, undefined, 2)).toMatchFileSnapshot(
|
|
27
27
|
pastedSnapshotPath
|
|
28
28
|
);
|
|
29
29
|
|
|
@@ -99,6 +99,11 @@ P*ara*~~grap~~h
|
|
|
99
99
|
* Bullet List Item`;
|
|
100
100
|
await parseMarkdownAndCompareSnapshots(markdown, "complex");
|
|
101
101
|
});
|
|
102
|
+
|
|
103
|
+
it("whitespace bold", async () => {
|
|
104
|
+
const markdown = `hello **beautiful ** world`;
|
|
105
|
+
await parseMarkdownAndCompareSnapshots(markdown, "whitespace bold");
|
|
106
|
+
});
|
|
102
107
|
});
|
|
103
108
|
|
|
104
109
|
describe("Issue 226", () => {
|
|
@@ -48,18 +48,9 @@ function code(state: any, node: any) {
|
|
|
48
48
|
return result;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
export async function
|
|
52
|
-
BSchema extends BlockSchema,
|
|
53
|
-
I extends InlineContentSchema,
|
|
54
|
-
S extends StyleSchema
|
|
55
|
-
>(
|
|
56
|
-
markdown: string,
|
|
57
|
-
blockSchema: BSchema,
|
|
58
|
-
icSchema: I,
|
|
59
|
-
styleSchema: S,
|
|
60
|
-
pmSchema: Schema
|
|
61
|
-
): Promise<Block<BSchema, I, S>[]> {
|
|
51
|
+
export async function markdownToHTML(markdown: string): Promise<string> {
|
|
62
52
|
const deps = await initializeESMDependencies();
|
|
53
|
+
|
|
63
54
|
const htmlString = deps.unified
|
|
64
55
|
.unified()
|
|
65
56
|
.use(deps.remarkParse.default)
|
|
@@ -73,11 +64,21 @@ export async function markdownToBlocks<
|
|
|
73
64
|
.use(deps.rehypeStringify.default)
|
|
74
65
|
.processSync(markdown);
|
|
75
66
|
|
|
76
|
-
return
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
67
|
+
return htmlString.value as string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function markdownToBlocks<
|
|
71
|
+
BSchema extends BlockSchema,
|
|
72
|
+
I extends InlineContentSchema,
|
|
73
|
+
S extends StyleSchema
|
|
74
|
+
>(
|
|
75
|
+
markdown: string,
|
|
76
|
+
blockSchema: BSchema,
|
|
77
|
+
icSchema: I,
|
|
78
|
+
styleSchema: S,
|
|
79
|
+
pmSchema: Schema
|
|
80
|
+
): Promise<Block<BSchema, I, S>[]> {
|
|
81
|
+
const htmlString = await markdownToHTML(markdown);
|
|
82
|
+
|
|
83
|
+
return HTMLToBlocks(htmlString, blockSchema, icSchema, styleSchema, pmSchema);
|
|
83
84
|
}
|
|
@@ -23,6 +23,18 @@ export const defaultSchemaTestCases: EditorTestCases<
|
|
|
23
23
|
return BlockNoteEditor.create({
|
|
24
24
|
schema: withPageBreak(BlockNoteSchema.create()),
|
|
25
25
|
uploadFile: uploadToTmpFilesDotOrg_DEV_ONLY,
|
|
26
|
+
codeBlock: {
|
|
27
|
+
supportedLanguages: {
|
|
28
|
+
javascript: {
|
|
29
|
+
name: "JavaScript",
|
|
30
|
+
aliases: ["js"],
|
|
31
|
+
},
|
|
32
|
+
python: {
|
|
33
|
+
name: "Python",
|
|
34
|
+
aliases: ["py"],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
26
38
|
});
|
|
27
39
|
},
|
|
28
40
|
documents: [
|
|
@@ -213,6 +225,7 @@ export const defaultSchemaTestCases: EditorTestCases<
|
|
|
213
225
|
blocks: [
|
|
214
226
|
{
|
|
215
227
|
type: "codeBlock",
|
|
228
|
+
props: { language: "javascript" },
|
|
216
229
|
content: "const hello = 'world';\nconsole.log(hello);\n",
|
|
217
230
|
},
|
|
218
231
|
],
|