Check for balanced parens before executing gradient regex

The regex for gradients is particularly tricky with parens, which is why it's causing JS engine to go into an infinite loop in the case described in #4650. To workaround this problem, first verify that content has balanced parens.

Assigning to @JeffryBooher since we discussed this offline