Ejemplo n.º 1
0
    def handle_angle_brackets(inline_request):
        """
        Given an open angle bracket, determine which of the three possibilities it is.
        """
        closing_angle_index = inline_request.source_text.find(
            InlineHelper.__angle_bracket_end, inline_request.next_index)
        new_token = None
        if closing_angle_index not in (-1, inline_request.next_index + 1):

            between_brackets = inline_request.source_text[
                inline_request.next_index + 1:closing_angle_index]
            remaining_line = inline_request.source_text[inline_request.
                                                        next_index + 1:]
            closing_angle_index += 1
            new_token = InlineHelper.__parse_valid_uri_autolink(
                between_brackets)
            if not new_token:
                new_token = InlineHelper.__parse_valid_email_autolink(
                    between_brackets)
            if not new_token:
                LOGGER.debug(">>between_brackets>>%s", str(between_brackets))
                new_token, after_index = HtmlHelper.parse_raw_html(
                    between_brackets, remaining_line)
                LOGGER.debug(">>new_token>>%s", str(new_token))
                if after_index != -1:
                    closing_angle_index = after_index + inline_request.next_index + 1

        inline_response = InlineResponse()
        if new_token:
            inline_response.new_string = ""
            inline_response.new_index = closing_angle_index
            inline_response.new_tokens = [new_token]
        else:
            inline_response.new_string = InlineHelper.angle_bracket_start
            inline_response.new_index = inline_request.next_index + 1
        return inline_response
Ejemplo n.º 2
0
    def handle_angle_brackets(inline_request: InlineRequest) -> InlineResponse:
        """
        Given an open angle bracket, determine which of the three possibilities it is.
        """
        closing_angle_index = inline_request.source_text.find(
            InlineHelper.__angle_bracket_end, inline_request.next_index)
        if closing_angle_index not in (-1, inline_request.next_index + 1):

            between_brackets, remaining_line = (
                inline_request.source_text[inline_request.next_index +
                                           1:closing_angle_index],
                inline_request.source_text[inline_request.next_index + 1:],
            )
            closing_angle_index += 1

            assert inline_request.line_number is not None
            assert inline_request.column_number is not None
            assert inline_request.remaining_line is not None
            new_column_number = inline_request.column_number + len(
                inline_request.remaining_line)

            new_token: Optional[
                MarkdownToken] = InlineHelper.__parse_valid_uri_autolink(
                    between_brackets, inline_request.line_number,
                    new_column_number)
            if not new_token:
                new_token = InlineHelper.__parse_valid_email_autolink(
                    between_brackets, inline_request.line_number,
                    new_column_number)
            if not new_token:
                new_token, after_index = HtmlHelper.parse_raw_html(
                    between_brackets,
                    remaining_line,
                    inline_request.line_number,
                    new_column_number,
                    inline_request,
                )
                if after_index != -1:
                    closing_angle_index = after_index + inline_request.next_index + 1
                    html_token = cast(RawHtmlMarkdownToken, new_token)
                    between_brackets = html_token.raw_tag
        else:
            new_token, between_brackets = None, None

        inline_response = InlineResponse()
        if new_token:
            (
                inline_response.new_string,
                inline_response.new_index,
                inline_response.new_tokens,
                between_brackets,
            ) = (
                "",
                closing_angle_index,
                [new_token],
                f"{InlineHelper.angle_bracket_start}{between_brackets}{InlineHelper.__angle_bracket_end}",
            )
        else:
            inline_response.new_string, inline_response.new_index, between_brackets = (
                InlineHelper.angle_bracket_start,
                inline_request.next_index + 1,
                InlineHelper.angle_bracket_start,
            )

        (
            inline_response.delta_line_number,
            inline_response.delta_column_number,
        ) = ParserHelper.calculate_deltas(between_brackets)
        return inline_response