Remove “​” from being injected into HTML

I ran into an issue developing a recent site of a few zero width space characters (​) getting injecting into the html output:

zero width space character

Apparently Sublime Text 3 was the source of the problem, but these characters didn’t appear in the source. Opening the file in VIM allowed me to see the offending characters, this time <200b>:


I could have simply deleted the code right there in VIM, but it scares me a little bit, so I wanted to be able to have these characters show in Sublime. Searching the web turned up an article on Stack Overflow to do just that.

Here’s how:

1. Create a new file and paste this code into it:

import sublime_plugin

class ShowZeroWidthSpace(sublime_plugin.EventListener):
def on_modified(self, view):
spaces = []
p = 0
while True:
s = view.find(u’\u200b’, p + 1)
if not s:
p = s.a

if spaces:
view.add_regions("zero-width", spaces, "invalid")

2. Save this file to Packages/User directory as

Here’s the full path to that directory:
/Users/{user}/Library/Application Support/Sublime Text 3/Packages

Restart Sublime and you should be able to see the characters as lines, which are red for me:

Screen Shot 2015-09-16 at 12.04.23 PM

Delete them and you should be good to go.

Leave a Reply

Your email address will not be published. Required fields are marked *

See if Cinch is right for you.

Ask us anything. Seriously. Like, what is the air speed velocity of an unladen swallow?

Start a chat right now

Or go ahead and Sign up now