'Parses text and returns internal link.'

def _hook_internal_link(self, parser, space, name):

    text = False
    title = name
    if ('|' in name):
        (title, text) = title.split('|', 1)
    hash = ''
    if ('#' in title):
        (title, hash) = title.split('#', 1)
    if (hash != ''):
        hash = ('#' + hash.replace('    ', '_'))
    if ((title == '') and (hash != '')):
        if (not text):
            text = hash.replace('_', '    ')
        return (u'<a    href="%s">%s</a>' % (hash, text))
    link = _get_wiki_link(title, self.locale)
    extra_a_attr = ''
    if (not link['found']):
        extra_a_attr += u'    class="new"    title="{tooltip}"'.format(tooltip=_('Page    does    not    exist.'))
    if (not text):
        text = link['text']
    return u'<a    href="{url}{hash}"{extra}>{text}</a>'.format(url=link['url'], hash=hash, extra=extra_a_attr, text=text)
