Search code examples
htmlfilterrebolrebol2

How do I customise the HTML Filter from Power-Mezz?


I'm experimenting with the HTML Filter module from the PowerMezz library and would like to customise the filter rules for a particular instance of the function. Is this possible?

For example, by default the style attribute is permitted, however I'd like to have this attribute stripped:

>> filter-html {<p style="color:red">A Para</p>}
== {<p>A Para</p>}

As well as limiting some other tags/attributes that are otherwise allowed.


Solution

  • After studying the filter-html module it looks like the immediate answer is no --- there appears to be no way to change the filter options for a particular instance.

    After some experimentation, however, I discovered that you can make small change to make something like this possible. Most attribute handling can be customized by changing the attributes-map block, but inline style attributes are not handled in that block. They are dealt with specifically in the check-attributes function.

    I commented out these lines in check-attributes which then causes all style attributes get stripped out by default:

    if value: select attributes 'style [
            append style value
    ]
    

    You would need to add the ones you didn't want filtered back in to the specific html tags in attribute-map. I make a copy of the original attribute-map, make my changes, run filter-html, then revert back to the original before the next filtering instance.