coalesce stream output in the notebook

This merges consecutive outputs on one stream into a single output.

Essentially, it applies the same merging that we do visually to the content stored in the notebook document.

The result is a large performance improvement in load-time and file size for notebooks that have many calls to `sys.stdout.flush()`.