| 1 |
import { createBlock } from '@wordpress/blocks'; |
| 2 |
import { escapeHTML } from '@wordpress/escape-html'; |
| 3 |
import blockConfig from '../block.json'; |
| 4 |
import type { Attributes, Lang } from '../types'; |
| 5 |
import { getMainAlias } from '../util/languages'; |
| 6 |
|
| 7 |
export const transformToCBP = (attrs: any) => { |
| 8 |
const { content, language } = attrs; |
| 9 |
const decode = (value: string) => { |
| 10 |
const txt = document.createElement('textarea'); |
| 11 |
txt.innerHTML = value; |
| 12 |
return txt.value; |
| 13 |
}; |
| 14 |
return createBlock(blockConfig.name, { |
| 15 |
code: content ? escapeHTML(decode(content)) : undefined, |
| 16 |
language: getMainAlias(language) as Lang, |
| 17 |
}); |
| 18 |
}; |
| 19 |
|
| 20 |
export const transformFromCBP = (attrs: Attributes) => { |
| 21 |
const { code: content } = attrs; |
| 22 |
return createBlock('core/code', { content }); |
| 23 |
}; |
| 24 |
|