diff --git a/devel_themer.css b/devel_themer.css
index 6c48795..1f27900 100644
--- a/devel_themer.css
+++ b/devel_themer.css
@@ -1,3 +1,9 @@
+span.k.e.n.t.h.v[thmr] {
+	display:inline;
+	padding:0;
+	margin:0;
+}
+
 .field-tip {
   position: absolute;
   padding: 3px 5px;
diff --git a/devel_themer.module b/devel_themer.module
index 05740fa..fff306b 100644
--- a/devel_themer.module
+++ b/devel_themer.module
@@ -184,6 +184,111 @@ function devel_themer_module_implements_alter(&$implementations, $hook) {
   }
 }
 
+class devel_themer_html {
+  private $html = "";
+  public $tree = array();
+  
+  public function __construct($html) {
+    $this->html = $html;
+    $this->parse($html); 
+  }
+    
+  private function parse($html) {
+    // Getting html tags.
+    $tags = array(); 
+    preg_match_all('/<[^>]+>/', $html, $tags, PREG_OFFSET_CAPTURE);
+    $tags = $tags[0];
+    foreach ($tags as &$tag) {
+      $tag['type'] = 'tag';
+      $tag['name'] = self::get_tag_name($tag[0]);
+    }
+    // Getting text.
+    $texts = preg_split('/<[^>]+>/', $html, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE );
+    foreach ($texts as &$text) {
+      $text['type'] = 'text';
+    }
+    // Merging the two.
+    $a = $e = 0;
+    while ($a < count($tags) && $e < count($texts)) {
+      if ($tags[$a][1] < $texts[$e][1])
+        $this->tree[] = $tags[$a++];
+      else 
+        $this->tree[] = $texts[$e++];
+    }
+    while ($a < count($tags)) {
+      $this->tree[] = $tags[$a++];
+    }
+    while ($e < count($texts)) {
+      $this->tree[] = $texts[$e++];
+    }
+  }
+  
+  public function insert($key) {
+    // Check if key already inserted
+    if (strpos($this->html, "thmr='$key'") > 0) {
+      return $this->html;
+    }
+    // Add spans around top level text elements, add attribute directly to top level tags.
+    $cur = 0;
+    $open_tags = 0;
+    $open_tag = "";
+    while ($cur < count($this->tree)) {
+      $current = $this->tree[$cur];
+      if ($current['type'] == "text") {
+        if ($open_tags == 0 && trim($current[0]) != "") {
+          $this->tree[$cur][0] = "<span thmr='$key' class='k e n t h v'>{$current[0]}</span>";
+        }
+      } else if (strpos($current['name'],'/') > 0 ) {  /* short tag */
+        if( $open_tags == 0 ) {
+          $this->add_to_tag($cur, $key);
+        }
+      } else if (strpos($current['name'], '/') === 0) { /* end tag */
+        if ($current['name'] === "/$open_tag") {
+          if ($open_tags > 0) {
+            $open_tags--;
+          }
+          if ($open_tags == 0) {
+            $open_tag = "";
+          }
+        } 
+      } else { /* opening tag */
+        if ($open_tags === 0) {
+          $this->add_to_tag($cur, $key);
+          $open_tags++;
+          $open_tag = $current['name'];
+        } else if ($open_tag === $current['name']) {
+          $open_tags++;
+        } 
+      }
+      $cur++;
+    }
+    
+    return $this->build_html();
+  }
+  private function build_html() {
+    $this->html = "";
+    for ($i = 0; $i < count($this->tree); $i++) {
+      $this->html .= $this->tree[$i][0];
+    }
+    return $this->html;
+  }
+  
+  private function add_to_tag($idx, $key) {
+    $html = $this->tree[$idx][0];
+    $tag = "<" . $this->tree[$idx]['name'];
+    if (strpos($tag, '/') > 0) {
+      $tag = substr($tag,0,-1);
+    }
+    $pos = strpos($html, $tag) + strlen($tag);
+    $this->tree[$idx][0] = substr($html, 0, $pos) . " thmr='$key'" . substr($html, $pos);
+  }
+  
+  public static function get_tag_name($tag) {
+    $parts = preg_split( '/[<>\s]/', $tag, -1, PREG_SPLIT_NO_EMPTY);
+    return $parts[0] . (strpos($tag, '/>') > 0 ? '/' : '');
+  }
+}
+
 /**
  * Intercepts all theme calls (including templates), adds to template log, and dispatches to original theme function.
  */
@@ -208,13 +313,13 @@ function devel_themer_catch_function() {
 
   if (!empty($return) && !is_array($return) && !is_object($return) && user_access('access devel information')) {
     $key = "thmr_$counter";
-
     // Check for themer attribute in content returned
-    if (!strpos($return, $key)) {
-       // TODO exclude some hooks here.
-      $return = '<span thmr="' . $key . '">' . $return . '</span>';
+    // Excluding the options none hook (can't inject html here)
+    if ($hook != 'options_none') {
+      $injector = new devel_themer_html($return);
+      $return = $injector->insert($key);
     }
-
+   
     if ($meta['type'] == 'func') {
       $name = $meta['name'];
       $used = $meta['used'];
@@ -235,7 +340,6 @@ function devel_themer_catch_function() {
       $used = $meta['used'];
     }
 
-
     // Set preprocessors.
     if (isset($meta['processor_functions']['preprocess functions'])) {
       $preprocessors = $meta['processor_functions']['preprocess functions'];
@@ -273,10 +377,7 @@ function devel_themer_catch_function() {
       'type' => $meta['type'],
     );
   }
-  else {
-    $output = $return;
-  }
-  return isset($output) ? $output : $return;
+  return $return;
 }
 
 /**
