|
|
@ -7,6 +7,11 @@ use League\CommonMark\Extension\FrontMatter\FrontMatterExtension;
|
|
|
|
use League\CommonMark\Extension\FrontMatter\Output\RenderedContentWithFrontMatter;
|
|
|
|
use League\CommonMark\Extension\FrontMatter\Output\RenderedContentWithFrontMatter;
|
|
|
|
use League\CommonMark\MarkdownConverter;
|
|
|
|
use League\CommonMark\MarkdownConverter;
|
|
|
|
use League\CommonMark\CommonMarkConverter;
|
|
|
|
use League\CommonMark\CommonMarkConverter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use HtmlSanitizer\Extension\Basic\BasicExtension;
|
|
|
|
|
|
|
|
use HtmlSanitizer\Extension\Iframe\IframeExtension;
|
|
|
|
|
|
|
|
use HtmlSanitizer\SanitizerBuilder;
|
|
|
|
|
|
|
|
|
|
|
|
use function _\orderBy;
|
|
|
|
use function _\orderBy;
|
|
|
|
|
|
|
|
|
|
|
|
class Contents
|
|
|
|
class Contents
|
|
|
@ -63,16 +68,35 @@ class Contents
|
|
|
|
->parse(file_get_contents($file));
|
|
|
|
->parse(file_get_contents($file));
|
|
|
|
|
|
|
|
|
|
|
|
//never trust the front end. clean it up
|
|
|
|
//never trust the front end. clean it up
|
|
|
|
$sanitizer = HtmlSanitizer\Sanitizer::create([
|
|
|
|
|
|
|
|
"extensions" => ["basic", "image", "list", "code"],
|
|
|
|
$builder = new SanitizerBuilder();
|
|
|
|
|
|
|
|
$builder->registerExtension(new BasicExtension());
|
|
|
|
|
|
|
|
$builder->registerExtension(new IframeExtension());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//relative-a and relative-image
|
|
|
|
|
|
|
|
$builder->registerExtension(
|
|
|
|
|
|
|
|
new \HtmlSanitizer\Extension\Relative\A\AExtension()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$builder->registerExtension(
|
|
|
|
|
|
|
|
new \HtmlSanitizer\Extension\Relative\Image\ImageExtension()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$detergent = [
|
|
|
|
|
|
|
|
"extensions" => ["basic", "relative-a", "relative-image", "iframe"],
|
|
|
|
"tags" => [
|
|
|
|
"tags" => [
|
|
|
|
|
|
|
|
"div" => [
|
|
|
|
|
|
|
|
"allowed_attributes" => ["class", "title"],
|
|
|
|
|
|
|
|
],
|
|
|
|
"img" => [
|
|
|
|
"img" => [
|
|
|
|
"allowed_attributes" => ["src", "alt", "title", "class"],
|
|
|
|
"allowed_attributes" => ["src", "alt", "title", "class"],
|
|
|
|
"allowed_hosts" => null,
|
|
|
|
],
|
|
|
|
"allow_relative_links" => true,
|
|
|
|
"iframe" => [
|
|
|
|
|
|
|
|
"allowed_attributes" => ["height", "width", "title", "src"],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sanitizer = $builder->build($detergent);
|
|
|
|
|
|
|
|
|
|
|
|
$scrubbed = $sanitizer->sanitize($result->getContent());
|
|
|
|
$scrubbed = $sanitizer->sanitize($result->getContent());
|
|
|
|
|
|
|
|
|
|
|
|