<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def markdown_2_rst(lines):
 """ Convert markdown to restructured text """

    out = []
    code = False
    for line in lines:
        # code blocks
        if line.strip() == "```":
            code = not code
            space = " " * (len(line.rstrip()) - 3)
            if code:
                out.append("\n\n%s.. code-block:: none\n\n" % space)
            else:
                out.append("\n")
        else:
            if code and line.strip():
                line = "    " + line
            else:
                # escape any backslashes
                line = line.replace("\\", "\\\\")
            out.append(line)
    return out