def render_highlighted_line(
    line_text, mapped_syntax_data, syntax_settings_map, join_objects=False
):
    """Return highlighted text object(s) from the line.

    Parameters
    ==========
    line_text (string)
        text to be turned into syntax highlighted text
        objects.
    mapped_syntax_data (dict)
        maps 2-tuples to strings; the 2-tuples represent
        intervals of highlighted text in the line text;
        the strings indicate the kind of highlighted data
        (comments, keywords, etc.)
    syntax_settings_map (dict)
        maps strings to dicts; the strings indicate the kind
        of highlighted data (including 'normal' for text
        which isn't highlighted at all); the dicts are
        keyword arguments for rendering each kind of
        highlighted data.
    join_objects (boolean)
        whether to join text objects into a single one
        or not.
    """
    string_kwargs_pairs = (
        ### grab a pair containing the slice of the line text
        ### and the text settings corresponding to the kind
        ### of highlight to be applied
        (line_text[including_start:excluding_end], syntax_settings_map[kind])
        ### from each interval/kind pair in
        ### mapped_syntax_data sorted by the interval,
        ###
        ### the interval is further decomposed into its
        ### first and second elements, including_start and
        ### excluding_end, respectively
        for (including_start, excluding_end), kind in sorted(
            mapped_syntax_data.items(), key=lambda item: item[0]
        )
    )

    ### create a special list containing text objects
    ### instantiated from each item in the pairs
    ### from the string_kwargs_pairs iterator

    text_objs = List2D(
        Object2D.from_surface(
            surface=render_text(
                text=string,
                ### text settings
                **text_settings
            )
        )
        for string, text_settings in string_kwargs_pairs
    )

    ### align objects in the list one beside the other
    ### from left to right
    text_objs.rect.snap_rects_ip()

    ### return text objects (or single one) depending on
    ### quantity of text objects and special argument

    ## if there's more than one text object...

    if len(text_objs) > 1:

        ### if requested, join objects into a single one
        ### and return the object

        if join_objects:

            image = Surface(text_objs.rect.size).convert()

            image.fill(syntax_settings_map["normal"]["background_color"])

            text_objs.draw_on_surf(image)

            rect = image.get_rect()

            return Object2D(image=image, rect=rect)

        else:
            return text_objs

    ### otherwise we assume there's only a single
    ### text object, so we return it
    else:
        return text_objs.pop()
Return highlighted text object(s) from the line.

    Parameters
    ==========
    line_text (string)
        text to be turned into syntax highlighted text
        objects.
    mapped_syntax_data (dict)
        maps 2-tuples to strings; the 2-tuples represent
        intervals of highlighted text in the line text;
        the strings indicate the kind of highlighted data
        (comments, keywords, etc.)
    syntax_settings_map (dict)
        maps strings to dicts; the strings indicate the kind
        of highlighted data (including 'normal' for text
        which isn't highlighted at all); the dicts are
        keyword arguments for rendering each kind of
        highlighted data.
    join_objects (boolean)
        whether to join text objects into a single one
        or not.
    
nodezator/textman/text.py