Take handling of outputs over from sphinx-thebe
In order to detect whether a cell has an output, thebe looks for the next element in DOM to have correct attributes. That means that input and output must follow each other in DOM.
sphinx-thebe uses a more flexible approach where input and output must both be children of a cell container. The advantage of this approach is the ability to retain layout and styling by wrapping the DOM elements. In practice sphinx-thebe uses a simple script to manipulate the DOM in order to make thebe recognize the inputs on activation.
I think it would be better if thebe itself used a more flexible approach. That would remove much (most?) of javascript from sphinx-thebe, and make thebe more broadly applicable.
I think a reasonable approach to backwards compatibility is to use the nested selector if the parent container is specified in the config, and otherwise to use the original one.