         # if DEBUG console.log 'html_process_output_mesg', mesg, mark
         if mesg.stdout?.length > 0
             # assertion: for stdout, `mark` might be undefined
-            stdout = mesg.stdout.join('\n')
-            out += "<div class='output stdout'>#{stdout}</div>"
-        if mesg.stderr?
+            out += "<div class='output stdout'>#{mesg.stdout}</div>"
+        if mesg.stderr?.length > 0
             out += "<div class='output stderr'>#{mesg.stderr}</div>"
         if mesg.html?
             $html = $("<div>#{mesg.html}</div>")

            # ignored
            out += ' '

        if out == ''
            console.warn "sagews2html: encounted unknown mesg", mesg
        return @html_post_process(out)

    html_post_process: (html) ->

            input_lines      = []
            input_lines_mode = null

        process_lines = (cb) =>
            line = 0
            lines_total = cm.lineCount()
            while line < lines_total
