deprecated
1 week ago
block.json
1 week ago
component.js
1 week ago
edit.js
1 week ago
icon.svg
2 months ago
index.js
1 week ago
index.php
2 months ago
save.js
1 week ago
style.scss
1 week ago
transforms.js
2 months ago
transforms.js
37 lines
| 1 | /** |
| 2 | * WordPress dependencies |
| 3 | */ |
| 4 | import { createBlock } from '@wordpress/blocks'; |
| 5 | |
| 6 | const transforms = { |
| 7 | from: [ |
| 8 | { |
| 9 | type: 'block', |
| 10 | isMultiBlock: false, |
| 11 | blocks: ['core/paragraph'], |
| 12 | transform: ({ content }) => { |
| 13 | const div = document.createElement('div'); |
| 14 | div.innerHTML = content; |
| 15 | const text = div.innerText || ''; |
| 16 | const link = div.querySelector('a'); |
| 17 | const url = link?.getAttribute('href'); |
| 18 | const target = link?.getAttribute('target') ? true : false; |
| 19 | return createBlock('vk-blocks/button', { |
| 20 | content: text, |
| 21 | buttonUrl: url, |
| 22 | buttonTarget: target, |
| 23 | }); |
| 24 | }, |
| 25 | isMatch: (attributes) => { |
| 26 | const div = document.createElement('div'); |
| 27 | div.innerHTML = attributes.content; |
| 28 | const text = div.innerText || ''; |
| 29 | const links = div.querySelectorAll('a'); |
| 30 | return text.length <= 30 && links.length <= 1; |
| 31 | }, |
| 32 | }, |
| 33 | ], |
| 34 | }; |
| 35 | |
| 36 | export default transforms; |
| 37 |