milesj / decoda

A lightweight lexical string parser for BBCode styled markup.
MIT License
196 stars 52 forks source link

[Feature] Add attributes to [url] and [td] #91

Closed vansante closed 9 years ago

vansante commented 9 years ago

Hello,

I have two feature requests: Could you add support for target="_blank" on the [url] tag and width="xx" on the [td] tag?

Thanks!

milesj commented 9 years ago

These aren't features that are really necessary in core. You could always extend the UrlFilter and TableFilter with custom classes and add the attributes manually.

avidh commented 9 years ago

Hi, I'm also interested in target="_blank" ont he [url] tag as well. Would you be able to show an example on how to extend the UrlFilter to support this with custom classes?

milesj commented 9 years ago

Simply extend the UrlFilter and add new attributes in the constructor.

class MyUrlFilter extends UrlFilter {
    public function __construct(array $config = []) {
        $this->_tags['url']['attributes']['target'] = '/^(blank|self)$/i';
        parent::__construct($config);
    }
}
vamsiikrishna commented 9 years ago

Shouldn't it be htmlAttributes ?

milesj commented 9 years ago

The attributes is for Decoda attributes and htmlAttributes is for HTML attributes to directly put on the parsed tag.