Hack #26. Convert Straight Quotes

Automatically convert straight quotes to "smart" quotes, like word processors do.

You are typographically cool. You use smart publishing software to automatically convert boring straight quotes and apostrophes to their curly Unicode equivalents. Don't you also want to flaunt your coolness when you post comments on other sites? Now you can! This hack takes straight quotes and other plain typography in web forms and replaces them with their curly equivalents.

The Code

This user script runs on all pages. It traps form submission and smartens straight quotes in <textarea> elements of web forms.

Save the following user script as smartquotes.user.js:

 // ==UserScript== // @name Smart Quotes // @namespace http://www.slightlyremarkable.com/ // @description Curlify typography in web forms // @include * // ==/UserScript== // based on code by Jonathan Fenocchi // and included here with his gracious permission function filterChars(formatted) { var temp = new Array(); var count = 0; var DELIM_CHAR = '\u00A4'; var BASE_CHAR = '\u0041-\u005A\u0061-\u007A\u00C0-\u00D6\u00D8-'+ '\u00F6\u00F8-\u00FF\u0100-\u0131\u0134-\u013E\u0141-\u0148\u014A-'+ '\u017E\u0180-\u01C3\u01CD-\u01F0\u01F4-\u01F5\u01FA-\u0217\u0250-'+ '\u02A8\u02BB-\u02C1\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-'+ '\u03CE\u03D0-\u03D6\u03DA\u03DC\u03DE\u03E0\u03E2-\u03F3\u0401-'+ '\u040C\u040E-\u044F\u0451-\u045C\u045E-\u0481\u0490-\u04C4\u04C7-'+ '\u04C8\u04CB-\u04CC\u04D0-\u04EB\u04EE-\u04F5\u04F8-\u04F9\u0531-'+ ...

Get Greasemonkey Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.