UNPKG

telegram-markdown-v2

Version:

Convert markdown into Telegram Markdown V2 format with TypeScript support

29 lines (28 loc) 1.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleText = handleText; exports.handleInlineCode = handleInlineCode; exports.handleCode = handleCode; const utils_js_1 = require("../utils.js"); function handleText(node, _parent, state, _info) { const exit = state.enter('phrasing'); const text = node.value; exit(); return (0, utils_js_1.escapeSymbols)(text); } function handleInlineCode(node, _parent, state, _info) { const exit = state.enter('paragraph'); const value = (0, utils_js_1.escapeSymbols)(node.value, 'code'); exit(); return `\`${value}\``; } function handleCode(node, _parent, state, _info) { const exit = state.enter('codeFenced'); // Remove language prefix for deprecated markdown formatters const content = node.value.replace(/^#![a-z]+\n/, ''); const escapedContent = (0, utils_js_1.escapeSymbols)(content, 'code'); exit(); // For compatibility with original tests, don't include language // (can be enabled later for full V2 support) return (0, utils_js_1.wrap)(escapedContent, '```', '\n'); }