littlefish/htmlutil.py
def split_line(line, min_line_length=30, max_line_length=100):
    """
    This is designed to work with prettified output from Beautiful Soup which indents with a single space.

    :param line: The line to split
    :param min_line_length: The minimum desired line length
    :param max_line_length: The maximum desired line length

    :return: A list of lines
    """
    if len(line) <= max_line_length:
        # No need to split!
        return [line]

    # First work out the indentation on the beginning of the line
    indent = 0
    while line[indent] == ' ' and indent < len(line):
        indent += 1

    # Try to split the line
    # Start looking for a space at character max_line_length working backwards
    i = max_line_length
    split_point = None
    while i > min_line_length:
        if line[i] == ' ':
            split_point = i
            break
        i -= 1

    if split_point is None:
        # We didn't find a split point - search beyond the end of the line
        i = max_line_length + 1
        while i < len(line):
            if line[i] == ' ':
                split_point = i
                break
            i += 1

    if split_point is None:
        # There is nowhere to split the line!
        return [line]
    else:
        # Split it!
        line1 = line[:split_point]
        line2 = ' ' * indent + line[split_point + 1:]
        return [line1] + split_line(line2, min_line_length, max_line_length)
def split_line(line, min_line_length=30, max_line_length=100):
    if len(line) <= max_line_length:
        # No need to split!
        return [line]

    # First work out the indentation on the beginning of the line
    indent = 0
    while line[indent] == ' ' and indent < len(line):
        indent += 1

    # Try to split the line
    # Start looking for a space at character max_line_length working backwards
    i = max_line_length
    split_point = None
    while i > min_line_length:
        if line[i] == ' ':
            split_point = i
            break
        i -= 1

    if split_point is None:
        # We didn't find a split point - search beyond the end of the line
        i = max_line_length + 1
        while i < len(line):
            if line[i] == ' ':
                split_point = i
                break
            i += 1

    if split_point is None:
        # There is nowhere to split the line!
        return [line]
    else:
        # Split it!
        line1 = line[:split_point]
        line2 = ' ' * indent + line[split_point + 1:]
        return [line1] + split_line(line2, min_line_length, max_line_length)
def split_line ( line , min_line_length = 30 , max_line_length = 100 ) : if len ( line ) <= max_line_length : # No need to split! return [ line ] # First work out the indentation on the beginning of the line indent = 0 while line [ indent ] == ' ' and indent < len ( line ) : indent += 1 # Try to split the line # Start looking for a space at character max_line_length working backwards i = max_line_length split_point = None while i > min_line_length : if line [ i ] == ' ' : split_point = i break i -= 1 if split_point is None : # We didn't find a split point - search beyond the end of the line i = max_line_length + 1 while i < len ( line ) : if line [ i ] == ' ' : split_point = i break i += 1 if split_point is None : # There is nowhere to split the line! return [ line ] else : # Split it! line1 = line [ : split_point ] line2 = ' ' * indent + line [ split_point + 1 : ] return [ line1 ] + split_line ( line2 , min_line_length , max_line_length )
This is designed to work with prettified output from Beautiful Soup which indents with a single space.

    :param line: The line to split
    :param min_line_length: The minimum desired line length
    :param max_line_length: The maximum desired line length

    :return: A list of lines
This is designed to work with prettified output from Beautiful Soup which indents with a single space .