| 1 |
import MarkdownIt from 'markdown-it'; |
| 2 |
|
| 3 |
import { RawHTML } from '@wordpress/element'; |
| 4 |
import { __ } from '@wordpress/i18n'; |
| 5 |
|
| 6 |
/** |
| 7 |
* Module variables |
| 8 |
*/ |
| 9 |
const markdownConverter = new MarkdownIt(); |
| 10 |
|
| 11 |
/** |
| 12 |
* MDRender Class. |
| 13 |
* |
| 14 |
* @param props |
| 15 |
*/ |
| 16 |
export default function MDRender(props) { |
| 17 |
const { content, ...restProps } = props; |
| 18 |
|
| 19 |
return ( |
| 20 |
<RawHTML |
| 21 |
onClick={(e) => { |
| 22 |
if (e.target.nodeName === 'A') { |
| 23 |
if ( |
| 24 |
// eslint-disable-next-line no-alert |
| 25 |
!window.confirm( |
| 26 |
__( |
| 27 |
'Are you sure you wish to leave this page?', |
| 28 |
'ghostkit' |
| 29 |
) |
| 30 |
) |
| 31 |
) { |
| 32 |
e.preventDefault(); |
| 33 |
} |
| 34 |
} |
| 35 |
}} |
| 36 |
{...restProps} |
| 37 |
> |
| 38 |
{content && content.length ? markdownConverter.render(content) : ''} |
| 39 |
</RawHTML> |
| 40 |
); |
| 41 |
} |
| 42 |
|