Is it possible to programmaticaly change the HTML rendered by Drupal 7?
If you want to alter the rendered content of a page, you start by adding a post_render function to the node:

/**
 * Implements hook_node_view_alter().
 */
function MODULE_node_view_alter(&amp;$build) {
  $build['#post_render'][] = 'MODULE_wrap_images';
}


And then in that post render function, you can do what you need to do. In the example below, I am replacing float:left and float:right with a wrapper div:

function MODULE_wrap_images($content) {
  // Find all links within the content and extract the complete &lt;img&gt; tag.
  if (preg_match_all('#&lt;img.*?/&gt;#i', $content, $matches)) {

    // Loop matches and process.
    foreach ($matches[0] as $index =&gt; $match) {

      // Align images left.
      if (stripos($match, 'float: left;')) {
        $new = '&lt;div class="content-img content-img-left"&gt;' . str_ireplace('float: left;', '', $match) . '&lt;/div&gt;';
        $content = str_ireplace($match, $new, $content);
      }

      // Align images right.
      if (stripos($match, 'float: right;')) {
        $new = '&lt;div class="content-img content-img-right"&gt;' . str_ireplace('float: right;', '', $match) . '&lt;/div&gt;';
        $content = str_ireplace($match, $new, $content);
      }
    }
  }

  return $content;
}