Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I add an attribute? #54

Open
matt-panton opened this issue Jan 28, 2017 · 8 comments
Open

How can I add an attribute? #54

matt-panton opened this issue Jan 28, 2017 · 8 comments

Comments

@matt-panton
Copy link

I'm trying to add the align attribute to the <table> tag. I've found the relevant documentation on the htmlpurifier website but can't get figure out how to get it to work with this laravel package.
I've put this code in my config/purifier.php file but it's still showing the error Attribute 'align' in element 'table' not supported

$config = \HTMLPurifier_Config::createDefault();
$def = $config->getHTMLDefinition(true);
$def->addAttribute('table', 'align', 'Enum#left,right,center');
@LukeTowers
Copy link
Contributor

You can use my forked package instead, then you'll be able to just add it through the config file, along with having default support for HTML5: https://packagist.org/packages/luketowers/purifier
It looks like the maintainer is no longer interested in maintaining this version

@jplew
Copy link

jplew commented Sep 28, 2017

@LukeTowers thanks for supporting the project. However, custom attributes don't seem to work for me. I'm trying to pass <img data-filename="..."> and getting this error:

ErrorException in HTMLDefinition.php line 379:
Attribute 'data-filename' in element 'img' not supported (for information on implementing this, see the support forums)

Here is the relevant part of my config/purifier.php:

'HTML.Allowed'  => 'div,b,strong,i,em,u,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src|style|data-filename]',

Am I doing something wrong?

Edit:
In addition, I'm trying to pass a 'style' attribute on my <img> tag. Despite the fact I have also specified 'style' in my HTML.Allowed, the clean() function is stripping out my style attribute. It doesn't give an error message like it does for data-filename, however.

@LukeTowers
Copy link
Contributor

@jplew Are you using my package? If so, log an issue on my repository then please: https://github.com/LukeTowers/Purifier

@jplew
Copy link

jplew commented Sep 28, 2017

@LukeTowers yes, I switched to your fork. I just submitted an issue there: LukeTowers#2

@francisashley
Copy link

+1

@LukeTowers
Copy link
Contributor

@prjctnxt instead of just adding a +1, could you try playing around with the code mentioned here and see if you can figure out the issue?

@francisashley
Copy link

Hi, managed to solve it with this library /stevebauman/purify. One thing that caught me out was that Purifier will still strip your tags unless they are 100% valid. As in (after configuring): <img data-src="#"> is considered invalid but <img src="#" data-src="#"> is fine.

I played around with your library before learning about this so not sure if it is a solution?

Will take a look when I get a chance :-)

@leewillis77
Copy link

@prjctnxt Thanks for leaving this comment. I too couldn't get this library to work. Swapped over to https://github.com/stevebauman/purify and had it up and running inside 5 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants