I have a self-hosted WP install, and have been using codecolorer (and have tried a few others along the way) to highlight R syntax. Looks nice, too.
The problem is that R uses a <-
symbol instead of =
when assigning objects (on pretty much every single line), and when you switch from ‘Visual’ to ‘HTML’ while editing a post it will mangle the code – <-
becomes <-
; worse, sections of the code will disappear.
It would be possible to use =
for the ‘assign’ command but it’s not, strictly-speaking, correct. At the moment I have to do all the pretty writing and inserting of images in WYSIWYG ‘visual’ mode, then switch to HTML just before I post to fix up the R code, and then be careful never to switch back again. Ever.
Any fixes for this behaviour?
EDIT: examples!
Putting this into the Visual editor:
[cc]
lorum <- ipsum
[/cc]
Produces the following in the final post:
lorum <- ipsum
Going back to HTML mode and putting a <-
code worked for the final post but then I could never switch back to Visual without the <
being interpreted as part of a tag.
1 Answer
Solved it. A real RTFM moment.
The FAQ for CodeColorer makes a note about this (though it’s not mentioned in the main how-to text).
Using the escaped = "true"
code in the [cc]
tag brings back the behaviour I was looking for – now it’s possible to write the <-
operator in Visual (and it becomes <
in HTML), but the published post displays <-
correctly.
Thus, entering this in the visual editor:
[cc escaped="true"]
lorum <- ipsum
[/cc]
Produces, in the published post:
lorum <- ipsum