Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(Preview): allow removing Preview with backspace
* Also only allow link marks inside the Preview.
* See #5442 for list of other follow up fixes for Previews

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Mar 13, 2024
commit 18681f3cae26c7124cef08a4c3974a30bb729f0c
6 changes: 5 additions & 1 deletion src/nodes/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export default Node.create({

content: 'text?',

defining: true,
atom: true,

marks: 'link',

isolating: true,

addOptions() {
return {
Expand Down
15 changes: 9 additions & 6 deletions src/tests/nodes/Preview.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Preview from './../../nodes/Preview'
import Markdown from './../../extensions/Markdown'
import Link from './../../marks/Link'
import { getExtensionField } from '@tiptap/core'
import { createCustomEditor, markdownThroughEditor, markdownThroughEditorHtml } from '../helpers'
import markdownit from '../../markdownit/index.js'
Expand All @@ -11,9 +12,7 @@ describe('Preview extension', () => {
})

it('exposes the toMarkdown function in the prosemirror schema', () => {
const editor = createCustomEditor({
extensions: [Markdown, Preview]
})
const editor = createEditorWithPreview()
const preview = editor.schema.nodes.preview
expect(preview.spec.toMarkdown).toBeDefined()
})
Expand All @@ -32,9 +31,7 @@ describe('Preview extension', () => {

it('detects links', () => {
const link = `<a href="https://nextcloud.com" title="preview">link</a>`
const editor = createCustomEditor({
extensions: [Markdown, Preview]
})
const editor = createEditorWithPreview()
editor.commands.setContent(`${link}<p>hello></p>`)
const node = editor.state.doc.content.firstChild
expect(node.type.name).toBe('preview')
Expand All @@ -43,3 +40,9 @@ describe('Preview extension', () => {
})

})

function createEditorWithPreview() {
return createCustomEditor({
extensions: [Markdown, Preview, Link]
})
}