4

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 &lt;-; 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 &lt;- 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.

8
  • Have you tried wrapping those chunks in <code></code>?
    – SickHippie
    Mar 22, 2012 at 16:09
  • Yep - they're all wrapped nicely. <code lang="rsplus"></code>.
    – Simbamangu
    Mar 22, 2012 at 18:13
  • 1
    I found some sample R code and pasted it into the WP editor. I switched back and forth between Visual and HTML mode with no ill effects. The transliteration of '<' into '&lt;' is supposed to happen. The '<' character has special meaning as a start-of-tag in HTML, so it must be escaped into the '&lt;' entity to show up correctly in text. Were you by chance changing it back to a '<' while in HTML mode? Because that would wreak havoc on your post. Mar 22, 2012 at 21:08
  • The only way to make '&lt' not appear in the post within the code was to put it in while in HTML mode - try 'preview' to see what I mean. Indeed, that's why it gets mangled twixt Visual and HTML ...
    – Simbamangu
    Mar 23, 2012 at 6:33
  • Okay, you've edited with more details... When you switch to HTML editor, DO NOT change '&lt;' back to '<'. This is what is causing your problems. Leave it alone. It's doing what it's supposed to do. Mar 24, 2012 at 2:41

1 Answer 1

1

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 &lt 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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