<?php
// Auto-split module from bot.php. Keep this file beside the project root.

// ========================== Text formatting compatibility ==========================
// Telegram renders bold text with Markdown-style **text**. This helper normalizes old
// HTML bold/code markup before sending messages, so outdated bold tags are not shown.
if(!function_exists('bot_markup_to_bale_markdown')){
    function bot_markup_to_bale_markdown($text){
        $text = (string)$text;
        $text = preg_replace('/<\s*br\s*\/?>/iu', "\n", $text);
        $text = preg_replace('/<\s*(b|strong)\s*>/iu', '**', $text);
        $text = preg_replace('/<\s*\/\s*(b|strong)\s*>/iu', '**', $text);
        $text = preg_replace('/<\s*code\s*>/iu', '`', $text);
        $text = preg_replace('/<\s*\/\s*code\s*>/iu', '`', $text);
        return html_entity_decode($text, ENT_QUOTES | ENT_HTML5, 'UTF-8');
    }
}

// Backward-compatible name used by older branches. It now keeps **bold** as Markdown.
if(!function_exists('bot_double_star_bold_to_html')){
    function bot_double_star_bold_to_html($text){
        return bot_markup_to_bale_markdown($text);
    }
}
