diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index 7ea238f6f5ab05bbb8f459056c95baba97b773ee..565459220d6f8ba5fc42a2815ca5ba3803c112de 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -668,6 +668,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
     function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
                             $height=NULL, $cache=NULL, $linking=NULL) {
         global $ID;
+        list($src,$hash) = explode('#',$src,2);
         resolve_mediaid(getNS($ID),$src, $exists);
 
         $noLink = false;
@@ -687,6 +688,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
             $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true);
         }
 
+        if($hash) $link['url'] .= '#'.$hash;
+
         //markup non existing files
         if (!$exists)
           $link['class'] .= ' wikilink2';
@@ -698,6 +701,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
 
     function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
                             $height=NULL, $cache=NULL, $linking=NULL) {
+        list($src,$hash) = explode('#',$src,2);
         $noLink = false;
         $render = ($linking == 'linkonly') ? false : true;
         $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
@@ -714,7 +718,9 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
         }else{
              // add file icons
              $link['class'] .= ' mediafile mf_'.$ext;
-         }
+        }
+
+        if($hash) $link['url'] .= '#'.$hash;
 
         //output formatted
         if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];