-
-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Code block * fix: Export code block from core * feat: Customize code block util * feat: Code block fixes, improvements & tests * fix: Update snapshots * fix: Update snapshots (link menu) * fix: Update snapshots (link menu) * fix merge mistake * export customizeCodeBlock --------- Co-authored-by: Yousef <yousefdardiry@gmail.com>
- Loading branch information
Showing
60 changed files
with
1,632 additions
and
584 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/core/src/api/clipboard/fromClipboard/acceptedMIMETypes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export const acceptedMIMETypes = [ | ||
"vscode-editor-data", | ||
"blocknote/html", | ||
"Files", | ||
"text/html", | ||
|
49 changes: 49 additions & 0 deletions
49
packages/core/src/api/clipboard/fromClipboard/handleVSCodePaste.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js"; | ||
import { | ||
BlockSchema, | ||
InlineContentSchema, | ||
StyleSchema, | ||
} from "../../../schema/index.js"; | ||
|
||
export async function handleVSCodePaste< | ||
BSchema extends BlockSchema, | ||
I extends InlineContentSchema, | ||
S extends StyleSchema | ||
>(event: ClipboardEvent, editor: BlockNoteEditor<BSchema, I, S>) { | ||
const view = editor.prosemirrorView; | ||
const { schema } = view.state; | ||
|
||
if (!event.clipboardData) { | ||
return false; | ||
} | ||
|
||
const text = event.clipboardData!.getData("text/plain"); | ||
const vscode = event.clipboardData!.getData("vscode-editor-data"); | ||
const vscodeData = vscode ? JSON.parse(vscode) : undefined; | ||
const language = vscodeData?.mode; | ||
|
||
if (!text) { | ||
return false; | ||
} | ||
|
||
if (!schema.nodes.codeBlock) { | ||
view.pasteText(text); | ||
|
||
return true; | ||
} | ||
|
||
if (!language) { | ||
return false; | ||
} | ||
|
||
// strip carriage return chars from text pasted as code | ||
// see: https://github.com/ProseMirror/prosemirror-view/commit/a50a6bcceb4ce52ac8fcc6162488d8875613aacd | ||
editor._tiptapEditor.view.pasteHTML( | ||
`<pre><code class="language-${language}">${text.replace( | ||
/\r\n?/g, | ||
"\n" | ||
)}</code></pre>` | ||
); | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/core/src/api/exporters/html/__snapshots__/codeBlock/defaultLanguage/external.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<pre><code class="bn-inline-content language-javascript">console.log('Hello, world!');</code></pre> |
1 change: 1 addition & 0 deletions
1
packages/core/src/api/exporters/html/__snapshots__/codeBlock/defaultLanguage/internal.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="1"><div class="bn-block" data-node-type="blockContainer" data-id="1"><div class="bn-block-content" data-content-type="codeBlock"><pre><code class="bn-inline-content language-javascript">console.log('Hello, world!');</code></pre></div></div></div></div> |
1 change: 1 addition & 0 deletions
1
packages/core/src/api/exporters/html/__snapshots__/codeBlock/empty/external.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<pre><code class="bn-inline-content language-javascript"></code></pre> |
1 change: 1 addition & 0 deletions
1
packages/core/src/api/exporters/html/__snapshots__/codeBlock/empty/internal.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="1"><div class="bn-block" data-node-type="blockContainer" data-id="1"><div class="bn-block-content" data-content-type="codeBlock"><pre><code class="bn-inline-content language-javascript"></code></pre></div></div></div></div> |
1 change: 1 addition & 0 deletions
1
packages/core/src/api/exporters/html/__snapshots__/codeBlock/python/external.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<pre><code class="bn-inline-content language-python">print('Hello, world!')</code></pre> |
1 change: 1 addition & 0 deletions
1
packages/core/src/api/exporters/html/__snapshots__/codeBlock/python/internal.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="1"><div class="bn-block" data-node-type="blockContainer" data-id="1"><div class="bn-block-content" data-content-type="codeBlock"><pre><code class="bn-inline-content language-python">print('Hello, world!')</code></pre></div></div></div></div> |
3 changes: 3 additions & 0 deletions
3
.../src/api/exporters/markdown/__snapshots__/codeBlock/defaultLanguage/markdown.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```javascript | ||
console.log('Hello, world!'); | ||
``` |
2 changes: 2 additions & 0 deletions
2
packages/core/src/api/exporters/markdown/__snapshots__/codeBlock/empty/markdown.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
```javascript | ||
``` |
3 changes: 3 additions & 0 deletions
3
...ages/core/src/api/exporters/markdown/__snapshots__/codeBlock/python/markdown.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```python | ||
print('Hello, world!') | ||
``` |
Oops, something went wrong.