Fixing link replacement for # and javascript: href