def presplit_textwrap(words, margin=79, *, two_spaces=True):
    """
    Combines "words" into lines and returns the result as a string.

    "words" should be an iterator containing pre-split text.

    "margin" specifies the maximum length of each line.

    If "two_spaces" is true, words that end in sentence-ending
    punctuation ('.', '?', and '!') will be followed by two spaces,
    not one.

    Elements in "words" are not modified; any leading or trailing
    whitespace will be preserved.  This is used for the "don't reformat
    indented 'code'" feature: "code" lines start with '\n', and the last
    one ends with '\n' too.
    """

    words = iter(words)
    col = 0
    lastword = ''
    text = []

    for word in words:
        l = len(word)

        if not l:
            lastword = word
            col = 0
            text.append('\n')
            continue

        if two_spaces and lastword.endswith(('.', '?', '!')):
            space = "  "
            len_space = 2
        else:
            space = " "
            len_space = 1

        if (l + len_space + col) > margin:
            if col:
                text.append('\n')
                col = 0
        elif col:
            text.append(space)
            col += len_space

        text.append(word)
        col += len(word)
        lastword = word

    return "".join(text)