forked from udecode/plate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow the link plugin to optionally specify a custom href for link te…
…xt (udecode#1687) * Allow the link plugin to optionally specify a custom href for link text * changeset
- Loading branch information
Showing
3 changed files
with
63 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@udecode/plate-link': patch | ||
--- | ||
|
||
Allow the link plugin to optionally specify a custom href for link text |
51 changes: 51 additions & 0 deletions
51
...s/link/src/__tests__/withLink/insertText/space-after-url-block-start-custom-href.spec.tsx
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,51 @@ | ||
/** @jsx jsx */ | ||
|
||
import { createPlateEditor } from '@udecode/plate-core'; | ||
import { jsx } from '@udecode/plate-test-utils'; | ||
import { createLinkPlugin } from '../../../createLinkPlugin'; | ||
|
||
jsx; | ||
|
||
const input = ( | ||
<editor> | ||
<hp> | ||
google.com | ||
<cursor /> | ||
</hp> | ||
</editor> | ||
) as any; | ||
|
||
const text = ' '; | ||
|
||
const output = ( | ||
<editor> | ||
<hp> | ||
<htext /> | ||
<element type="a" url="http://google.com"> | ||
google.com | ||
</element>{' '} | ||
</hp> | ||
</editor> | ||
) as any; | ||
|
||
describe('when inserting a space with a link element at the beginning of a block using a custom href', () => { | ||
it('should wrap the url in a link', () => { | ||
const editor = createPlateEditor({ | ||
editor: input, | ||
plugins: [ | ||
createLinkPlugin({ | ||
options: { | ||
isUrl: (url) => url === 'google.com', | ||
getUrlHref: (url) => { | ||
return 'http://google.com'; | ||
}, | ||
}, | ||
}), | ||
], | ||
}); | ||
|
||
editor.insertText(text); | ||
|
||
expect(input.children).toEqual(output.children); | ||
}); | ||
}); |
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