Question

I'm using the SyntaxHighlighter plugin for CKEditor to insert code into my pages. The plugin uses <pre> tags to contain the code whilst making use of "brush" classes to define the programming language. My problem is that upon submission of the page HTML Purifier is stripping the class attribute from the pre tags, which effectively prevents the syntax highlighting from occurring.

The source code goes from:

<pre class="brush:php;">
   <?php echo '<p>Hello World</p>'; ?>
</pre>

to:

<pre>
   <?php echo '<p>Hello World</p>'; ?>
</pre>

I'm hoping there is some magical setting to stop HTML Purifier from doing this.

Was it helpful?

Solution

The reason is brush:php is not a valid class name per the HTML4 specification. I guess you could write your own class name validator and override the builtin using http://htmlpurifier.org/docs/enduser-customize.html

But a better solution might be to run the syntax highlighting before you run HTML Purifier!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top