How to avoid the xc2 character or   in my code snippets?

I’ve just started a coding blog, and I’m using the SyntaxHighlighter Evolved WordPress plugin for Syntax Highlighting of my snippets.

I’ve just about finished writing a Pythonic post, and wanted to test out my code snippets before publishing.

Read More

If you double click code from inside my snippets, the plugin will stop highlighting the code, allowing you to select it as plain text. However, if I copy and paste some Python code from my snippets, it includes xc2 or   chracters in. This causes Python to winge about the encoding:

SyntaxError: Non-ASCII character ‘xc2’ in file ex2.py on line 3, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

I don’t particularly want to be declaring encodings for every single Python snippet I write – and I don’t even know if this will solve the issue.

The best solution would of course to be to get my plugin to not use   characters in the plain text version. Or would it?

Does anyone have any ideas as to how I can get around this issue?

Related posts

Leave a Reply

3 comments

  1. Ah, got it. Just a bit of poking around in the plugin’s source fixed this issue for me…

    If you beautify the syntaxhighlighter3/scripts/shCore.js file, then you can see there is a config variable, which includes:

    space: " "
    

    All I had to do was change it to space: " " and repack it.

  2. I ran into this problem when python code had been copied from skype. Since I use vim to edit, I went ahead and found all of these by doing this:

    :hls
    /<space>
    

    This shows where these odd space characters aren’t because they’re not highlighted.
    Yank one of the characters which will store it into register 0.
    Use the substitute command and use <ctrl-R> <0> to paste that character into the command prompt.

    :%s/<ctrl-R><0>/ /g
    

    It will look like

    :%s/ / /g
    

    but when run, it will correct the problem.