Fixed infinite loop in JS parser for link-in-link-in-image.

Partially addresses #252.

This fixes the infinite loop, and brings the JS parser into
agreement with cmark, but both still have bad output in this
case, so more work is needed.