1

Topic: How to preserve only selected definitions in style attribute

Topic How to allow attribute style="text-align: center" (http://www.bioinformatics.org/phplabware/forum/viewtopic.php?id=329) is closed, but I have question to solution.

I need to preserve only "text-align: center" in style attribute of paragraph. So I use parameter

$spec = 'p=style(match=%"text-align:\s+center;?"%)';

When in style attribute is more definitions, they are not removed, like in example

<p style="text-align: center; color:red">Center aligned paragraph</p>

"color:red" isn't pushed out. I don't know how to preserve only "text-align: center".

2

Re: How to preserve only selected definitions in style attribute

The attribute-specific rules specified in $spec operate on the full attribute values. Therefore, as you noticed, a value of text-align: center; color:red passes the rule style(match=%"text-align:\s+center;?"%).

In your case, to not permit the style property of color, you have may be two options, depending on your expectations about user input and your goals.

If you just want to _disallow_ any style attribute value if it contains a style property other than text-align (with value center), you can use a stricter regex in $spec, such as:

// Removes 'p' 'style' if it contains anything other than or besides 'text-align:center'

p=style(match=%"^\s*text-align:\s*center;?\s*$"%)

If you want to _filter out_ properties other than text-align, you will have to use a custom function and declare its used with $config hook_tag. Please take a look at forum postings like this one. Or let me know if you need help with designing such function's code.

3

Re: How to preserve only selected definitions in style attribute

Thank you, for now it fits my needs.