/** * @route ajax/rich_text_preview */ public function richTextPreview() { if (\Airship\all_keys_exist(['format', 'body'], $_POST)) { switch ($_POST['format']) { case 'HTML': case 'Rich Text': \Airship\json_response(['status' => 'OK', 'body' => \Airship\LensFunctions\get_purified($_POST['body'] ?? '')]); break; case 'Markdown': \Airship\json_response(['status' => 'OK', 'body' => \Airship\LensFunctions\render_purified_markdown($_POST['body'] ?? '', true)]); break; case 'RST': \Airship\json_response(['status' => 'OK', 'body' => \Airship\LensFunctions\get_purified(\Airship\LensFunctions\render_rst($_POST['body'] ?? '', true))]); break; default: \Airship\json_response(['status' => 'ERROR', 'message' => 'Unknown format: ' . $_POST['format']]); } } \Airship\json_response(['status' => 'ERROR', 'message' => \__('Incomplete request')]); }
/** * ReStructuredText then HTMLPurifier * * @param string $string * @param bool $return * @return string|null */ function render_purified_rest(string $string = '', bool $return = false) { if ($return) { \ob_start(); } \Airship\LensFunctions\purify(\Airship\LensFunctions\render_rst($string, true)); if ($return) { return \ob_get_clean(); } return null; }