Tidy HTML output

This commit is contained in:
Les De Ridder 2018-10-16 04:42:13 +02:00
parent f627e545b8
commit 562c45713d
5 changed files with 131 additions and 2 deletions

View File

@ -18,6 +18,7 @@ class Kernel extends HttpKernel
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\Stolz\HtmlTidy\Middleware::class,
];
/**

View File

@ -17,7 +17,8 @@
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "^7.0"
"phpunit/phpunit": "^7.0",
"stolz/laravel-html-tidy": "^0.1.1"
},
"autoload": {
"classmap": [

59
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "a875862ccc0c27fcee12c6892c3e2b32",
"content-hash": "88c4c6682a40e4d392c06df35c52baf4",
"packages": [
{
"name": "dnoegel/php-xdg-base-dir",
@ -4156,6 +4156,63 @@
"homepage": "https://github.com/sebastianbergmann/version",
"time": "2016-10-03T07:35:21+00:00"
},
{
"name": "stolz/laravel-html-tidy",
"version": "0.1.1",
"source": {
"type": "git",
"url": "https://github.com/Stolz/laravel-html-tidy.git",
"reference": "e559ce9a3cbd8f690d27c0eabc6385bb50882cc1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Stolz/laravel-html-tidy/zipball/e559ce9a3cbd8f690d27c0eabc6385bb50882cc1",
"reference": "e559ce9a3cbd8f690d27c0eabc6385bb50882cc1",
"shasum": ""
},
"require": {
"ext-tidy": "*",
"illuminate/http": "5.*",
"illuminate/support": "5.*",
"php": ">=5.4"
},
"require-dev": {
"squizlabs/php_codesniffer": "2.*"
},
"type": "library",
"autoload": {
"psr-4": {
"Stolz\\HtmlTidy\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Stolz",
"homepage": "https://github.com/Stolz/laravel-html-tidy",
"role": "developer"
}
],
"description": "HTML Tidy middleware for Laravel",
"keywords": [
"HTML5",
"HTMLtidy",
"Purifier",
"beautifier",
"filter",
"html",
"htmlpurifier",
"indent",
"laravel",
"markup",
"middleware",
"tidy"
],
"time": "2015-12-28T03:55:57+00:00"
},
{
"name": "theseer/tokenizer",
"version": "1.1.0",

View File

@ -166,6 +166,7 @@ return [
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Stolz\HtmlTidy\ServiceProvider::class,
],
/*

69
config/tidy.php Normal file
View File

@ -0,0 +1,69 @@
<?php
/*
|--------------------------------------------------------------------------
| HTML Tidy Laravel filter
|--------------------------------------------------------------------------
|
| Here is a list of all available config options with their default values.
|
| For more info please visit https://github.com/Stolz/laravel-html-tidy
|
*/
return [
// Enable if PHP has tidy extension support
'enabled' => extension_loaded('tidy'),
// Process AJAX requests
'ajax' => false,
// Encoding of your original documents. This refers to the encoding that you original documents have,
// not the enconding that will be used for the output.
'encoding' => 'utf8', // Possible values: ascii, latin0, latin1, raw, utf8, iso2022, mac, win1252, ibm858, utf16, utf16le, utf16be, big5, and shiftjis.
// Doctype used for the output
'doctype' => '<!doctype html>',
// Append errors to output
'display_errors' => false,
// Errors container opening tag
'container_open_tag' => '<div id="tidy_errors" style="position: absolute;right: 0;top: 0;z-index: 100;padding:1em;margin:1em;border:1px solid #DC0024;font-family: Sans-Serif;background-color:#FFE5E5;color:#DC0024"><a style="float:right;cursor:pointer;color:blue;margin:-15px" onclick="document.getElementById(\'tidy_errors\').style.display = \'none\'">[x]</a>',
// Errors container closing tag
'container_close_tag' => '</div>',
// Options passed to HTML Tidy parseString() function. Docs: http://tidy.sourceforge.net/docs/quickref.html
'tidy_options' => [
'output-xhtml' => false,
'char-encoding' => 'utf8',
'wrap' => 0,
'wrap-sections' => false,
'indent' => 2, // 2 is equivalent to 'auto', which seems to be ignored by PHP-html-tidy extension
'indent-spaces' => 4,
// HTML5 workarounds
'doctype' => 'omit', //The filter will add the configured doctype later
'new-blocklevel-tags' => 'article,aside,canvas,dialog,embed,figcaption,figure,footer,header,hgroup,nav,output,progress,section,video',
'new-inline-tags' => 'audio,bdi,command,datagrid,datalist,details,keygen,mark,meter,rp,rt,ruby,source,summary,time,track,wbr',
],
// Errors that match these regexs wont be displayed
'ignored_errors' => [
// workaround to hide errors related to HTML5
"/line.*<html> proprietary attribute \"class\"\n?/",
"/line.*<input> proprietary attribute \"autocomplete\"\n?/",
"/line.*<input> proprietary attribute \"autofocus\"\n?/",
"/line.*<meta> lacks \"content\" attribute\n?/",
"/line.*<meta> proprietary attribute \"charset\"\n?/",
"/line.*<script> inserting \"type\" attribute\n?/",
"/line.*<style> inserting \"type\" attribute\n?/",
"/line.*<table> lacks \"summary\" attribute\n?/",
"/line.*is not approved by W3C\n?/",
"/line.*proprietary attribute \"data-.*\n?/",
"/line.*proprietary attribute \"placeholder.*\n?/",
"/line.*proprietary attribute \"contenteditable.*\n?/",
],
];