regex

Wrap first letter and first sentence in span via jQuery

For each target element, this script will wrap the first letter and the first sentence of the text. This is particularly useful if you need to style Drop Caps or a leading sentence.

Add a unique body class in Ruby on Rails template

After using Drupal's template.php file to preprocess html and add unique classes to various html elements, I because very dependent on page specific css classes. While building a Ruby on Rails app, I thought it would be nice to at least add in a page-specific body class. Here's a quick snippet you can use:

Helpful regexs for stripping extranous styling

Content migration is a pain, particularly when you are charged with copying content from an old html site into a new framework. Often times, old content comes with the baggage of inline css styling, which wreaks havoc on your pretty new site design. Here's a handful of helpful regexs that I use to strip out undeed inline styling, while still preserving the html element structure.

To strip out span tags:

<span[^>]+>

Follow up to strip out the close tags:

</span>

Strip out inline styling:

style="[^"]+"

FYI:[] defines a character class, ^ excludes characters.

I think you get the idea.

Subscribe to RSS - regex