My hack above worked today, so I will take your much more elegant bit of python and replace a few lines. My python foo is still a bit green... Thanks!
For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/