Browse Source

indent the HTML sent from the editor

pull/82/head
Aaron Parecki 7 years ago
parent
commit
1894da9452
No known key found for this signature in database GPG Key ID: 276C2817346D6056
3 changed files with 64 additions and 2 deletions
  1. +2
    -1
      composer.json
  2. +46
    -1
      composer.lock
  3. +16
    -0
      lib/helpers.php

+ 2
- 1
composer.json View File

@ -14,7 +14,8 @@
"ezyang/htmlpurifier": "4.*", "ezyang/htmlpurifier": "4.*",
"p3k/multipart": "*", "p3k/multipart": "*",
"tantek/cassis": "*", "tantek/cassis": "*",
"p3k/timezone": "*"
"p3k/timezone": "*",
"gajus/dindent": "^2.0"
}, },
"autoload": { "autoload": {
"files": [ "files": [

+ 46
- 1
composer.lock View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "1eb78fb0a7afe487cc3c9dd58d35532e",
"content-hash": "05f646a93f2c1204dddd80c4670dcf15",
"packages": [ "packages": [
{ {
"name": "abraham/twitteroauth", "name": "abraham/twitteroauth",
@ -231,6 +231,51 @@
"homepage": "https://github.com/firebase/php-jwt", "homepage": "https://github.com/firebase/php-jwt",
"time": "2015-06-22T23:26:39+00:00" "time": "2015-06-22T23:26:39+00:00"
}, },
{
"name": "gajus/dindent",
"version": "2.0.2",
"source": {
"type": "git",
"url": "https://github.com/gajus/dindent.git",
"reference": "d81c3a6f78fbe1ab26f5e753098bbbef6b6a9f3c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/gajus/dindent/zipball/d81c3a6f78fbe1ab26f5e753098bbbef6b6a9f3c",
"reference": "d81c3a6f78fbe1ab26f5e753098bbbef6b6a9f3c",
"shasum": ""
},
"require": {
"php": ">=5.3"
},
"require-dev": {
"satooshi/php-coveralls": "dev-master"
},
"type": "library",
"autoload": {
"psr-4": {
"Gajus\\Dindent\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Gajus Kuizinas",
"email": "gk@anuary.com"
}
],
"description": "HTML indentation library for development and testing.",
"homepage": "https://github.com/gajus/dindent",
"keywords": [
"format",
"html",
"indent"
],
"time": "2014-10-08T10:03:04+00:00"
},
{ {
"name": "indieauth/client", "name": "indieauth/client",
"version": "0.1.13", "version": "0.1.13",

+ 16
- 0
lib/helpers.php View File

@ -382,12 +382,15 @@ function correct_photo_rotation($filename) {
} }
function sanitize_editor_html($html) { function sanitize_editor_html($html) {
#error_log($html."\n");
$config = HTMLPurifier_Config::createDefault(); $config = HTMLPurifier_Config::createDefault();
$config->set('Cache.DefinitionImpl', null); $config->set('Cache.DefinitionImpl', null);
$config->set('HTML.AllowedElements', [ $config->set('HTML.AllowedElements', [
'a', 'a',
'abbr', 'abbr',
'b', 'b',
'br',
'code', 'code',
'del', 'del',
'em', 'em',
@ -425,5 +428,18 @@ function sanitize_editor_html($html) {
$sanitized = str_replace('<p><br /></p>','',$sanitized); $sanitized = str_replace('<p><br /></p>','',$sanitized);
$sanitized = str_replace('<p></p>','',$sanitized); $sanitized = str_replace('<p></p>','',$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; return $sanitized;
} }

Loading…
Cancel
Save