Skip to content

MarkdownV2 support? #1093

Closed
Closed
@asafov

Description

@asafov

At telegram api docs present parse_mode = MarkdownV2.
I tried to send some data and find, that needed new escape for support this format.

https://core.telegram.org/bots/api#markdownv2-style

    public static function escapeMarkdownV2($text)
    {
        $markdown = [
            '#',
            '*',
            '_',
            '=',
            '.',
            '[',
            ']',
            '(',
            ')',
            // ... rest of markdown entities
        ];
        //'_‘, ’*‘, , ’~‘, ’`‘, ’>‘, ’#‘, ’+‘, ’-‘, ’=‘, ’|‘, ’{‘, ’}‘, ’.‘, ’!‘
        $replacements = [
            '\#',
            '\*',
            '\_',
            '\\=',
            '\.',
            '\[',
            '\]',
            '\(',
            '\)',
            // ... rest of corresponding escaped markdown
        ];

        return str_replace($markdown, $replacements, $text);
    }

Something like this, as i think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions