From 1894da9452edaf1f2b3de5a6a969d60844645a23 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Fri, 3 Feb 2017 14:51:11 -0800 Subject: indent the HTML sent from the editor --- lib/helpers.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib') diff --git a/lib/helpers.php b/lib/helpers.php index 26faf49..f5dc13d 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -382,12 +382,15 @@ function correct_photo_rotation($filename) { } function sanitize_editor_html($html) { + #error_log($html."\n"); + $config = HTMLPurifier_Config::createDefault(); $config->set('Cache.DefinitionImpl', null); $config->set('HTML.AllowedElements', [ 'a', 'abbr', 'b', + 'br', 'code', 'del', 'em', @@ -425,5 +428,18 @@ function sanitize_editor_html($html) { $sanitized = str_replace('


','',$sanitized); $sanitized = str_replace('

','',$sanitized); + $indenter = new \Gajus\Dindent\Indenter([ + 'indentation_character' => ' ' + ]); + $indenter->setElementType('h1', \Gajus\Dindent\Indenter::ELEMENT_TYPE_INLINE); + $indenter->setElementType('h2', \Gajus\Dindent\Indenter::ELEMENT_TYPE_INLINE); + $indenter->setElementType('h3', \Gajus\Dindent\Indenter::ELEMENT_TYPE_INLINE); + $indenter->setElementType('h4', \Gajus\Dindent\Indenter::ELEMENT_TYPE_INLINE); + $indenter->setElementType('h5', \Gajus\Dindent\Indenter::ELEMENT_TYPE_INLINE); + $indenter->setElementType('h6', \Gajus\Dindent\Indenter::ELEMENT_TYPE_INLINE); + $sanitized = $indenter->indent($sanitized); + + #error_log($sanitized."\n"); + return $sanitized; } -- cgit v1.2.3