
As an editor of online materials, I find myself with a curious problem: how to deal with single and double quotation marks. Because I suffer from a mild form of OCD, I like these always to be represented by the typewriter keys ' and ". Then I let WordPress, or whatever other content management system I’m using, convert these characters into the typographic symbols with left and right sides.
For example:
“The sky above the port was the color of television, tuned to a dead channel.”
And:
‘The sky above the port was the color of television, tuned to a dead channel.’
But as an editor, I get text in many forms. Rarely are single and double quotes delivered as ' and ". Instead, they are entered as ‘/’ and “/”, as well as ‘/’ and “/”.
If those last two sets are confusing you, they are just how HTML actual stores these right and left quotation marks. All you need to know is that writers actually do submit text with these symbols in the text and they are perfectly correct.
The problem is that I don’t like them. I like my text to be straight ASCII7, and so I like my straight ' and " keys. If I had to choose from the other sets, I would take ‘ over ‘.
The other day, I was talking to a fellow editor who was complaining about this. She didn’t mind ‘ so much, but ‘ drove her crazy. It’s understandable; they really do make the raw HTML harder to read.
Since I was no longer alone in my complaints, it occurred to me that I should write a program to fix this problem. At first, I thought I would write it in PHP, given that I really like its string (short for “text string” or more generally a collection of characters) library. But then I thought it would be downright trivial to do with JavaScript.
One great thing with JavaScript is that you don’t even need a server. You can just run the program locally on your machine. And a few minutes later, I had the following program:
Remove Annoying Quotation Marks
This program removes annoying special quotation marks and replaces them with normal ASCII7 characters. The characters are:
- ”
- “
- ’
- ‘
- “
- ”
- ‘
- ’
Text Box
Source Code
I often pine for the days when you had to really get inside a machine. But I have to admit that it’s pretty cool to be able to write a program that solves an annoying problem like this with almost no thought or time.
Here is the entire program. All you would have to do is put it in a file with an html extension and then run it in a browser on your computer.
<html>
<head>
<title>Remove Annoying Quotation Marks</title>
<script>
function Clean() {
var t1, t2;
t1 = document.getElementById("text1").value;
t2 = t1.replace(/”/g,"\"");
t1 = t2.replace(/“/g,"\"");
t2 = t1.replace(/“/g,"\"");
t1 = t2.replace(/”/g,"\"");
t2 = t1.replace(/‘/g,"'");
t1 = t2.replace(/’/g,"'");
t2 = t1.replace(/‘/g,"'");
t1 = t2.replace(/’/g,"'");
document.getElementById("text1").value = t1;
}
</script>
</head>
<body>
<h1>Remove Annoying Quotation Marks</h1>
<p>This program removes annoying special quotation
marks and replaces them with normal ASCII7 characters.
The characters are:</p>
<ul>
<li>”</li>
<li>“</li>
<li>’</li>
<li>‘</li>
<li>“</li>
<li>”</li>
<li>‘</li>
<li>’</li>
</ul>
<h2>Text Box</h2>
<div style="text-align: center;
margin-left: auto;
margin-right: auto;"><textarea rows="5"
cols="50" id="text1"></textarea></div>
<p style="text-align: center;"><input
onClick="Clean();" type="button"
value="Clean" /></p>
</body>
</html>
You can download the program if you wish:
Conclusion
I realize this is pretty arcane. It combines a number of things people don’t care about: computer programming, editing, and my neuroses. But I still think it’s interesting.