         # 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>")

                                    continue

                                #if DEBUG then console.log 'sagews2html: output message', mesg
                                if mesg.stdout?
                                    mesg_stdout.stdout.push(mesg.stdout)
                                else
                                    # add non-stdout mesg from this iteration
                                    if mesg.clear
                                        mesg_stdout = {stdout : []}
                                        output_msgs = []
                                    else if mesg.delete_last
                                        mesg_stdout.stdout.pop()
                                    else
                                        output_msgs.push(mesg)
                            # after for-loop over rendered output cells
                            for mesg in output_msgs
                                om = @html_process_output_mesg(mesg, mark)
                                _html.push(om) if om?

                process_collected_mesg_stdout()
                line++
            input_lines_process(final = true)
            # combine all html snippets to one html block

            # ignored
            out += ' '

        return @html_post_process(out)

    html_post_process: (html) ->
