Fix error handling of references with text and definitions

Previously if the definition was syntactically wrong the target was
treated as text, this fixes it.