Giter Site home page Giter Site logo

fossabot / htmlpurifier-html5 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xemlock/htmlpurifier-html5

0.0 1.0 0.0 171 KB

HTML5 element definitions for HTMLPurifier

Home Page: https://packagist.org/packages/xemlock/htmlpurifier-html5

License: MIT License

PHP 100.00%

htmlpurifier-html5's Introduction

HTML5 Definitions for HTML Purifier

Maintenance Build Status Coverage Status Latest Stable Version Total Downloads License FOSSA Status

This library provides HTML5 element definitions for HTML Purifier.

It is the most complete HTML5-compliant solution among all based on HTML Purifier. Apart from providing the most extensive set of element definitions, it provides tidy/sanitization rules for transforming the input into a valid HTML5 output.

Installation

Install with Composer by running the following command:

composer require xemlock/htmlpurifier-html5

Usage

The most basic usage is similar to the original HTML Purifier. Create a HTML5-compatible config using HTMLPurifier_HTML5Config::createDefault() factory method, and then pass it to an HTMLPurifier instance:

$config = HTMLPurifier_HTML5Config::createDefault();
$purifier = new HTMLPurifier($config);
$clean_html5 = $purifier->purify($dirty_html5);

To modify the config you can either instantiate the config with a configuration array passed to HTMLPurifier_HTML5Config::create(), or by calling set method on an already existing config instance.

For example, to allow IFRAMEs with Youtube videos you can do the following:

$config = HTMLPurifier_HTML5Config::create(array(
  'HTML.SafeIframe' => true,
  'URI.SafeIframeRegexp' => '%^//www\.youtube\.com/embed/%',
));

or equivalently:

$config = HTMLPurifier_HTML5Config::createDefault();
$config->set('HTML.SafeIframe', true);
$config->set('URI.SafeIframeRegexp', '%^//www\.youtube\.com/embed/%');

Configuration

Apart from HTML Purifier's built-in configuration directives, the following new directives are also supported:

  • HTML.IframeAllowFullscreen

    Version added: 0.1.11
    Type: Boolean
    Default: false

    Whether or not to permit allowfullscreen attribute on iframe tags. It requires either %HTML.SafeIframe or %HTML.Trusted to be true.

Supported HTML5 elements

Aside from HTML elements supported originally by HTML Purifier, this library adds support for the following HTML5 elements:

<article>, <aside>, <audio>, <bdi>, <details>, <dialog>, <figcaption>, <figure>, <footer>, <header>, <hgroup>, <main>, <mark>, <nav>, <picture>, <progress>, <section>, <source>, <summary>, <time>, <track>, <video>, <wbr>

as well as HTML5 attributes added to existing HTML elements, such as:

<a>, <del>, <fieldset>, <ins>, <script>

License

The MIT License (MIT). See the LICENSE file.

htmlpurifier-html5's People

Contributors

fossabot avatar mbrodala avatar sherbrow avatar xemlock avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.