Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?

like image 414
Alex Coplan Avatar asked Mar 29 '12 21:03

Alex Coplan


2 Answers

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.

like image 123
Alex Coplan Avatar answered Sep 17 '22 20:09

Alex Coplan


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.

like image 35
horta Avatar answered Sep 18 '22 20:09

horta