-
-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9f121e
commit ac88ec4
Showing
5 changed files
with
126 additions
and
5 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
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
99 changes: 99 additions & 0 deletions
99
packages/core/src/lib/static/__tests__/node-to-props.spec.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,99 @@ | ||
it('TODO: serialize list to html', () => { | ||
expect(1).toBe(1); | ||
}); | ||
|
||
import { BaseLinkPlugin } from '@udecode/plate-link'; | ||
import { BaseImagePlugin } from '@udecode/plate-media'; | ||
|
||
import { createSlateEditor } from '../../editor'; | ||
import { BaseParagraphPlugin } from '../../plugins'; | ||
import { serializePlateStatic } from '../serializedHtml'; | ||
import { staticComponents } from './create-static-editor'; | ||
|
||
const plugins = [ | ||
BaseParagraphPlugin, | ||
BaseLinkPlugin.extend(() => ({ | ||
node: { | ||
dangerouslyAllowAttributes: ['target'], | ||
props: ({ element }) => | ||
/^https?:\/\/slatejs.org\/?/.test((element as any).url) | ||
? {} | ||
: { target: '_blank' }, | ||
}, | ||
})), | ||
BaseImagePlugin.extend({ | ||
node: { | ||
props: ({ element }) => ({ | ||
alt: (element as any).attributes?.alt, | ||
width: (element as any).url.split('/').pop(), | ||
}), | ||
}, | ||
}), | ||
]; | ||
|
||
it('serialize link to html with attributes', async () => { | ||
const staticEditor = createSlateEditor({ | ||
plugins, | ||
value: [ | ||
{ | ||
children: [ | ||
{ text: 'An external ' }, | ||
{ | ||
children: [{ text: 'link' }], | ||
type: 'a', | ||
url: 'https://theuselessweb.com/', | ||
}, | ||
{ text: ' and an internal ' }, | ||
{ | ||
children: [{ text: 'link' }], | ||
target: '_self', | ||
type: 'a', | ||
url: 'https://slatejs.org/', | ||
}, | ||
{ text: '.' }, | ||
], | ||
type: 'p', | ||
}, | ||
], | ||
}); | ||
|
||
expect( | ||
await serializePlateStatic(staticEditor, staticComponents, { | ||
preserveClassNames: [], | ||
stripClassNames: true, | ||
stripDataAttributes: true, | ||
}) | ||
).toContain(`target="_blank"`); | ||
}); | ||
|
||
it('serialize image with alt to html', async () => { | ||
const staticEditor = createSlateEditor({ | ||
plugins, | ||
value: [ | ||
{ | ||
children: [ | ||
{ | ||
attributes: { alt: 'Placeholder' }, | ||
children: [], | ||
type: 'img', | ||
url: 'https://via.placeholder.com/300', | ||
}, | ||
], | ||
type: 'p', | ||
}, | ||
], | ||
}); | ||
|
||
const htmlString = await serializePlateStatic( | ||
staticEditor, | ||
staticComponents, | ||
{ | ||
preserveClassNames: [], | ||
stripClassNames: true, | ||
stripDataAttributes: true, | ||
} | ||
); | ||
|
||
expect(htmlString).toContain(`alt="Placeholder"`); | ||
expect(htmlString).toContain(`width="300"`); | ||
}); |
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
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