Thursday, March 19, 2009

A grease monkey script to view tab and new line characters in a browser

In certain cases its necessary to recognize tab and newline characters in a document. Microsoft word comes with an option to hide or show such punctuation marks like newline and tab characters. The short cut for enabling the display of punctuation marks is “Ctrl + *”. It can be very beneficial I differentiating space characters from tab characters.

Internet explorer or any other browser such as firefox, safari, opera or chrome does not come with such a option to view newline and tab characters. Simple one line greasemonkey script can do the job for firefox.

As can be seen in above screen, the newline characters in wikipedia home page been replaced by “q|” and tab characters have been replaced by “-->”.

The code for the oneline greasemonkey script is given below:

document.documentElement.innerHTML=document.documentElement.innerHTML.replace(/\t/g,"-->").replace(/\n/g,"q|");

Hopefully future versions of Internet browsers will provide this facility to view tab and newline characters when required.

No comments: