diff --git a/media.filter.inc b/media.filter.inc
index aec8abe..5082b29 100644
--- a/media.filter.inc
+++ b/media.filter.inc
@@ -153,12 +153,32 @@ function media_token_to_markup($match, $wysiwyg = FALSE) {
     $settings = array_intersect_key($settings, array_flip($attribute_whitelist));
 
     // @TODO: What case does this provide for?  Can we add this logic in JS when we embed it?
-    // This doesn't look great to me.  Also won't work if the style has anything
-    // between width and height (or if they are in reverse order).
     if (isset($settings['style'])) {
-      if (preg_match('@width: (.+?)px; height: (.+?)px;@i', $settings['style'], $matches)) {
-        $settings['width'] = $matches[1];
-        $settings['height'] = $matches[2];
+      // add trailing semi-colon
+      if (substr($settings['style'], count($settings['style'])-2) != ';') {
+        $settings['style'] .= ';';
+      }
+      
+      if (preg_match_all('/([a-z\-]+):\s*([a-z0-9\-]+(\s+[a-z0-9\-]+)*);/i', $settings['style'], $matches)) {
+        $allowed_tags = array('width', 'height', 'float', 'display',
+        'margin-top', 'margin-bottom', 'margin-left', 'margin-right', 'margin',
+        'border-width', 'border-style');
+        for($i=0; $i<count($matches[0]); $i++) {
+          $tag = $matches[1][$i];
+          $val = $matches[2][$i];
+          if (in_array($tag, $allowed_tags)) {
+            switch ($tag) {
+              case 'width':
+              case 'height':
+                $pixels = preg_replace('/[^\d]+/', '', $val);
+                $settings[$tag] = $pixels;
+                break;
+              default:
+                $settings[$tag] = $val;
+                break;
+            }
+          }
+        }
       }
     }
     if ($wysiwyg) {
@@ -357,7 +377,9 @@ function media_get_file_without_label($media, $view_mode, $settings = array()) {
   $format['label'] = 'hidden';
   $format['settings'] = array_merge($format['settings'], $settings);
   $media->override = $settings;
-  return field_view_field('media', $media, 'file', $format);
+  $field_view = field_view_field('media', $media, 'file', $format);
+  unset($field_view['#theme']);
+  return $field_view;
 }
 
 /**
