By setting a single CSS property, CodeMirror can be made to automatically resize to fit the content. Use max-height to prevent it from growing past a given point (on halfway modern browsers).
max-height