     end
   end
 
+  defp collapse(["\n" <> _ | t], max, count, i) do
+    collapse(t, max, count + 1, i)
+  end
+  defp collapse(["" | t], max, count, i) do
+    collapse(t, max, count, i)
+  end
+  defp collapse(t, max, count, i) do
+    [:binary.copy("\n", min(max, count)) <> :binary.copy(" ", i) | t]
+  end
+
   defp apply_nesting(_, k, :cursor), do: k
   defp apply_nesting(_, _, :reset), do: 0
   defp apply_nesting(i, _, j), do: i + j

          | doc_color
          | doc_force
          | doc_cancel

  @typep doc_string :: {:doc_string, t, non_neg_integer}
  defmacrop doc_string(string, length) do

  @spec break(binary) :: doc_break
  def break(string \\ " ") when is_binary(string) do
    doc_break(string, :strict)
  end

  @doc """
  Collapse any new lines and whitespace following this
  node and emitting up to `max` new lines.
  """
  @spec collapse_lines(pos_integer) :: doc_collapse
  def collapse_lines(max) when is_integer(max) and max > 0 do
    doc_collapse(max)
  end

  @doc """
