I'm trying to use bleach to escape HTML tags. It works just fine, unless I'm trying to insert a code snipped as a content of a page. The snippet is inserted like this:
for (auto a = 0; i < 10; ++i)
You want to whitelist children tags of < pre > and < code >. From what I can infer from reading on the documentation, you have to define one by one the tags you want to whitelist or use a callable that every time a tag gets encountered the callable will be invoked.
Check on the documentation the section named: Callable Filters
A possible solution for your problem is to pass a function on the clean bleach.clean that will check whether the tag encountered by then clean method is a child of the code html tag. You will have to parse the HTML there, you can use HTML parser for that along with TreeBuilder of
Here is an example on a different answer.