   end
 
   defp wrap_pipescript_with_do state do
-    regex = ~R/(<\s*(?!do|fn)[^>]*>\s*?)(\| +[\s\S]+?)_line: ([0-9]+)([\s\S]*?)(?=\n\s*@\w+\s+|\n\s*<\/?[\w\.\-]+)/u
+    regex = ~R/(<\s*(?!do|fn)[^>]*>\s*?)(\|\s+[\s\S]+?)_line: ([0-9]+)([\s\S]*?)(?=\n\s*@\w+\s+|\n\s*<\/?[\w\.\-]+)/u
     replace_stmt = "\\1 <do _line='\\3'> <![CDATA[ \\2\\4 ]]> </do>"
     res = Regex.replace regex, state.script, replace_stmt
     %{state | script: res}

  end

  defp do_fix_line_syntax {line, no}, :fix_do_opts do
    line1 = ~R/((?:^ *| +)\| +[\w\.\-]+[^\|]*) +do: +(\| +.+)/u
      |> Regex.replace(line, "\\1 do \\2 | end")

    line2 = ~R/(^ *| +)\| +([\w\.\-]+)( +[^\|]*?)do(?= *$| +\| +[\w\.\-]+)/u
      |> Regex.replace(line1, "\\1| do.\\2\\3")
    {line2, no}
  end

  defp do_fix_line_syntax {line, no}, :fix_question_mark do
    line2 = ~R/(^ *)\| +([\w\.\-]+)\? *?(.*?)([\w\.\-:]+: +.+?)?(?=(\s+\| +[\w\.\-]+.*)|\s*$)\5?/u
      |> Regex.replace(line, fn
        _, _1, _2, "", _4, "" -> ""
        _, f1, f2, "", _4, f5 -> "#{f1}| unless do #{f2}#{f5} | end"

  end

  defp fix_pipe_comments state do
    regex = ~R/(\s+)'(\|\s+[\w\.\-]+)/u
    res = Regex.replace regex, state.script, "\\1\\2"
    %{state | script: res}
  end
