renderQualName :: Namespace -> QualName VName -> DocM Html
renderQualName ns (QualName names (VName name tag)) =
  if tag <= maxIntrinsicTag
      then return $ prefix <> renderName name
      else f <$> ref
  where prefix :: Html
        prefix = mapM_ ((<> ".") . renderName) names
        f s = prefix <> (a ! A.href (fromString s) $ renderName name)

        ref = do --vname <- getVName ns (QualName names name)
                 Just file <- gets (M.lookup (ns, VName name tag))
                 current <- asks fst
                 if file == current
                     then return ("#" ++ show tag)
                     else return $ relativise file current ++
                          ".html#" ++ show tag
renderQualName :: Namespace -> QualName VName -> DocM Html
renderQualName ns (QualName names (VName name tag)) =
  if tag <= maxIntrinsicTag
      then return $ prefix <> renderName name
      else f <$> ref
  where prefix :: Html
        prefix = mapM_ ((<> ".") . renderName) names
        f s = prefix <> (a ! A.href (fromString s) $ renderName name)

        ref = do --vname <- getVName ns (QualName names name)
                 Just file <- gets (M.lookup (ns, VName name tag))
                 current <- asks fst
                 if file == current
                     then return ("#" ++ show tag)
                     else return $ relativise file current ++
                          ".html#" ++ show tag
renderQualName ns (QualName names (VName name tag)) =
  if tag <= maxIntrinsicTag
      then return $ prefix <> renderName name
      else f <$> ref
  where prefix :: Html
        prefix = mapM_ ((<> ".") . renderName) names
        f s = prefix <> (a ! A.href (fromString s) $ renderName name)

        ref = do --vname <- getVName ns (QualName names name)
                 Just file <- gets (M.lookup (ns, VName name tag))
                 current <- asks fst
                 if file == current
                     then return ("#" ++ show tag)
                     else return $ relativise file current ++
                          ".html#" ++ show tag