/ Published in: JavaScript
Expand |
Embed | Plain Text
// Typographical fixes var replaceStart = new Date().getTime(); $('body').html($('body').html() .replace(/(\d)-(\d)/ig, '$1–$2') // Proper use of en-dash for ranges .replace(/Entree/, 'Entrée') // Make Entree use the acute e .replace(/(\d)(.*?)(hours?|minutes?|seconds?$)/ig, '<span class="time">$1$2$3</span>') // Wrap <span class="time"></span> around times .replace(/(\d+)\/(\d+)/ig, '<sup>$1<\/sup>⁄<sub>$2<\/sub>') // Pretty fractions .replace(/(\d) <sup>/ig, '$1<sup>') // Remove the space from mixed fractions .replace(/(minutes?)/ig, '<abbr title="$1">min.</abbr>') .replace(/(hours?)/ig, '<abbr title="$1">hr.</abbr>') .replace(/(seconds?)/ig, '<abbr title="$1">sec.</abbr>') .replace(/(teaspoons?)/ig, '<abbr title="$1">t.</abbr>') .replace(/(tablespoons?)/ig, '<abbr title="$1">T.</abbr>') .replace(/(fluid ounces?)/ig, '<abbr title="$1">fl. oz.</abbr>') .replace(/(ounces(?!">))/ig, '<abbr title="ounces">oz.</abbr>') // For some reason, the s? and the (?!">) were not playing nice... .replace(/(ounce(?!s">))/ig, '<abbr title="ounces">oz.</abbr>') // ...So I had to write each line separately. Oh well. .replace(/(cups?)/ig, '<abbr title="$1">c.</abbr>') .replace(/(pints?)/ig, '<abbr title="$1">pt.</abbr>') .replace(/(quarts?)/ig, '<abbr title="$1">qt.</abbr>') .replace(/(gallons?)/ig, '<abbr title="$1">gal.</abbr>') .replace(/(pounds)/ig, '<abbr title="$1">lbs.</abbr>') .replace(/(pound(?!s">))/ig, '<abbr title="$1">lb.</abbr>') // Tricky, I had to exclude title="pounds" ); var replaceEnd = new Date().getTime(); var replaceTime = replaceEnd - replaceStart; console.log('It took ' + replaceTime + 'ms to format everything via regular expressions.');
You need to login to post a comment.
