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.

有帮助吗?

解决方案

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!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top