Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm writing a tutorial on using the R language to do some applied statistics. An example post is:

http://mcmcinirt.stat.cmu.edu/archives/223

This answer taught me how to develop a custom shortcode so that I can include files stored on the webserver directly into the post. It works great.

However, if possible, I'd like to have syntax highlighting too instead of 'just' the <pre> tag rendering.

My initial attempt was to change the output of the shortcode function from:

return '<pre>'.$file.'</pre>';

to

return '<pre class="lang:r">'.$file.'</pre>';   

so that the CSS defined for the Crayon Syntax Highlighter would take over.

However, that doesn't work because Crayon seems to take a <pre> tag and replace it with a lot of other divs e.g. <div class="crayon-line crayon-striped-line" ...> which are what the CSS is actually for.

Is there a way to force Crayon to run after my shortcode so that the text included by the shortcode gets appropriately processed? Or do I need a different solution entirely? Perhaps a different syntax highlighter?

Also, FWIW, I'd rather have non-duplicated code than pretty code. I figure it doesn't hurt to ping the experts though.

share|improve this question
    
Not sure if your Question is a duplicate or not, check it out. –  brasofilo Oct 14 '13 at 23:45
    
@brasofilo As I understand the other question, their question is about how to write their own syntax highlighter. My question is how to use a syntax highlighter for an external file. –  Nathan VanHoudnos Oct 14 '13 at 23:56

1 Answer 1

I had a similar issue with WP-Syntax and solved by applying the_content filter in the Shortcode returned values. It would go like:

function my_shortcode( $atts, $content )
{
    $code = '<pre class="lang:r">' . $file . '</pre>';   
    return apply_filters ( 'the_content', $code );
}
share|improve this answer
    
So if I were to switch to the WP-Syntax plugin, this solution would work? (I naively tried it with my current Crayon setup and it broke things to pieces, e.g. all of the formatting on the page went away!) –  Nathan VanHoudnos Oct 15 '13 at 2:10
    
Works for me is this plugin. So, you tried to apply the filter and it brought havoc? No, not "naively", we can only know after trying ;) –  brasofilo Oct 15 '13 at 2:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.