def METHOD_NAME(tokens: Iterable[Token]) -> str:
    out = io.StringIO()
    context = ElementStack()
    for prev2, prev1, token, next1, next2 in sliding_window.window(tokens, 2, 2):
        if isinstance(token, Tag):
            if token.is_opening:
                out.write(indent_text(token.data, context.indent))
                if not is_inline(prev2, prev1, token, next1, next2):
                    out.write("\n")
                context.push_tag(token.tag)
            elif token.is_closing:
                context.pop_tag(token.tag)
                if is_inline(prev2, prev1, token, next1, next2):
                    out.write(token.data)
                else:
                    out.write(indent_text(token.data, context.indent))
                out.write("\n")
            else:  # self-closing
                out.write(indent_text(token.data, context.indent))
                out.write("\n")
        elif isinstance(token, Text):
            if is_inline(prev2, prev1, token, next1, next2):
                out.write(token.text)
            else:
                out.write(indent_text(token.data, context.indent))
                out.write("\n")
        else:  # pragma: no cover
            raise RuntimeError()
    return out.getvalue()