def blit_path_representation(self):
        """Blit representation of text in current path."""

        rect = (
            1,
            BUTTON_HEIGHT + 2,
            self.width - 2,
            self.height - ((BUTTON_HEIGHT * 2) + 2),
        )

        image = self.image

        ###
        width, height = self.width, self.height

        path = Path(self.current_path)

        try:
            text = path.read_text(
                encoding="utf-8",
                errors="ignore",
            )

        except COMMON_READ_ERRORS:

            try:
                subsurf = self.path_repr_subsurf

            except AttributeError:

                subsurf = self.path_repr_subsurf = image.subsurface(rect)

            subsurf.blit(NOT_FOUND_SURF_MAP[subsurf.get_size()], (0, 0))

            super().blit_path_representation()
            return

        except Exception as err:

            ## log traceback in regular
            ## log and and user log

            msg = (
                "An unexpected error ocurred while trying to load the text"
                " from the path."
            )

            logger.exception(msg)
            USER_LOGGER.exception(msg)

            ## notify user via dialog

            dialog_message = msg + (
                " Check the user log for details (press <Ctrl+Shift+j> after"
                " leaving this dialog or access the \"Help > User log\" option"
                " on the menubar)."
            )

            create_and_show_dialog(dialog_message, level_name='error')

            try:
                subsurf = self.path_repr_subsurf

            except AttributeError:

                subsurf = self.path_repr_subsurf = image.subsurface(rect)

            subsurf.blit(NOT_FOUND_SURF_MAP[subsurf.get_size()], (0, 0))

            super().blit_path_representation()
            return

        no_of_visible_lines = 7
        show_line_number = True
        font_height = FIRA_MONO_BOLD_FONT_HEIGHT
        font_path = FIRA_MONO_BOLD_FONT_PATH

        syntax_highlighting = "python" if path.suffix.lower() in (".py", ".pyl") else ""

        if syntax_highlighting:

            theme_map = get_ready_theme(
                syntax_highlighting,
                GENERAL_TEXT_SETTINGS,
            )

            get_syntax_map = SYNTAX_TO_MAPPING_FUNCTION[syntax_highlighting]

            ## define text settings for the line numbers

            # reference the theme text settings locally
            theme_text_settings = theme_map["text_settings"]

            # if the line number settings from the theme
            # are available, use them
            try:
                lineno_settings = theme_text_settings["line_number"]

            # otherwise use the settings for normal text of
            # the theme for the line number settings

            except KeyError:

                lineno_settings = theme_text_settings["normal"]

            ## store the colors

            lineno_fg = lineno_settings["foreground_color"]

            lineno_bg = lineno_settings["background_color"]

            ### define the background color for the text
            background_color = theme_map["background_color"]

        else:

            foreground_color = lineno_fg = GENERAL_TEXT_SETTINGS["foreground_color"]

            background_color = lineno_bg = GENERAL_TEXT_SETTINGS["background_color"]

        draw_rect(image, background_color, rect)

        if show_line_number:

            lineno_width, _ = get_text_size(
                "01", font_height=font_height, font_path=FIRA_MONO_BOLD_FONT_PATH
            )

            draw_rect(
                image,
                lineno_bg,
                (1, BUTTON_HEIGHT + 2, lineno_width - 2, height - BUTTON_HEIGHT + 2),
            )

        else:
            lineno_width = 0

        lines = text.splitlines()[:no_of_visible_lines]

        if syntax_highlighting:

            try:
                highlight_data = get_syntax_map(text)

            except SyntaxMappingError:

                highlight_data = {
                    ## store a dict item where the line index
                    ## is the key and another dict is the value
                    line_index: {
                        ## in this dict, an interval representing
                        ## the indices of all items of the line
                        ## (character objects) is used as the
                        ## key, while the 'normal' string is used
                        ## as value, indicating that all content
                        ## must be considered normal text
                        (0, len(line_text)): "normal"
                    }
                    ## for each line_index and respective line
                    for line_index, line_text in enumerate(lines)
                    ## but only if the line isn't empty
                    if line_text
                }

            ##
            x = lineno_width + 4
            y = BUTTON_HEIGHT + 2

            theme_text_settings = theme_map["text_settings"]

            ## iterate over the visible lines and their
            ## indices, highlighting their text according
            ## to the highlighting data present

            for line_index, line_text in enumerate(lines, 0):

                ## try popping out the interval data from
                ## the highlight data dict with the line
                ## index

                try:
                    interval_data = highlight_data.pop(line_index)

                ## if there is no such data, skip iteration
                ## of this item
                except KeyError:
                    pass

                ## otherwise...
                else:

                    line_surf = render_highlighted_line(
                        line_text, interval_data, theme_text_settings, join_objects=True
                    ).image

                    image.blit(line_surf, (x, y))

                y += font_height

        else:

            y = BUTTON_HEIGHT + 2

            x = lineno_width + 4 if show_line_number else 4

            for line_number, line_text in enumerate(lines, 1):

                if line_number > no_of_visible_lines:
                    break

                surf = render_text(
                    text=line_text,
                    font_height=font_height,
                    font_path=font_path,
                    foreground_color=foreground_color,
                    background_color=background_color,
                )

                image.blit(surf, (x, y))

                y += font_height

        ###

        if show_line_number:

            y = BUTTON_HEIGHT + 2

            for line_number, line_text in enumerate(lines, 1):

                surf = render_text(
                    text=str(line_number).rjust(2, "0"),
                    font_height=font_height,
                    font_path=FIRA_MONO_BOLD_FONT_PATH,
                    foreground_color=lineno_fg,
                    background_color=lineno_bg,
                )

                image.blit(surf, (2, y))

                y += font_height

        draw_depth_finish(image)

        ###
        super().blit_path_representation()
Blit representation of text in current path.
nodezator/widget/pathpreview/text.py