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.
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?
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:All I had to do was change it to
space: " "
and repack it.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:
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.It will look like
but when run, it will correct the problem.
NBSP isn’t considered whitespace for the purpose of indentation anyways, so you should take a look at what the pre select user script does and mimic it.